Yuta HIGUCHI
Committed by Gerrit Code Review

[ONOS-4691] Refactoring OpticalPortOperator (2/3)

- Define ConfigOperator for a Port
- Refactor OpticalPortOperator as PortConfigOperator
- Add plug-in mechanism for PortConfigOperator on DeviceManager
- Move OpticalPortConfig, OpticalPortOperator to optical-model bundle

Change-Id: I5d416305b0c1b0e31e0ad64baa92d126303548bc
...@@ -4,7 +4,7 @@ COMPILE_DEPS = [ ...@@ -4,7 +4,7 @@ COMPILE_DEPS = [
4 ] 4 ]
5 5
6 TEST_DEPS = [ 6 TEST_DEPS = [
7 - '//lib:TEST', 7 + '//lib:TEST_ADAPTERS',
8 ] 8 ]
9 9
10 10
......
...@@ -47,6 +47,13 @@ ...@@ -47,6 +47,13 @@
47 47
48 <dependency> 48 <dependency>
49 <groupId>org.onosproject</groupId> 49 <groupId>org.onosproject</groupId>
50 + <artifactId>onos-api</artifactId>
51 + <classifier>tests</classifier>
52 + <scope>test</scope>
53 + </dependency>
54 +
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
50 <artifactId>onlab-junit</artifactId> 57 <artifactId>onlab-junit</artifactId>
51 <scope>test</scope> 58 <scope>test</scope>
52 </dependency> 59 </dependency>
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.net.config.basics; 16 +package org.onosproject.net.optical.config;
17 17
18 import java.util.Optional; 18 import java.util.Optional;
19 19
...@@ -30,6 +30,7 @@ import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL; ...@@ -30,6 +30,7 @@ import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL;
30 * Configurations for an optical port on a device. 30 * Configurations for an optical port on a device.
31 */ 31 */
32 public final class OpticalPortConfig extends Config<ConnectPoint> { 32 public final class OpticalPortConfig extends Config<ConnectPoint> {
33 +
33 // optical type {OMS, OCH, ODUClt, fiber} 34 // optical type {OMS, OCH, ODUClt, fiber}
34 public static final String TYPE = "type"; 35 public static final String TYPE = "type";
35 36
......
...@@ -13,17 +13,26 @@ ...@@ -13,17 +13,26 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.net.device.impl; 16 +package org.onosproject.net.optical.config;
17 17
18 import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription; 18 import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
19 import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription; 19 import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
20 import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription; 20 import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
21 import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription; 21 import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription;
22 import static org.slf4j.LoggerFactory.getLogger; 22 import static org.slf4j.LoggerFactory.getLogger;
23 -import org.onosproject.net.config.ConfigOperator; 23 +
24 -import org.onosproject.net.config.basics.OpticalPortConfig; 24 +import java.util.Set;
25 +
26 +import static com.google.common.base.MoreObjects.firstNonNull;
27 +import static com.google.common.base.Preconditions.checkNotNull;
28 +
29 +import org.onosproject.net.config.NetworkConfigService;
30 +import org.onosproject.net.config.PortConfigOperator;
25 import org.onosproject.net.AnnotationKeys; 31 import org.onosproject.net.AnnotationKeys;
32 +import org.onosproject.net.ConnectPoint;
26 import org.onosproject.net.DefaultAnnotations; 33 import org.onosproject.net.DefaultAnnotations;
34 +import org.onosproject.net.Port;
35 +import org.onosproject.net.Port.Type;
27 import org.onosproject.net.PortNumber; 36 import org.onosproject.net.PortNumber;
28 import org.onosproject.net.SparseAnnotations; 37 import org.onosproject.net.SparseAnnotations;
29 import org.onosproject.net.device.DefaultPortDescription; 38 import org.onosproject.net.device.DefaultPortDescription;
...@@ -34,63 +43,85 @@ import org.onosproject.net.device.OtuPortDescription; ...@@ -34,63 +43,85 @@ import org.onosproject.net.device.OtuPortDescription;
34 import org.onosproject.net.device.PortDescription; 43 import org.onosproject.net.device.PortDescription;
35 import org.slf4j.Logger; 44 import org.slf4j.Logger;
36 45
46 +import com.google.common.collect.Sets;
47 +
37 /** 48 /**
38 * Implementations of merge policies for various sources of optical port 49 * Implementations of merge policies for various sources of optical port
39 * configuration information. This includes applications, provides, and network 50 * configuration information. This includes applications, provides, and network
40 * configurations. 51 * configurations.
41 */ 52 */
42 -public final class OpticalPortOperator implements ConfigOperator { 53 +public final class OpticalPortOperator implements PortConfigOperator {
43 54
44 private static final Logger log = getLogger(OpticalPortOperator.class); 55 private static final Logger log = getLogger(OpticalPortOperator.class);
45 56
46 - private OpticalPortOperator() { 57 + /**
58 + * Port.Type this PortConfigOperator reacts on.
59 + */
60 + private final Set<Port.Type> optical = Sets.immutableEnumSet(Port.Type.ODUCLT,
61 + Port.Type.OMS,
62 + Port.Type.OCH,
63 + Port.Type.OTU,
64 + Port.Type.FIBER,
65 + Port.Type.PACKET);
66 +
67 + private NetworkConfigService networkConfigService;
68 +
69 +
70 + public OpticalPortOperator() {
71 + }
72 +
73 + @Override
74 + public void bindService(NetworkConfigService networkConfigService) {
75 + this.networkConfigService = networkConfigService;
76 + }
77 +
78 + private OpticalPortConfig lookupConfig(ConnectPoint cp) {
79 + if (networkConfigService == null) {
80 + return null;
81 + }
82 + return networkConfigService.getConfig(cp, OpticalPortConfig.class);
47 } 83 }
48 84
49 /** 85 /**
50 * Generates a PortDescription containing fields from a PortDescription and 86 * Generates a PortDescription containing fields from a PortDescription and
51 * an OpticalPortConfig. 87 * an OpticalPortConfig.
52 * 88 *
53 - * @param opc the port config entity from network config 89 + * @param cp {@link ConnectPoint} representing the port.
54 - * @param descr a PortDescription 90 + * @param descr input {@link PortDescription}
55 - * @return PortDescription based on both sources 91 + * @return Combined {@link PortDescription}
56 */ 92 */
57 - public static PortDescription combine(OpticalPortConfig opc, PortDescription descr) { 93 + @Override
94 + public PortDescription combine(ConnectPoint cp, PortDescription descr) {
95 + checkNotNull(cp);
96 +
97 + // short-circuit for non-optical ports
98 + // must be removed if we need type override
99 + if (descr != null && !optical.contains(descr.type())) {
100 + return descr;
101 + }
102 +
103 + OpticalPortConfig opc = lookupConfig(cp);
58 if (opc == null) { 104 if (opc == null) {
59 return descr; 105 return descr;
60 } 106 }
61 107
62 - PortNumber port = descr.portNumber(); 108 + PortNumber number = descr.portNumber();
63 - final String name = opc.name(); 109 + // handle PortNumber "name" portion
64 - final String numName = opc.numberName(); 110 + if (!opc.name().isEmpty()) {
65 - // if the description is null, or the current description port name != config name, 111 + number = PortNumber.portNumber(descr.portNumber().toLong(), opc.name());
66 - // create a new PortNumber.
67 - PortNumber newPort = null;
68 - if (port == null) {
69 - // try to get the portNumber from the numName.
70 - if (!numName.isEmpty()) {
71 - final long pn = Long.parseLong(numName);
72 - newPort = (!name.isEmpty()) ? PortNumber.portNumber(pn, name) : PortNumber.portNumber(pn);
73 - } else {
74 - // we don't have defining info (a port number value)
75 - throw new RuntimeException("Possible misconfig, bailing on handling for: \n\t" + descr);
76 - }
77 - } else if ((!name.isEmpty()) && !name.equals(port.name())) {
78 - final long pn = (numName.isEmpty()) ? port.toLong() : Long.parseLong(numName);
79 - newPort = PortNumber.portNumber(pn, name);
80 } 112 }
81 113
82 - // Port type won't change unless we're overwriting a port completely. 114 + // handle additional annotations
83 - // Watch out for overwrites to avoid class cast craziness. 115 + SparseAnnotations annotations = combine(opc, descr.annotations());
84 - boolean noOwrite = opc.type() == descr.type();
85 116
86 - SparseAnnotations sa = combine(opc, descr.annotations()); 117 + // (Future work) handle type overwrite?
87 - if (noOwrite) { 118 + Type type = firstNonNull(opc.type(), descr.type());
88 - return updateDescription((newPort == null) ? port : newPort, sa, descr); 119 + if (type != descr.type()) {
89 - } else { 120 + // TODO: Do we need to be able to overwrite Port.Type?
90 - // TODO: must reconstruct a different type of PortDescription. 121 + log.warn("Port type overwrite requested for {}. Ignoring.", cp);
91 - log.info("Type rewrite from {} to {} required", descr.type(), opc.type());
92 } 122 }
93 - return descr; 123 +
124 + return updateDescription(number, annotations, descr);
94 } 125 }
95 126
96 // updates a port description whose port type has not changed. 127 // updates a port description whose port type has not changed.
...@@ -161,8 +192,9 @@ public final class OpticalPortOperator implements ConfigOperator { ...@@ -161,8 +192,9 @@ public final class OpticalPortOperator implements ConfigOperator {
161 * @param an the annotation 192 * @param an the annotation
162 * @return annotation combining both sources 193 * @return annotation combining both sources
163 */ 194 */
164 - public static SparseAnnotations combine(OpticalPortConfig opc, SparseAnnotations an) { 195 + private static SparseAnnotations combine(OpticalPortConfig opc, SparseAnnotations an) {
165 DefaultAnnotations.Builder b = DefaultAnnotations.builder(); 196 DefaultAnnotations.Builder b = DefaultAnnotations.builder();
197 + b.putAll(an);
166 if (!opc.staticPort().isEmpty()) { 198 if (!opc.staticPort().isEmpty()) {
167 b.set(AnnotationKeys.STATIC_PORT, opc.staticPort()); 199 b.set(AnnotationKeys.STATIC_PORT, opc.staticPort());
168 } 200 }
...@@ -173,7 +205,8 @@ public final class OpticalPortOperator implements ConfigOperator { ...@@ -173,7 +205,8 @@ public final class OpticalPortOperator implements ConfigOperator {
173 if (!opc.name().isEmpty()) { 205 if (!opc.name().isEmpty()) {
174 b.set(AnnotationKeys.PORT_NAME, opc.name()); 206 b.set(AnnotationKeys.PORT_NAME, opc.name());
175 } 207 }
176 - return DefaultAnnotations.union(an, b.build()); 208 + return b.build();
177 } 209 }
178 210
211 +
179 } 212 }
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 + * use this file except in compliance with the License. You may obtain a copy of
6 + * the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 + * License for the specific language governing permissions and limitations under
14 + * the License.
15 + */
16 +/**
17 + * Various optical model related configurations.
18 + */
19 +package org.onosproject.net.optical.config;
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net.optical.internal;
17 +
18 +import static org.onosproject.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
19 +
20 +import org.apache.felix.scr.annotations.Activate;
21 +import org.apache.felix.scr.annotations.Component;
22 +import org.apache.felix.scr.annotations.Deactivate;
23 +import org.apache.felix.scr.annotations.Reference;
24 +import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.onosproject.net.ConnectPoint;
26 +import org.onosproject.net.config.ConfigFactory;
27 +import org.onosproject.net.config.NetworkConfigRegistry;
28 +import org.onosproject.net.config.PortConfigOperatorRegistry;
29 +import org.onosproject.net.optical.config.OpticalPortConfig;
30 +import org.onosproject.net.optical.config.OpticalPortOperator;
31 +import org.slf4j.Logger;
32 +import org.slf4j.LoggerFactory;
33 +
34 +/**
35 + * Loader which registers optical model related config, etc.
36 + */
37 +@Component(immediate = true)
38 +public class OpticalModelLoader {
39 +
40 + private final Logger log = LoggerFactory.getLogger(getClass());
41 +
42 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
43 + protected PortConfigOperatorRegistry portOperatorRegistry;
44 +
45 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
46 + protected NetworkConfigRegistry netcfgRegistry;
47 +
48 +
49 + private OpticalPortOperator opticalPortOp;
50 +
51 + private ConfigFactory<ConnectPoint, OpticalPortConfig>
52 + opticalPortConfigFactory = new ConfigFactory<ConnectPoint, OpticalPortConfig>(CONNECT_POINT_SUBJECT_FACTORY,
53 + OpticalPortConfig.class,
54 + "optical") {
55 + @Override
56 + public OpticalPortConfig createConfig() {
57 + return new OpticalPortConfig();
58 + }
59 + };
60 +
61 + @Activate
62 + protected void activate() {
63 + netcfgRegistry.registerConfigFactory(opticalPortConfigFactory);
64 +
65 + opticalPortOp = new OpticalPortOperator();
66 + portOperatorRegistry.registerPortConfigOperator(opticalPortOp,
67 + OpticalPortConfig.class);
68 +
69 + log.info("Started");
70 + }
71 +
72 + @Deactivate
73 + protected void deactivate() {
74 + portOperatorRegistry.unregisterPortConfigOperator(opticalPortOp);
75 +
76 + netcfgRegistry.unregisterConfigFactory(opticalPortConfigFactory);
77 + log.info("Stopped");
78 + }
79 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 + * use this file except in compliance with the License. You may obtain a copy of
6 + * the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 + * License for the specific language governing permissions and limitations under
14 + * the License.
15 + */
16 +/**
17 + * Internal tools for optical model.
18 + */
19 +package org.onosproject.net.optical.internal;
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.incubator.net.config.basics; 16 +package org.onosproject.net.optical.config;
17 17
18 import static org.junit.Assert.assertEquals; 18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse; 19 import static org.junit.Assert.assertFalse;
20 -import static org.onosproject.net.config.basics.OpticalPortConfig.TYPE; 20 +import static org.onosproject.net.optical.config.OpticalPortConfig.NAME;
21 -import static org.onosproject.net.config.basics.OpticalPortConfig.NAME; 21 +import static org.onosproject.net.optical.config.OpticalPortConfig.PORT;
22 -import static org.onosproject.net.config.basics.OpticalPortConfig.PORT; 22 +import static org.onosproject.net.optical.config.OpticalPortConfig.STATIC_LAMBDA;
23 -import static org.onosproject.net.config.basics.OpticalPortConfig.STATIC_LAMBDA; 23 +import static org.onosproject.net.optical.config.OpticalPortConfig.STATIC_PORT;
24 -import static org.onosproject.net.config.basics.OpticalPortConfig.STATIC_PORT; 24 +import static org.onosproject.net.optical.config.OpticalPortConfig.TYPE;
25 25
26 import java.io.IOException; 26 import java.io.IOException;
27 import java.util.Iterator; 27 import java.util.Iterator;
...@@ -41,7 +41,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -41,7 +41,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
41 import com.fasterxml.jackson.databind.node.JsonNodeFactory; 41 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
42 import com.fasterxml.jackson.databind.node.ObjectNode; 42 import com.fasterxml.jackson.databind.node.ObjectNode;
43 import com.google.common.collect.Lists; 43 import com.google.common.collect.Lists;
44 -import org.onosproject.net.config.basics.OpticalPortConfig;
45 44
46 public class OpticalPortConfigTest { 45 public class OpticalPortConfigTest {
47 private static final String FIELD = "ports"; 46 private static final String FIELD = "ports";
......
...@@ -13,14 +13,14 @@ ...@@ -13,14 +13,14 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.net.device.impl; 16 +package org.onosproject.net.optical.config;
17 17
18 import org.junit.Before; 18 import org.junit.Before;
19 import org.junit.Test; 19 import org.junit.Test;
20 import org.onosproject.net.CltSignalType; 20 import org.onosproject.net.CltSignalType;
21 import org.onosproject.net.config.Config; 21 import org.onosproject.net.config.Config;
22 import org.onosproject.net.config.ConfigApplyDelegate; 22 import org.onosproject.net.config.ConfigApplyDelegate;
23 -import org.onosproject.net.config.basics.OpticalPortConfig; 23 +import org.onosproject.net.config.NetworkConfigServiceAdapter;
24 import org.onosproject.net.AnnotationKeys; 24 import org.onosproject.net.AnnotationKeys;
25 import org.onosproject.net.ConnectPoint; 25 import org.onosproject.net.ConnectPoint;
26 import org.onosproject.net.DefaultAnnotations; 26 import org.onosproject.net.DefaultAnnotations;
...@@ -29,6 +29,7 @@ import org.onosproject.net.Port; ...@@ -29,6 +29,7 @@ import org.onosproject.net.Port;
29 import org.onosproject.net.PortNumber; 29 import org.onosproject.net.PortNumber;
30 import org.onosproject.net.SparseAnnotations; 30 import org.onosproject.net.SparseAnnotations;
31 import org.onosproject.net.device.PortDescription; 31 import org.onosproject.net.device.PortDescription;
32 +
32 import com.fasterxml.jackson.databind.ObjectMapper; 33 import com.fasterxml.jackson.databind.ObjectMapper;
33 import com.fasterxml.jackson.databind.node.JsonNodeFactory; 34 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
34 35
...@@ -62,27 +63,33 @@ public class OpticalPortOperatorTest { ...@@ -62,27 +63,33 @@ public class OpticalPortOperatorTest {
62 63
63 private static final ConnectPoint CP = new ConnectPoint(DID, UNNAMED); 64 private static final ConnectPoint CP = new ConnectPoint(DID, UNNAMED);
64 65
65 - private static final OpticalPortConfig OPC = new OpticalPortConfig(); 66 + private OpticalPortConfig opc;
67 +
68 + private OpticalPortOperator oper;
66 69
67 @Before 70 @Before
68 public void setUp() { 71 public void setUp() {
69 - OPC.init(CP, CFG_KEY, JsonNodeFactory.instance.objectNode(), mapper, delegate); 72 + opc = new OpticalPortConfig();
73 + opc.init(CP, CFG_KEY, JsonNodeFactory.instance.objectNode(), mapper, delegate);
74 +
75 + oper = new OpticalPortOperator();
76 + oper.bindService(new MockNetworkConfigService());
70 } 77 }
71 78
72 @Test 79 @Test
73 public void testConfigPortName() { 80 public void testConfigPortName() {
74 - OPC.portType(Port.Type.ODUCLT) 81 + opc.portType(Port.Type.ODUCLT)
75 .portNumberName(PORT_NUMBER) 82 .portNumberName(PORT_NUMBER)
76 .portName(CFG_PORT_NAME); 83 .portName(CFG_PORT_NAME);
77 84
78 PortDescription res; 85 PortDescription res;
79 // full desc + opc with name 86 // full desc + opc with name
80 - res = OpticalPortOperator.combine(OPC, N_DESC); 87 + res = oper.combine(CP, N_DESC);
81 assertEquals("Configured port name expected", 88 assertEquals("Configured port name expected",
82 CFG_PORT_NAME, res.portNumber().name()); 89 CFG_PORT_NAME, res.portNumber().name());
83 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT)); 90 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
84 91
85 - res = OpticalPortOperator.combine(OPC, U_DESC); 92 + res = oper.combine(CP, U_DESC);
86 assertEquals("Configured port name expected", 93 assertEquals("Configured port name expected",
87 CFG_PORT_NAME, res.portNumber().name()); 94 CFG_PORT_NAME, res.portNumber().name());
88 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT)); 95 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
...@@ -90,12 +97,12 @@ public class OpticalPortOperatorTest { ...@@ -90,12 +97,12 @@ public class OpticalPortOperatorTest {
90 97
91 @Test 98 @Test
92 public void testConfigAddStaticLambda() { 99 public void testConfigAddStaticLambda() {
93 - OPC.portType(Port.Type.ODUCLT) 100 + opc.portType(Port.Type.ODUCLT)
94 .portNumberName(PORT_NUMBER) 101 .portNumberName(PORT_NUMBER)
95 .staticLambda(CFG_STATIC_LAMBDA); 102 .staticLambda(CFG_STATIC_LAMBDA);
96 103
97 PortDescription res; 104 PortDescription res;
98 - res = OpticalPortOperator.combine(OPC, N_DESC); 105 + res = oper.combine(CP, N_DESC);
99 assertEquals("Original port name expected", 106 assertEquals("Original port name expected",
100 DESC_PORT_NAME, res.portNumber().name()); 107 DESC_PORT_NAME, res.portNumber().name());
101 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT)); 108 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
...@@ -105,17 +112,31 @@ public class OpticalPortOperatorTest { ...@@ -105,17 +112,31 @@ public class OpticalPortOperatorTest {
105 112
106 @Test 113 @Test
107 public void testEmptyConfig() { 114 public void testEmptyConfig() {
108 - OPC.portType(Port.Type.ODUCLT) 115 + opc.portType(Port.Type.ODUCLT)
109 .portNumberName(PORT_NUMBER); 116 .portNumberName(PORT_NUMBER);
110 117
111 PortDescription res; 118 PortDescription res;
112 - res = OpticalPortOperator.combine(OPC, N_DESC); 119 + res = oper.combine(CP, N_DESC);
113 assertEquals("Configured port name expected", 120 assertEquals("Configured port name expected",
114 DESC_PORT_NAME, res.portNumber().name()); 121 DESC_PORT_NAME, res.portNumber().name());
115 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT)); 122 assertEquals(DESC_STATIC_PORT, res.annotations().value(AnnotationKeys.STATIC_PORT));
116 } 123 }
117 124
118 125
126 + private class MockNetworkConfigService
127 + extends NetworkConfigServiceAdapter {
128 +
129 + @Override
130 + public <S, C extends Config<S>> C getConfig(S subject,
131 + Class<C> configClass) {
132 + if (configClass == OpticalPortConfig.class) {
133 + return (C) opc;
134 + }
135 + return null;
136 + }
137 + }
138 +
139 +
119 private class MockCfgDelegate implements ConfigApplyDelegate { 140 private class MockCfgDelegate implements ConfigApplyDelegate {
120 141
121 @Override 142 @Override
......
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net.config;
17 +
18 +import org.onosproject.net.ConnectPoint;
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.net.device.PortDescription;
21 +
22 +import com.google.common.annotations.Beta;
23 +
24 +/**
25 + * {@link ConfigOperator} for Port.
26 + * <p>
27 + * Note: We currently assumes {@link PortConfigOperator}s are commutative.
28 + */
29 +@Beta
30 +public interface PortConfigOperator extends ConfigOperator {
31 +
32 + /**
33 + * Binds {@link NetworkConfigService} to use for retrieving configuration.
34 + *
35 + * @param networkConfigService the service to use
36 + */
37 + void bindService(NetworkConfigService networkConfigService);
38 +
39 +
40 + /**
41 + * Generates a PortDescription containing fields from a PortDescription and
42 + * configuration.
43 + *
44 + * @param cp {@link ConnectPoint} representing the port.
45 + * @param descr input {@link PortDescription}
46 + * @return Combined {@link PortDescription}
47 + */
48 + PortDescription combine(ConnectPoint cp, PortDescription descr);
49 +
50 + /**
51 + * Generates a PortDescription containing fields from a PortDescription and
52 + * configuration.
53 + *
54 + * @param did DeviceId which the port described by {@code descr} resides.
55 + * @param descr input {@link PortDescription}
56 + * @return Combined {@link PortDescription}
57 + */
58 + default PortDescription combine(DeviceId did, PortDescription descr) {
59 + return combine(new ConnectPoint(did, descr.portNumber()), descr);
60 + }
61 +
62 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 + * use this file except in compliance with the License. You may obtain a copy of
6 + * the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 + * License for the specific language governing permissions and limitations under
14 + * the License.
15 + */
16 +package org.onosproject.net.config;
17 +
18 +import org.onosproject.net.ConnectPoint;
19 +
20 +import com.google.common.annotations.Beta;
21 +
22 +/**
23 + * Abstraction of a port operator registry.
24 + */
25 +@Beta
26 +public interface PortConfigOperatorRegistry {
27 +
28 + /**
29 + * Registers {@link PortConfigOperator} instance.
30 + *
31 + * @param portOp {@link PortConfigOperator} instance.
32 + * @param configs {@link Config} class for a Port referred by {@code portOp}
33 + */
34 + void registerPortConfigOperator(PortConfigOperator portOp,
35 + Class<? extends Config<ConnectPoint>>... configs);
36 +
37 + /**
38 + * Unregisters {@link PortConfigOperator} instance.
39 + *
40 + * @param portOp {@link PortConfigOperator} instance.
41 + */
42 + void unregisterPortConfigOperator(PortConfigOperator portOp);
43 +
44 +}
...@@ -105,9 +105,7 @@ ...@@ -105,9 +105,7 @@
105 </dependency> 105 </dependency>
106 106
107 <!-- TODO Remove after decoupling optical --> 107 <!-- TODO Remove after decoupling optical -->
108 - <!-- - DeviceManager.InternalDeviceProviderService#ensureGeneric -->
109 <!-- - OpticalCompilers x4 --> 108 <!-- - OpticalCompilers x4 -->
110 - <!-- - OpticalPortOperator -->
111 <dependency> 109 <dependency>
112 <groupId>org.onosproject</groupId> 110 <groupId>org.onosproject</groupId>
113 <artifactId>onos-optical-model</artifactId> 111 <artifactId>onos-optical-model</artifactId>
......
...@@ -34,7 +34,6 @@ import org.onosproject.net.config.NetworkConfigRegistry; ...@@ -34,7 +34,6 @@ import org.onosproject.net.config.NetworkConfigRegistry;
34 import org.onosproject.net.config.basics.BasicDeviceConfig; 34 import org.onosproject.net.config.basics.BasicDeviceConfig;
35 import org.onosproject.net.config.basics.BasicHostConfig; 35 import org.onosproject.net.config.basics.BasicHostConfig;
36 import org.onosproject.net.config.basics.BasicLinkConfig; 36 import org.onosproject.net.config.basics.BasicLinkConfig;
37 -import org.onosproject.net.config.basics.OpticalPortConfig;
38 import org.onosproject.net.config.basics.SubjectFactories; 37 import org.onosproject.net.config.basics.SubjectFactories;
39 import org.slf4j.Logger; 38 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory; 39 import org.slf4j.LoggerFactory;
...@@ -85,15 +84,6 @@ public class BasicNetworkConfigs implements BasicNetworkConfigService { ...@@ -85,15 +84,6 @@ public class BasicNetworkConfigs implements BasicNetworkConfigService {
85 public BasicLinkConfig createConfig() { 84 public BasicLinkConfig createConfig() {
86 return new BasicLinkConfig(); 85 return new BasicLinkConfig();
87 } 86 }
88 - },
89 - // TODO move this optical specific configuration out to optical app
90 - new ConfigFactory<ConnectPoint, OpticalPortConfig>(CONNECT_POINT_SUBJECT_FACTORY,
91 - OpticalPortConfig.class,
92 - "optical") {
93 - @Override
94 - public OpticalPortConfig createConfig() {
95 - return new OpticalPortConfig();
96 - }
97 } 87 }
98 ); 88 );
99 89
......