Avantika-Huawei
Committed by Gerrit Code Review

[ONOS-4166] Store device capapbilities using network config

Change-Id: Ib085c516bec0ecf9845e009eca090aad9302fbb0
...@@ -132,5 +132,10 @@ ...@@ -132,5 +132,10 @@
132 <artifactId>onlab-misc</artifactId> 132 <artifactId>onlab-misc</artifactId>
133 <version>${project.version}</version> 133 <version>${project.version}</version>
134 </dependency> 134 </dependency>
135 + <dependency>
136 + <groupId>org.onosproject</groupId>
137 + <artifactId>onos-app-pcep-api</artifactId>
138 + <version>${project.version}</version>
139 + </dependency>
135 </dependencies> 140 </dependencies>
136 </project> 141 </project>
......
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.pcep.api;
17 +
18 +import org.onosproject.net.DeviceId;
19 +import org.onosproject.net.config.Config;
20 +
21 +/**
22 + * Configuration to specify device capabilities.
23 + */
24 +public class DeviceCapability extends Config<DeviceId> {
25 + public static final String SRCAP = "srCapabaility";
26 + public static final String LABELSTACKCAP = "labelStackCapability";
27 + public static final String LOCALLABELCAP = "localLabelCapability";
28 +
29 + @Override
30 + public boolean isValid() {
31 + return true;
32 + }
33 +
34 + /**
35 + * Gets the SR capability of the router.
36 + *
37 + * @return SR capability
38 + */
39 + public boolean srCap() {
40 + String srCap = get(SRCAP, null);
41 + return srCap != null ?
42 + Boolean.valueOf(srCap) :
43 + false;
44 + }
45 +
46 + /**
47 + * Gets the label stack capability of the router.
48 + *
49 + * @return label stack capability
50 + */
51 + public boolean labelStackCap() {
52 + String labelStackCap = get(LABELSTACKCAP, null);
53 + return labelStackCap != null ?
54 + Boolean.valueOf(labelStackCap) :
55 + false;
56 + }
57 +
58 + /**
59 + * Gets the local label capability of the router.
60 + *
61 + * @return local label capability
62 + */
63 + public boolean localLabelCap() {
64 + String localLabelCap = get(LOCALLABELCAP, null);
65 + return localLabelCap != null ?
66 + Boolean.valueOf(localLabelCap) :
67 + false;
68 + }
69 +
70 + /**
71 + * Sets the SR capability of the router.
72 + *
73 + * @param srCap SR capability of the router.
74 + * @return the capability configuration of the device.
75 + */
76 + public DeviceCapability setSrCap(boolean srCap) {
77 + return (DeviceCapability) setOrClear(SRCAP, srCap);
78 + }
79 +
80 + /**
81 + * Sets the label stack capability of the router.
82 + *
83 + * @param labelStackCap label stack capability of the router.
84 + * @return the capability configuration of the device.
85 + */
86 + public DeviceCapability setLabelStackCap(boolean labelStackCap) {
87 + return (DeviceCapability) setOrClear(LABELSTACKCAP, labelStackCap);
88 + }
89 +
90 + /**
91 + * Sets the local label capability of the router.
92 + *
93 + * @param localLabelCap local label capability of the router.
94 + * @return the capability configuration of the device.
95 + */
96 + public DeviceCapability setLocalLabelCap(boolean localLabelCap) {
97 + return (DeviceCapability) setOrClear(LOCALLABELCAP, localLabelCap);
98 + }
99 +}
100 +
...@@ -25,12 +25,12 @@ public interface PcepNodeListener { ...@@ -25,12 +25,12 @@ public interface PcepNodeListener {
25 * 25 *
26 * @param pc PCEP client details 26 * @param pc PCEP client details
27 */ 27 */
28 - void addNode(PcepClient pc); 28 + void addDevicePcepConfig(PcepClient pc);
29 29
30 /** 30 /**
31 * Notifies that the node was removed. 31 * Notifies that the node was removed.
32 * 32 *
33 * @param pccId PCEP client ID 33 * @param pccId PCEP client ID
34 */ 34 */
35 - void deleteNode(PccId pccId); 35 + void deleteDevicePcepConfig(PccId pccId);
36 } 36 }
......
...@@ -261,7 +261,7 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -261,7 +261,7 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
261 disconnectDuplicate(h); 261 disconnectDuplicate(h);
262 } else { 262 } else {
263 h.setState(ESTABLISHED); 263 h.setState(ESTABLISHED);
264 - //Session is established, add a PCEP device 264 + //Session is established, add a network configuration with LSR id and device capabilities.
265 h.addNode(); 265 h.addNode();
266 } 266 }
267 } 267 }
...@@ -472,14 +472,14 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -472,14 +472,14 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
472 } 472 }
473 473
474 /** 474 /**
475 - * Adds PCEP device once session is established. 475 + * Adds PCEP device configuration with capabilities once session is established.
476 */ 476 */
477 private void addNode() { 477 private void addNode() {
478 pc.addNode(pc); 478 pc.addNode(pc);
479 } 479 }
480 480
481 /** 481 /**
482 - * Deletes PCEP device when session is disconnected. 482 + * Deletes PCEP device configuration when session is disconnected.
483 */ 483 */
484 private void deleteNode() { 484 private void deleteNode() {
485 pc.deleteNode(pc.getPccId()); 485 pc.deleteNode(pc.getPccId());
......
...@@ -385,14 +385,14 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -385,14 +385,14 @@ public class PcepClientControllerImpl implements PcepClientController {
385 @Override 385 @Override
386 public void addNode(PcepClient pc) { 386 public void addNode(PcepClient pc) {
387 for (PcepNodeListener l : pcepNodeListener) { 387 for (PcepNodeListener l : pcepNodeListener) {
388 - l.addNode(pc); 388 + l.addDevicePcepConfig(pc);
389 } 389 }
390 } 390 }
391 391
392 @Override 392 @Override
393 public void deleteNode(PccId pccId) { 393 public void deleteNode(PccId pccId) {
394 for (PcepNodeListener l : pcepNodeListener) { 394 for (PcepNodeListener l : pcepNodeListener) {
395 - l.deleteNode(pccId); 395 + l.deleteDevicePcepConfig(pccId);
396 } 396 }
397 } 397 }
398 398
......
...@@ -29,6 +29,10 @@ import org.onosproject.net.DefaultAnnotations; ...@@ -29,6 +29,10 @@ import org.onosproject.net.DefaultAnnotations;
29 import org.onosproject.net.Device; 29 import org.onosproject.net.Device;
30 import org.onosproject.net.DeviceId; 30 import org.onosproject.net.DeviceId;
31 import org.onosproject.net.Link.Type; 31 import org.onosproject.net.Link.Type;
32 +import org.onosproject.net.config.ConfigFactory;
33 +import org.onosproject.net.config.NetworkConfigRegistry;
34 +import org.onosproject.net.config.NetworkConfigService;
35 +import org.onosproject.net.config.basics.SubjectFactories;
32 import org.onosproject.net.MastershipRole; 36 import org.onosproject.net.MastershipRole;
33 import org.onosproject.net.OchPort; 37 import org.onosproject.net.OchPort;
34 import org.onosproject.net.OduCltPort; 38 import org.onosproject.net.OduCltPort;
...@@ -54,6 +58,7 @@ import org.onosproject.net.link.LinkProviderService; ...@@ -54,6 +58,7 @@ import org.onosproject.net.link.LinkProviderService;
54 import org.onosproject.net.link.LinkService; 58 import org.onosproject.net.link.LinkService;
55 import org.onosproject.net.provider.AbstractProvider; 59 import org.onosproject.net.provider.AbstractProvider;
56 import org.onosproject.net.provider.ProviderId; 60 import org.onosproject.net.provider.ProviderId;
61 +import org.onosproject.pcep.api.DeviceCapability;
57 import org.onosproject.pcep.api.PcepController; 62 import org.onosproject.pcep.api.PcepController;
58 import org.onosproject.pcep.api.PcepDpid; 63 import org.onosproject.pcep.api.PcepDpid;
59 import org.onosproject.pcep.api.PcepLink; 64 import org.onosproject.pcep.api.PcepLink;
...@@ -122,29 +127,26 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -122,29 +127,26 @@ public class PcepTopologyProvider extends AbstractProvider
122 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 127 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
123 protected PcepClientController pcepClientController; 128 protected PcepClientController pcepClientController;
124 129
130 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
131 + protected NetworkConfigRegistry netConfigRegistry;
132 +
133 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
134 + protected NetworkConfigService netConfigService;
135 +
125 private DeviceProviderService deviceProviderService; 136 private DeviceProviderService deviceProviderService;
126 private LinkProviderService linkProviderService; 137 private LinkProviderService linkProviderService;
127 138
128 private HashMap<Long, List<PortDescription>> portMap = new HashMap<>(); 139 private HashMap<Long, List<PortDescription>> portMap = new HashMap<>();
129 private InternalLinkProvider listener = new InternalLinkProvider(); 140 private InternalLinkProvider listener = new InternalLinkProvider();
130 141
131 - /* 142 + private final ConfigFactory<DeviceId, DeviceCapability> configFactory =
132 - * For the client supporting SR capability. 143 + new ConfigFactory<DeviceId, DeviceCapability>(SubjectFactories.DEVICE_SUBJECT_FACTORY,
133 - */ 144 + DeviceCapability.class, "deviceCapability", true) {
134 - public static final String SR_CAPABILITY = "srCapability"; 145 + @Override
135 - 146 + public DeviceCapability createConfig() {
136 - /* 147 + return new DeviceCapability();
137 - * For the client supporting PCECC capability. 148 + }
138 - */ 149 + };
139 - public static final String PCECC_CAPABILITY = "pceccCapability";
140 -
141 - /*
142 - * For the client supporting label stack capability.
143 - */
144 - public static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
145 -
146 - public static final String LSRID = "lsrId";
147 - private static final String UNKNOWN = "unknown";
148 150
149 @Activate 151 @Activate
150 public void activate() { 152 public void activate() {
...@@ -153,6 +155,7 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -153,6 +155,7 @@ public class PcepTopologyProvider extends AbstractProvider
153 controller.addListener(listener); 155 controller.addListener(listener);
154 controller.addLinkListener(listener); 156 controller.addLinkListener(listener);
155 pcepClientController.addNodeListener(listener); 157 pcepClientController.addNodeListener(listener);
158 + netConfigRegistry.registerConfigFactory(configFactory);
156 } 159 }
157 160
158 @Deactivate 161 @Deactivate
...@@ -162,6 +165,7 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -162,6 +165,7 @@ public class PcepTopologyProvider extends AbstractProvider
162 controller.removeListener(listener); 165 controller.removeListener(listener);
163 controller.removeLinkListener(listener); 166 controller.removeLinkListener(listener);
164 pcepClientController.removeNodeListener(listener); 167 pcepClientController.removeNodeListener(listener);
168 + netConfigRegistry.unregisterConfigFactory(configFactory);
165 } 169 }
166 170
167 private List<PortDescription> buildPortDescriptions(PcepDpid dpid, 171 private List<PortDescription> buildPortDescriptions(PcepDpid dpid,
...@@ -334,49 +338,27 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -334,49 +338,27 @@ public class PcepTopologyProvider extends AbstractProvider
334 } 338 }
335 339
336 @Override 340 @Override
337 - public void addNode(PcepClient pc) { 341 + public void addDevicePcepConfig(PcepClient pc) {
338 - if (deviceProviderService == null) { 342 + if (netConfigRegistry == null) {
343 + log.error("Cannot add PCEP device capability as network config service is not available.");
339 return; 344 return;
340 } 345 }
341 - 346 + DeviceId pccDeviceId = DeviceId.deviceId(String.valueOf(pc.getPccId().ipAddress()));
342 - //Right now device URI for PCEP devices is their LSRID 347 + DeviceCapability deviceCap = netConfigService.addConfig(pccDeviceId, DeviceCapability.class);
343 - DeviceId deviceId = deviceId(uri(new PcepDpid(pc.getPccId().id().getIp4Address().toInt()))); 348 + deviceCap.setLabelStackCap(pc.capability().labelStackCapability())
344 - ChassisId cId = new ChassisId(); 349 + .setLocalLabelCap(pc.capability().pceccCapability())
345 - 350 + .setSrCap(pc.capability().srCapability())
346 - Device.Type deviceType = Device.Type.ROUTER; 351 + .apply();
347 -
348 - DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder();
349 - //PCC capabilities (SR, PCECC and PCECC-SR)
350 - annotationBuilder.set(SR_CAPABILITY, String.valueOf(pc.capability().srCapability()));
351 - annotationBuilder.set(PCECC_CAPABILITY, String.valueOf(pc.capability().pceccCapability()));
352 - annotationBuilder.set(LABEL_STACK_CAPABILITY, String.valueOf(pc.capability().labelStackCapability()));
353 - //PccId is the lsrId contained in openMsg, if not present it will be the socket address
354 - annotationBuilder.set(LSRID, String.valueOf(pc.getPccId().id()));
355 -
356 - DeviceDescription description = new DefaultDeviceDescription(
357 - deviceId.uri(),
358 - deviceType,
359 - UNKNOWN,
360 - UNKNOWN,
361 - UNKNOWN,
362 - UNKNOWN,
363 - cId,
364 - annotationBuilder.build());
365 -
366 - deviceProviderService.deviceConnected(deviceId, description);
367 } 352 }
368 353
369 @Override 354 @Override
370 - public void deleteNode(PccId pccId) { 355 + public void deleteDevicePcepConfig(PccId pccId) {
371 - if (deviceProviderService == null || deviceService == null) { 356 + if (netConfigRegistry == null) {
372 - return; 357 + log.error("Cannot remove PCEP device capability as network config service is not available.");
373 - }
374 - //TODO: In device manager, in deviceDisconnected() method, get the device but null check is not validated
375 - if (deviceService.getDevice(DeviceId.deviceId(uri(new PcepDpid(pccId.id()
376 - .getIp4Address().toInt())))) == null) {
377 return; 358 return;
378 } 359 }
379 - deviceProviderService.deviceDisconnected(deviceId(uri(new PcepDpid(pccId.id().getIp4Address().toInt())))); 360 + DeviceId pccDeviceId = DeviceId.deviceId(String.valueOf(pccId.ipAddress()));
361 + netConfigService.removeConfig(pccDeviceId, DeviceCapability.class);
380 } 362 }
381 } 363 }
382 364
......
...@@ -271,14 +271,14 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -271,14 +271,14 @@ public class PcepClientControllerAdapter implements PcepClientController {
271 @Override 271 @Override
272 public void addNode(PcepClient pc) { 272 public void addNode(PcepClient pc) {
273 for (PcepNodeListener l : pcepNodeListener) { 273 for (PcepNodeListener l : pcepNodeListener) {
274 - l.addNode(pc); 274 + l.addDevicePcepConfig(pc);
275 } 275 }
276 } 276 }
277 277
278 @Override 278 @Override
279 public void deleteNode(PccId pccId) { 279 public void deleteNode(PccId pccId) {
280 for (PcepNodeListener l : pcepNodeListener) { 280 for (PcepNodeListener l : pcepNodeListener) {
281 - l.deleteNode(pccId); 281 + l.deleteDevicePcepConfig(pccId);
282 } 282 }
283 } 283 }
284 284
......
...@@ -12,13 +12,7 @@ ...@@ -12,13 +12,7 @@
12 */ 12 */
13 package org.onosproject.provider.pcep.topology.impl; 13 package org.onosproject.provider.pcep.topology.impl;
14 14
15 -import static org.hamcrest.MatcherAssert.assertThat;
16 -import static org.hamcrest.core.Is.is;
17 import static org.onosproject.net.Link.State.ACTIVE; 15 import static org.onosproject.net.Link.State.ACTIVE;
18 -import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.LABEL_STACK_CAPABILITY;
19 -import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.LSRID;
20 -import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.PCECC_CAPABILITY;
21 -import static org.onosproject.provider.pcep.topology.impl.PcepTopologyProvider.SR_CAPABILITY;
22 16
23 import java.util.Collection; 17 import java.util.Collection;
24 import java.util.HashMap; 18 import java.util.HashMap;
...@@ -39,6 +33,10 @@ import org.onosproject.net.Device; ...@@ -39,6 +33,10 @@ import org.onosproject.net.Device;
39 import org.onosproject.net.DeviceId; 33 import org.onosproject.net.DeviceId;
40 import org.onosproject.net.Link; 34 import org.onosproject.net.Link;
41 import org.onosproject.net.MastershipRole; 35 import org.onosproject.net.MastershipRole;
36 +import org.onosproject.net.config.Config;
37 +import org.onosproject.net.config.ConfigApplyDelegate;
38 +import org.onosproject.net.config.ConfigFactory;
39 +import org.onosproject.net.config.NetworkConfigRegistryAdapter;
42 import org.onosproject.net.device.DeviceDescription; 40 import org.onosproject.net.device.DeviceDescription;
43 import org.onosproject.net.device.DeviceProvider; 41 import org.onosproject.net.device.DeviceProvider;
44 import org.onosproject.net.device.DeviceProviderRegistry; 42 import org.onosproject.net.device.DeviceProviderRegistry;
...@@ -51,11 +49,19 @@ import org.onosproject.net.link.LinkProvider; ...@@ -51,11 +49,19 @@ import org.onosproject.net.link.LinkProvider;
51 import org.onosproject.net.link.LinkProviderRegistry; 49 import org.onosproject.net.link.LinkProviderRegistry;
52 import org.onosproject.net.link.LinkProviderService; 50 import org.onosproject.net.link.LinkProviderService;
53 import org.onosproject.net.provider.ProviderId; 51 import org.onosproject.net.provider.ProviderId;
52 +import org.onosproject.pcep.api.DeviceCapability;
54 import org.onosproject.pcep.controller.ClientCapability; 53 import org.onosproject.pcep.controller.ClientCapability;
55 import org.onosproject.pcep.controller.PccId; 54 import org.onosproject.pcep.controller.PccId;
56 import org.onosproject.pcep.controller.PcepClient; 55 import org.onosproject.pcep.controller.PcepClient;
57 import org.onosproject.pcep.controller.PcepNodeListener; 56 import org.onosproject.pcep.controller.PcepNodeListener;
57 +import com.fasterxml.jackson.databind.JsonNode;
58 +import com.fasterxml.jackson.databind.ObjectMapper;
59 +import com.fasterxml.jackson.databind.node.JsonNodeFactory;
60 +import com.fasterxml.jackson.databind.node.ObjectNode;
58 61
62 +import static org.hamcrest.MatcherAssert.assertThat;
63 +import static org.hamcrest.core.Is.is;
64 +import static org.hamcrest.core.IsNull.nullValue;
59 /** 65 /**
60 * Test for PCEP topology provider. 66 * Test for PCEP topology provider.
61 */ 67 */
...@@ -68,6 +74,7 @@ public class PcepTopologyProviderTest { ...@@ -68,6 +74,7 @@ public class PcepTopologyProviderTest {
68 private final PcepControllerAdapter controller = new PcepControllerAdapter(); 74 private final PcepControllerAdapter controller = new PcepControllerAdapter();
69 private final MockLinkRegistry linkRegistry = new MockLinkRegistry(); 75 private final MockLinkRegistry linkRegistry = new MockLinkRegistry();
70 private final MockDeviceService deviceService = new MockDeviceService(); 76 private final MockDeviceService deviceService = new MockDeviceService();
77 + private final MockNetConfigRegistryAdapter netConfigRegistry = new MockNetConfigRegistryAdapter();
71 private Map<DeviceId, Device> deviceMap = new HashMap<>(); 78 private Map<DeviceId, Device> deviceMap = new HashMap<>();
72 79
73 @Before 80 @Before
...@@ -77,6 +84,8 @@ public class PcepTopologyProviderTest { ...@@ -77,6 +84,8 @@ public class PcepTopologyProviderTest {
77 provider.linkProviderRegistry = linkRegistry; 84 provider.linkProviderRegistry = linkRegistry;
78 provider.controller = controller; 85 provider.controller = controller;
79 provider.deviceService = deviceService; 86 provider.deviceService = deviceService;
87 + provider.netConfigRegistry = netConfigRegistry;
88 + provider.netConfigService = netConfigRegistry;
80 provider.activate(); 89 provider.activate();
81 } 90 }
82 91
...@@ -88,6 +97,8 @@ public class PcepTopologyProviderTest { ...@@ -88,6 +97,8 @@ public class PcepTopologyProviderTest {
88 provider.linkProviderRegistry = null; 97 provider.linkProviderRegistry = null;
89 provider.controller = null; 98 provider.controller = null;
90 provider.deviceService = null; 99 provider.deviceService = null;
100 + provider.netConfigRegistry = null;
101 + provider.netConfigService = null;
91 } 102 }
92 103
93 /* Class implement device test registry */ 104 /* Class implement device test registry */
...@@ -217,24 +228,104 @@ public class PcepTopologyProviderTest { ...@@ -217,24 +228,104 @@ public class PcepTopologyProviderTest {
217 } 228 }
218 } 229 }
219 230
231 + /* Mock test for device service */
232 + private class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter {
233 + private ConfigFactory cfgFactory;
234 + private Map<DeviceId, DeviceCapability> classConfig = new HashMap<>();
235 +
236 + @Override
237 + public void registerConfigFactory(ConfigFactory configFactory) {
238 + cfgFactory = configFactory;
239 + }
240 +
241 + @Override
242 + public void unregisterConfigFactory(ConfigFactory configFactory) {
243 + cfgFactory = null;
244 + }
245 +
246 + @Override
247 + public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) {
248 + if (configClass == DeviceCapability.class) {
249 + DeviceCapability devCap = new DeviceCapability();
250 + classConfig.put((DeviceId) subject, devCap);
251 +
252 + JsonNode node = new ObjectNode(new MockJsonNode());
253 + ObjectMapper mapper = new ObjectMapper();
254 + ConfigApplyDelegate delegate = new InternalApplyDelegate();
255 + devCap.init((DeviceId) subject, null, node, mapper, delegate);
256 + return (C) devCap;
257 + }
258 +
259 + return null;
260 + }
261 +
262 + @Override
263 + public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) {
264 + classConfig.remove(subject);
265 + }
266 +
267 + @Override
268 + public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
269 + if (configClass == DeviceCapability.class) {
270 + return (C) classConfig.get(subject);
271 + }
272 + return null;
273 + }
274 +
275 + private class MockJsonNode extends JsonNodeFactory {
276 + }
277 +
278 + // Auxiliary delegate to receive notifications about changes applied to
279 + // the network configuration - by the apps.
280 + private class InternalApplyDelegate implements ConfigApplyDelegate {
281 + @Override
282 + public void onApply(Config config) {
283 + //configs.put(config.subject(), config.node());
284 + }
285 + }
286 + }
287 +
220 /** 288 /**
221 - * Adds the PCEP device and removes it. 289 + * Adds the PCEP device with SR, label stack and local label capabilities and deletes the device.
222 */ 290 */
223 @Test 291 @Test
224 public void testPcepTopologyProviderTestAddDevice1() { 292 public void testPcepTopologyProviderTestAddDevice1() {
225 PcepClient pc = clientController.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))); 293 PcepClient pc = clientController.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1")));
226 for (PcepNodeListener l : clientController.pcepNodeListener) { 294 for (PcepNodeListener l : clientController.pcepNodeListener) {
227 pc.setCapability(new ClientCapability(true, true, false, true, true)); 295 pc.setCapability(new ClientCapability(true, true, false, true, true));
228 - l.addNode(pc); 296 + l.addDevicePcepConfig(pc);
229 - assertThat(nodeRegistry.connected.size(), is(1)); 297 +
230 - assertThat(deviceMap.keySet().iterator().next(), is(DeviceId.deviceId("l3:1.1.1.1"))); 298 + DeviceId pccDeviceId = DeviceId.deviceId(String.valueOf(pc.getPccId().ipAddress()));
231 - assertThat(deviceMap.values().iterator().next().annotations().value(LABEL_STACK_CAPABILITY), is("true")); 299 + DeviceCapability deviceCap = netConfigRegistry.getConfig(pccDeviceId, DeviceCapability.class);
232 - assertThat(deviceMap.values().iterator().next().annotations().value(LSRID), is("1.1.1.1")); 300 + assertThat(deviceCap.srCap(), is(true));
233 - assertThat(deviceMap.values().iterator().next().annotations().value(PCECC_CAPABILITY), is("true")); 301 + assertThat(deviceCap.labelStackCap(), is(true));
234 - assertThat(deviceMap.values().iterator().next().annotations().value(SR_CAPABILITY), is("true")); 302 + assertThat(deviceCap.localLabelCap(), is(true));
235 - 303 +
236 - l.deleteNode(pc.getPccId()); 304 + l.deleteDevicePcepConfig(pc.getPccId());
237 - assertThat(nodeRegistry.connected.size(), is(0)); 305 + deviceCap = netConfigRegistry.getConfig(pccDeviceId, DeviceCapability.class);
306 + assertThat(deviceCap, is(nullValue()));
307 + }
308 + }
309 +
310 + /**
311 + * Adds the PCEP device with SR, and local label capabilities and deletes the device.
312 + */
313 + @Test
314 + public void testPcepTopologyProviderTestAddDevice2() {
315 + PcepClient pc = clientController.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1")));
316 + for (PcepNodeListener l : clientController.pcepNodeListener) {
317 + pc.setCapability(new ClientCapability(true, true, false, false, true));
318 + l.addDevicePcepConfig(pc);
319 +
320 + DeviceId pccDeviceId = DeviceId.deviceId(String.valueOf(pc.getPccId().ipAddress()));
321 + DeviceCapability deviceCap = netConfigRegistry.getConfig(pccDeviceId, DeviceCapability.class);
322 + assertThat(deviceCap.srCap(), is(true));
323 + assertThat(deviceCap.labelStackCap(), is(false));
324 + assertThat(deviceCap.localLabelCap(), is(true));
325 +
326 + l.deleteDevicePcepConfig(pc.getPccId());
327 + deviceCap = netConfigRegistry.getConfig(pccDeviceId, DeviceCapability.class);
328 + assertThat(deviceCap, is(nullValue()));
238 } 329 }
239 } 330 }
240 } 331 }
......
...@@ -275,14 +275,14 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -275,14 +275,14 @@ public class PcepClientControllerAdapter implements PcepClientController {
275 @Override 275 @Override
276 public void addNode(PcepClient pc) { 276 public void addNode(PcepClient pc) {
277 for (PcepNodeListener l : pcepNodeListener) { 277 for (PcepNodeListener l : pcepNodeListener) {
278 - l.addNode(pc); 278 + l.addDevicePcepConfig(pc);
279 } 279 }
280 } 280 }
281 281
282 @Override 282 @Override
283 public void deleteNode(PccId pccId) { 283 public void deleteNode(PccId pccId) {
284 for (PcepNodeListener l : pcepNodeListener) { 284 for (PcepNodeListener l : pcepNodeListener) {
285 - l.deleteNode(pccId); 285 + l.deleteDevicePcepConfig(pccId);
286 } 286 }
287 } 287 }
288 288
......