Priyanka B
Committed by Priyankab-Huawei

[ONOS] PCEP provider changes, added node listeners to topology provider

Change-Id: I98bc6445ee78a8f0bf53f897f0a25f678ec7fc99
Showing 19 changed files with 1081 additions and 19 deletions
1 COMPILE_DEPS = [ 1 COMPILE_DEPS = [
2 '//lib:CORE_DEPS', 2 '//lib:CORE_DEPS',
3 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio', 3 '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
4 + '//apps/pcep-api:onos-apps-pcep-api',
4 ] 5 ]
5 6
6 osgi_jar_with_tests ( 7 osgi_jar_with_tests (
......
...@@ -26,6 +26,8 @@ public class ClientCapability { ...@@ -26,6 +26,8 @@ public class ClientCapability {
26 private boolean pceccCapability; 26 private boolean pceccCapability;
27 private boolean statefulPceCapability; 27 private boolean statefulPceCapability;
28 private boolean pcInstantiationCapability; 28 private boolean pcInstantiationCapability;
29 + private boolean labelStackCapability;
30 + private boolean srCapability;
29 31
30 /** 32 /**
31 * Creates new instance of client capability. 33 * Creates new instance of client capability.
...@@ -33,11 +35,34 @@ public class ClientCapability { ...@@ -33,11 +35,34 @@ public class ClientCapability {
33 * @param pceccCapability represents PCECC capability 35 * @param pceccCapability represents PCECC capability
34 * @param statefulPceCapability represents stateful PCE capability 36 * @param statefulPceCapability represents stateful PCE capability
35 * @param pcInstantiationCapability represents PC initiation capability 37 * @param pcInstantiationCapability represents PC initiation capability
38 + * @param labelStackCapability represents S bit is set in PCECC capability
39 + * @param srCapability represents SR capability
36 */ 40 */
37 - public ClientCapability(boolean pceccCapability, boolean statefulPceCapability, boolean pcInstantiationCapability) { 41 + public ClientCapability(boolean pceccCapability, boolean statefulPceCapability, boolean pcInstantiationCapability,
42 + boolean labelStackCapability, boolean srCapability) {
38 this.pceccCapability = pceccCapability; 43 this.pceccCapability = pceccCapability;
39 this.statefulPceCapability = statefulPceCapability; 44 this.statefulPceCapability = statefulPceCapability;
40 this.pcInstantiationCapability = pcInstantiationCapability; 45 this.pcInstantiationCapability = pcInstantiationCapability;
46 + this.labelStackCapability = labelStackCapability;
47 + this.srCapability = srCapability;
48 + }
49 +
50 + /**
51 + * Obtains label stack capability.
52 + *
53 + * @return true if client supports PCECC capability with S bit set otherwise false
54 + */
55 + public boolean labelStackCapability() {
56 + return labelStackCapability;
57 + }
58 +
59 + /**
60 + * Obtains segment routing capability.
61 + *
62 + * @return true if client supports SR capability otherwise false
63 + */
64 + public boolean srCapability() {
65 + return srCapability;
41 } 66 }
42 67
43 /** 68 /**
...@@ -69,7 +94,8 @@ public class ClientCapability { ...@@ -69,7 +94,8 @@ public class ClientCapability {
69 94
70 @Override 95 @Override
71 public int hashCode() { 96 public int hashCode() {
72 - return Objects.hash(pceccCapability, statefulPceCapability, pcInstantiationCapability); 97 + return Objects.hash(pceccCapability, statefulPceCapability, pcInstantiationCapability, labelStackCapability,
98 + srCapability);
73 } 99 }
74 100
75 @Override 101 @Override
...@@ -81,7 +107,9 @@ public class ClientCapability { ...@@ -81,7 +107,9 @@ public class ClientCapability {
81 ClientCapability other = (ClientCapability) obj; 107 ClientCapability other = (ClientCapability) obj;
82 return Objects.equals(pceccCapability, other.pceccCapability) 108 return Objects.equals(pceccCapability, other.pceccCapability)
83 && Objects.equals(statefulPceCapability, other.statefulPceCapability) 109 && Objects.equals(statefulPceCapability, other.statefulPceCapability)
84 - && Objects.equals(pcInstantiationCapability, other.pcInstantiationCapability); 110 + && Objects.equals(pcInstantiationCapability, other.pcInstantiationCapability)
111 + && Objects.equals(labelStackCapability, other.labelStackCapability)
112 + && Objects.equals(srCapability, other.srCapability);
85 } 113 }
86 return false; 114 return false;
87 } 115 }
...@@ -92,6 +120,8 @@ public class ClientCapability { ...@@ -92,6 +120,8 @@ public class ClientCapability {
92 .add("pceccCapability", pceccCapability) 120 .add("pceccCapability", pceccCapability)
93 .add("statefulPceCapability", statefulPceCapability) 121 .add("statefulPceCapability", statefulPceCapability)
94 .add("pcInstantiationCapability", pcInstantiationCapability) 122 .add("pcInstantiationCapability", pcInstantiationCapability)
123 + .add("labelStackCapability", labelStackCapability)
124 + .add("srCapability", srCapability)
95 .toString(); 125 .toString();
96 } 126 }
97 } 127 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -135,4 +135,18 @@ public interface PcepClient { ...@@ -135,4 +135,18 @@ public interface PcepClient {
135 * @return capability supported by client 135 * @return capability supported by client
136 */ 136 */
137 ClientCapability capability(); 137 ClientCapability capability();
138 +
139 + /**
140 + * Adds PCEP device when session is successfully established.
141 + *
142 + * @param pc PCEP client details
143 + */
144 + void addNode(PcepClient pc);
145 +
146 + /**
147 + * Removes PCEP device when session is disconnected.
148 + *
149 + * @param pccId PCEP client ID
150 + */
151 + void deleteNode(PccId pccId);
138 } 152 }
......
...@@ -57,7 +57,7 @@ public interface PcepClientController { ...@@ -57,7 +57,7 @@ public interface PcepClientController {
57 void removeListener(PcepClientListener listener); 57 void removeListener(PcepClientListener listener);
58 58
59 /** 59 /**
60 - * Register a listener for OF msg events. 60 + * Register a listener for PCEP msg events.
61 * 61 *
62 * @param listener the listener to notify 62 * @param listener the listener to notify
63 */ 63 */
...@@ -71,6 +71,20 @@ public interface PcepClientController { ...@@ -71,6 +71,20 @@ public interface PcepClientController {
71 void removeEventListener(PcepEventListener listener); 71 void removeEventListener(PcepEventListener listener);
72 72
73 /** 73 /**
74 + * Register a listener for PCEP msg events[carrying node descriptor details].
75 + *
76 + * @param listener the listener to notify
77 + */
78 + void addNodeListener(PcepNodeListener listener);
79 +
80 + /**
81 + * Unregister a listener.
82 + *
83 + * @param listener the listener to be unregistered
84 + */
85 + void removeNodeListener(PcepNodeListener listener);
86 +
87 + /**
74 * Send a message to a particular pcc client. 88 * Send a message to a particular pcc client.
75 * 89 *
76 * @param pccId the id of the client to send message. 90 * @param pccId the id of the client to send message.
......
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.controller;
17 +
18 +/**
19 + * Notifies providers about PCEP node events.
20 + */
21 +public interface PcepNodeListener {
22 +
23 + /**
24 + * Notifies that the node was added.
25 + *
26 + * @param pc PCEP client details
27 + */
28 + void addNode(PcepClient pc);
29 +
30 + /**
31 + * Notifies that the node was removed.
32 + *
33 + * @param pccId PCEP client ID
34 + */
35 + void deleteNode(PccId pccId);
36 +}
...@@ -60,4 +60,17 @@ public interface PcepAgent { ...@@ -60,4 +60,17 @@ public interface PcepAgent {
60 */ 60 */
61 void processPcepMessage(PccId pccId, PcepMessage m); 61 void processPcepMessage(PccId pccId, PcepMessage m);
62 62
63 + /**
64 + * Adds PCEP device when session is successfully established.
65 + *
66 + * @param pc PCEP client details
67 + */
68 + void addNode(PcepClient pc);
69 +
70 + /**
71 + * Removes PCEP device when session is disconnected.
72 + *
73 + * @param pccId PCEP client ID
74 + */
75 + void deleteNode(PccId pccId);
63 } 76 }
......
...@@ -55,6 +55,7 @@ import org.onosproject.pcepio.protocol.PcepVersion; ...@@ -55,6 +55,7 @@ import org.onosproject.pcepio.protocol.PcepVersion;
55 import org.onosproject.pcepio.types.IPv4RouterIdOfLocalNodeSubTlv; 55 import org.onosproject.pcepio.types.IPv4RouterIdOfLocalNodeSubTlv;
56 import org.onosproject.pcepio.types.NodeAttributesTlv; 56 import org.onosproject.pcepio.types.NodeAttributesTlv;
57 import org.onosproject.pcepio.types.PceccCapabilityTlv; 57 import org.onosproject.pcepio.types.PceccCapabilityTlv;
58 +import org.onosproject.pcepio.types.SrPceCapabilityTlv;
58 import org.onosproject.pcepio.types.StatefulPceCapabilityTlv; 59 import org.onosproject.pcepio.types.StatefulPceCapabilityTlv;
59 import org.onosproject.pcepio.types.PcepErrorDetailInfo; 60 import org.onosproject.pcepio.types.PcepErrorDetailInfo;
60 import org.onosproject.pcepio.types.PcepValueType; 61 import org.onosproject.pcepio.types.PcepValueType;
...@@ -260,6 +261,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -260,6 +261,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
260 disconnectDuplicate(h); 261 disconnectDuplicate(h);
261 } else { 262 } else {
262 h.setState(ESTABLISHED); 263 h.setState(ESTABLISHED);
264 + //Session is established, add a PCEP device
265 + h.addNode();
263 } 266 }
264 } 267 }
265 } 268 }
...@@ -469,6 +472,20 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -469,6 +472,20 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
469 } 472 }
470 473
471 /** 474 /**
475 + * Adds PCEP device once session is established.
476 + */
477 + private void addNode() {
478 + pc.addNode(pc);
479 + }
480 +
481 + /**
482 + * Deletes PCEP device when session is disconnected.
483 + */
484 + private void deleteNode() {
485 + pc.deleteNode(pc.getPccId());
486 + }
487 +
488 + /**
472 * Return a string describing this client based on the already available 489 * Return a string describing this client based on the already available
473 * information (ip address and/or remote socket). 490 * information (ip address and/or remote socket).
474 * 491 *
...@@ -523,6 +540,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -523,6 +540,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
523 boolean pceccCapability = false; 540 boolean pceccCapability = false;
524 boolean statefulPceCapability = false; 541 boolean statefulPceCapability = false;
525 boolean pcInstantiationCapability = false; 542 boolean pcInstantiationCapability = false;
543 + boolean labelStackCapability = false;
544 + boolean srCapability = false;
526 545
527 ListIterator<PcepValueType> listIterator = tlvList.listIterator(); 546 ListIterator<PcepValueType> listIterator = tlvList.listIterator();
528 while (listIterator.hasNext()) { 547 while (listIterator.hasNext()) {
...@@ -531,6 +550,9 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -531,6 +550,9 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
531 switch (tlv.getType()) { 550 switch (tlv.getType()) {
532 case PceccCapabilityTlv.TYPE: 551 case PceccCapabilityTlv.TYPE:
533 pceccCapability = true; 552 pceccCapability = true;
553 + if (((PceccCapabilityTlv) tlv).sBit()) {
554 + labelStackCapability = true;
555 + }
534 break; 556 break;
535 case StatefulPceCapabilityTlv.TYPE: 557 case StatefulPceCapabilityTlv.TYPE:
536 statefulPceCapability = true; 558 statefulPceCapability = true;
...@@ -539,11 +561,15 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -539,11 +561,15 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
539 pcInstantiationCapability = true; 561 pcInstantiationCapability = true;
540 } 562 }
541 break; 563 break;
564 + case SrPceCapabilityTlv.TYPE:
565 + srCapability = true;
566 + break;
542 default: 567 default:
543 continue; 568 continue;
544 } 569 }
545 } 570 }
546 - this.capability = new ClientCapability(pceccCapability, statefulPceCapability, pcInstantiationCapability); 571 + this.capability = new ClientCapability(pceccCapability, statefulPceCapability, pcInstantiationCapability,
572 + labelStackCapability, srCapability);
547 } 573 }
548 574
549 /** 575 /**
...@@ -563,6 +589,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler { ...@@ -563,6 +589,8 @@ class PcepChannelHandler extends IdleStateAwareChannelHandler {
563 */ 589 */
564 private void sendErrMsgAndCloseChannel() { 590 private void sendErrMsgAndCloseChannel() {
565 // TODO send error message 591 // TODO send error message
592 + //Remove PCEP device from topology
593 + deleteNode();
566 channel.close(); 594 channel.close();
567 } 595 }
568 596
......
...@@ -25,12 +25,16 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -25,12 +25,16 @@ import java.util.concurrent.ConcurrentHashMap;
25 import org.apache.felix.scr.annotations.Activate; 25 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 26 import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 27 import org.apache.felix.scr.annotations.Deactivate;
28 +import org.apache.felix.scr.annotations.Reference;
29 +import org.apache.felix.scr.annotations.ReferenceCardinality;
28 import org.apache.felix.scr.annotations.Service; 30 import org.apache.felix.scr.annotations.Service;
31 +import org.onosproject.net.device.DeviceService;
29 import org.onosproject.pcep.controller.PccId; 32 import org.onosproject.pcep.controller.PccId;
30 import org.onosproject.pcep.controller.PcepClient; 33 import org.onosproject.pcep.controller.PcepClient;
31 import org.onosproject.pcep.controller.PcepClientController; 34 import org.onosproject.pcep.controller.PcepClientController;
32 import org.onosproject.pcep.controller.PcepClientListener; 35 import org.onosproject.pcep.controller.PcepClientListener;
33 import org.onosproject.pcep.controller.PcepEventListener; 36 import org.onosproject.pcep.controller.PcepEventListener;
37 +import org.onosproject.pcep.controller.PcepNodeListener;
34 import org.onosproject.pcep.controller.driver.PcepAgent; 38 import org.onosproject.pcep.controller.driver.PcepAgent;
35 import org.onosproject.pcepio.protocol.PcepError; 39 import org.onosproject.pcepio.protocol.PcepError;
36 import org.onosproject.pcepio.protocol.PcepErrorInfo; 40 import org.onosproject.pcepio.protocol.PcepErrorInfo;
...@@ -55,6 +59,9 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -55,6 +59,9 @@ public class PcepClientControllerImpl implements PcepClientController {
55 59
56 private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class); 60 private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class);
57 61
62 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 + protected DeviceService deviceService;
64 +
58 protected ConcurrentHashMap<PccId, PcepClient> connectedClients = 65 protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
59 new ConcurrentHashMap<>(); 66 new ConcurrentHashMap<>();
60 67
...@@ -62,6 +69,7 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -62,6 +69,7 @@ public class PcepClientControllerImpl implements PcepClientController {
62 protected Set<PcepClientListener> pcepClientListener = new HashSet<>(); 69 protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
63 70
64 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); 71 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
72 + protected Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
65 73
66 private final Controller ctrl = new Controller(); 74 private final Controller ctrl = new Controller();
67 75
...@@ -117,6 +125,16 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -117,6 +125,16 @@ public class PcepClientControllerImpl implements PcepClientController {
117 } 125 }
118 126
119 @Override 127 @Override
128 + public void addNodeListener(PcepNodeListener listener) {
129 + pcepNodeListener.add(listener);
130 + }
131 +
132 + @Override
133 + public void removeNodeListener(PcepNodeListener listener) {
134 + pcepNodeListener.remove(listener);
135 + }
136 +
137 + @Override
120 public void processClientMessage(PccId pccId, PcepMessage msg) { 138 public void processClientMessage(PccId pccId, PcepMessage msg) {
121 PcepClient pc = getClient(pccId); 139 PcepClient pc = getClient(pccId);
122 140
...@@ -173,6 +191,8 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -173,6 +191,8 @@ public class PcepClientControllerImpl implements PcepClientController {
173 break; 191 break;
174 case LABEL_RANGE_RESERV: 192 case LABEL_RANGE_RESERV:
175 break; 193 break;
194 + case LS_REPORT: //TODO: need to handle LS report to add or remove node
195 + break;
176 case MAX: 196 case MAX:
177 break; 197 break;
178 case END: 198 case END:
...@@ -270,5 +290,19 @@ public class PcepClientControllerImpl implements PcepClientController { ...@@ -270,5 +290,19 @@ public class PcepClientControllerImpl implements PcepClientController {
270 public void processPcepMessage(PccId pccId, PcepMessage m) { 290 public void processPcepMessage(PccId pccId, PcepMessage m) {
271 processClientMessage(pccId, m); 291 processClientMessage(pccId, m);
272 } 292 }
293 +
294 + @Override
295 + public void addNode(PcepClient pc) {
296 + for (PcepNodeListener l : pcepNodeListener) {
297 + l.addNode(pc);
298 + }
299 + }
300 +
301 + @Override
302 + public void deleteNode(PccId pccId) {
303 + for (PcepNodeListener l : pcepNodeListener) {
304 + l.deleteNode(pccId);
305 + }
306 + }
273 } 307 }
274 } 308 }
......
...@@ -26,6 +26,7 @@ import org.jboss.netty.channel.Channel; ...@@ -26,6 +26,7 @@ import org.jboss.netty.channel.Channel;
26 import org.onlab.packet.IpAddress; 26 import org.onlab.packet.IpAddress;
27 import org.onosproject.pcep.controller.ClientCapability; 27 import org.onosproject.pcep.controller.ClientCapability;
28 import org.onosproject.pcep.controller.PccId; 28 import org.onosproject.pcep.controller.PccId;
29 +import org.onosproject.pcep.controller.PcepClient;
29 import org.onosproject.pcep.controller.PcepPacketStats; 30 import org.onosproject.pcep.controller.PcepPacketStats;
30 import org.onosproject.pcep.controller.PcepSyncStatus; 31 import org.onosproject.pcep.controller.PcepSyncStatus;
31 import org.onosproject.pcep.controller.driver.PcepAgent; 32 import org.onosproject.pcep.controller.driver.PcepAgent;
...@@ -203,6 +204,16 @@ public class PcepClientImpl implements PcepClientDriver { ...@@ -203,6 +204,16 @@ public class PcepClientImpl implements PcepClientDriver {
203 } 204 }
204 205
205 @Override 206 @Override
207 + public void addNode(PcepClient pc) {
208 + this.agent.addNode(pc);
209 + }
210 +
211 + @Override
212 + public void deleteNode(PccId pccId) {
213 + this.agent.deleteNode(pccId);
214 + }
215 +
216 + @Override
206 public final boolean connectClient() { 217 public final boolean connectClient() {
207 return this.agent.addConnectedClient(pccId, this); 218 return this.agent.addConnectedClient(pccId, this);
208 } 219 }
......
...@@ -3,6 +3,9 @@ COMPILE_DEPS = [ ...@@ -3,6 +3,9 @@ COMPILE_DEPS = [
3 '//protocols/ovsdb/api:onos-protocols-ovsdb-api', 3 '//protocols/ovsdb/api:onos-protocols-ovsdb-api',
4 '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc', 4 '//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc',
5 '//apps/pcep-api:onos-apps-pcep-api', 5 '//apps/pcep-api:onos-apps-pcep-api',
6 + '//protocols/pcep/api:onos-protocols-pcep-api',
7 + '//protocols/pcep/pcepio:onos-protocols-pcep-pcepio',
8 + '//core/api:onos-api-tests',
6 ] 9 ]
7 10
8 osgi_jar_with_tests ( 11 osgi_jar_with_tests (
......
...@@ -24,10 +24,20 @@ ...@@ -24,10 +24,20 @@
24 <artifactId>onos-pcep-provider-topology</artifactId> 24 <artifactId>onos-pcep-provider-topology</artifactId>
25 <packaging>bundle</packaging> 25 <packaging>bundle</packaging>
26 <description>PCEP topology provider</description> 26 <description>PCEP topology provider</description>
27 - <dependencies>
28 - <dependency>
29 - <groupId>org.onosproject</groupId>
30 - <artifactId>onos-app-pcep-api</artifactId>
31 - </dependency>
32 - </dependencies>
33 -</project>
...\ No newline at end of file ...\ No newline at end of file
27 + <dependencies>
28 + <dependency>
29 + <groupId>org.onosproject</groupId>
30 + <artifactId>onos-app-pcep-api</artifactId>
31 + </dependency>
32 + <dependency>
33 + <groupId>org.onosproject</groupId>
34 + <artifactId>onos-pcep-controller-api</artifactId>
35 + </dependency>
36 + <dependency>
37 + <groupId>org.onosproject</groupId>
38 + <artifactId>onos-api</artifactId>
39 + <classifier>tests</classifier>
40 + <scope>test</scope>
41 + </dependency>
42 + </dependencies>
43 +</project>
......
...@@ -62,6 +62,10 @@ import org.onosproject.pcep.api.PcepLinkListener; ...@@ -62,6 +62,10 @@ import org.onosproject.pcep.api.PcepLinkListener;
62 import org.onosproject.pcep.api.PcepOperator.OperationType; 62 import org.onosproject.pcep.api.PcepOperator.OperationType;
63 import org.onosproject.pcep.api.PcepSwitch; 63 import org.onosproject.pcep.api.PcepSwitch;
64 import org.onosproject.pcep.api.PcepSwitchListener; 64 import org.onosproject.pcep.api.PcepSwitchListener;
65 +import org.onosproject.pcep.controller.PccId;
66 +import org.onosproject.pcep.controller.PcepClient;
67 +import org.onosproject.pcep.controller.PcepClientController;
68 +import org.onosproject.pcep.controller.PcepNodeListener;
65 import org.slf4j.Logger; 69 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory; 70 import org.slf4j.LoggerFactory;
67 71
...@@ -115,18 +119,40 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -115,18 +119,40 @@ public class PcepTopologyProvider extends AbstractProvider
115 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
116 protected ClusterService clusterService; 120 protected ClusterService clusterService;
117 121
122 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
123 + protected PcepClientController pcepClientController;
124 +
118 private DeviceProviderService deviceProviderService; 125 private DeviceProviderService deviceProviderService;
119 private LinkProviderService linkProviderService; 126 private LinkProviderService linkProviderService;
120 127
121 private HashMap<Long, List<PortDescription>> portMap = new HashMap<>(); 128 private HashMap<Long, List<PortDescription>> portMap = new HashMap<>();
122 private InternalLinkProvider listener = new InternalLinkProvider(); 129 private InternalLinkProvider listener = new InternalLinkProvider();
123 130
131 + /*
132 + * For the client supporting SR capability.
133 + */
134 + public static final String SR_CAPABILITY = "srCapability";
135 +
136 + /*
137 + * For the client supporting PCECC capability.
138 + */
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 +
124 @Activate 149 @Activate
125 public void activate() { 150 public void activate() {
126 linkProviderService = linkProviderRegistry.register(this); 151 linkProviderService = linkProviderRegistry.register(this);
127 deviceProviderService = deviceProviderRegistry.register(this); 152 deviceProviderService = deviceProviderRegistry.register(this);
128 controller.addListener(listener); 153 controller.addListener(listener);
129 controller.addLinkListener(listener); 154 controller.addLinkListener(listener);
155 + pcepClientController.addNodeListener(listener);
130 } 156 }
131 157
132 @Deactivate 158 @Deactivate
...@@ -135,6 +161,7 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -135,6 +161,7 @@ public class PcepTopologyProvider extends AbstractProvider
135 linkProviderService = null; 161 linkProviderService = null;
136 controller.removeListener(listener); 162 controller.removeListener(listener);
137 controller.removeLinkListener(listener); 163 controller.removeLinkListener(listener);
164 + pcepClientController.removeNodeListener(listener);
138 } 165 }
139 166
140 private List<PortDescription> buildPortDescriptions(PcepDpid dpid, 167 private List<PortDescription> buildPortDescriptions(PcepDpid dpid,
...@@ -225,7 +252,7 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -225,7 +252,7 @@ public class PcepTopologyProvider extends AbstractProvider
225 } 252 }
226 253
227 private class InternalLinkProvider 254 private class InternalLinkProvider
228 - implements PcepSwitchListener, PcepLinkListener { 255 + implements PcepSwitchListener, PcepLinkListener, PcepNodeListener {
229 256
230 @Override 257 @Override
231 public void switchAdded(PcepDpid dpid) { 258 public void switchAdded(PcepDpid dpid) {
...@@ -306,6 +333,51 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -306,6 +333,51 @@ public class PcepTopologyProvider extends AbstractProvider
306 } 333 }
307 } 334 }
308 335
336 + @Override
337 + public void addNode(PcepClient pc) {
338 + if (deviceProviderService == null) {
339 + return;
340 + }
341 +
342 + //Right now device URI for PCEP devices is their LSRID
343 + DeviceId deviceId = deviceId(uri(new PcepDpid(pc.getPccId().id().getIp4Address().toInt())));
344 + ChassisId cId = new ChassisId();
345 +
346 + Device.Type deviceType = Device.Type.ROUTER;
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 + }
368 +
369 + @Override
370 + public void deleteNode(PccId pccId) {
371 + if (deviceProviderService == null || deviceService == null) {
372 + return;
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;
378 + }
379 + deviceProviderService.deviceDisconnected(deviceId(uri(new PcepDpid(pccId.id().getIp4Address().toInt()))));
380 + }
309 } 381 }
310 382
311 @Override 383 @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.provider.pcep.topology.impl;
17 +
18 +import static org.junit.Assert.assertNotNull;
19 +
20 +import java.util.List;
21 +import java.util.concurrent.RejectedExecutionException;
22 +
23 +import org.jboss.netty.channel.Channel;
24 +import org.onosproject.pcep.controller.ClientCapability;
25 +import org.onosproject.pcep.controller.PccId;
26 +import org.onosproject.pcep.controller.PcepClient;
27 +import org.onosproject.pcep.controller.PcepSyncStatus;
28 +import org.onosproject.pcepio.protocol.PcepFactories;
29 +import org.onosproject.pcepio.protocol.PcepFactory;
30 +import org.onosproject.pcepio.protocol.PcepMessage;
31 +import org.onosproject.pcepio.protocol.PcepVersion;
32 +
33 +/**
34 + * Representation of PCEP client adapter.
35 + */
36 +public class PcepClientAdapter implements PcepClient {
37 +
38 + private Channel channel;
39 + protected String channelId;
40 +
41 + private boolean connected;
42 + private PccId pccId;
43 + private ClientCapability capability;
44 +
45 + private PcepVersion pcepVersion;
46 + private PcepSyncStatus lspDbSyncStatus;
47 + private PcepSyncStatus labelDbSyncStatus;
48 +
49 + /**
50 + * Initialize instance with specified parameters.
51 + *
52 + * @param pccId PCC id
53 + * @param pcepVersion PCEP message version
54 + */
55 + public void init(PccId pccId, PcepVersion pcepVersion) {
56 + this.pccId = pccId;
57 + this.pcepVersion = pcepVersion;
58 + }
59 +
60 + @Override
61 + public final void disconnectClient() {
62 + this.channel.close();
63 + }
64 +
65 + @Override
66 + public final void sendMessage(PcepMessage m) {
67 + }
68 +
69 + @Override
70 + public final void sendMessage(List<PcepMessage> msgs) {
71 + try {
72 + PcepMessage pcepMsg = msgs.get(0);
73 + assertNotNull("PCEP MSG should be created.", pcepMsg);
74 + } catch (RejectedExecutionException e) {
75 + throw e;
76 + }
77 + }
78 +
79 + @Override
80 + public final boolean isConnected() {
81 + return this.connected;
82 + }
83 +
84 + @Override
85 + public String channelId() {
86 + return channelId;
87 + }
88 +
89 + @Override
90 + public final PccId getPccId() {
91 + return this.pccId;
92 + };
93 +
94 + @Override
95 + public final String getStringId() {
96 + return this.pccId.toString();
97 + }
98 +
99 + @Override
100 + public final void handleMessage(PcepMessage m) {
101 + }
102 +
103 + @Override
104 + public boolean isOptical() {
105 + return false;
106 + }
107 +
108 + @Override
109 + public PcepFactory factory() {
110 + return PcepFactories.getFactory(pcepVersion);
111 + }
112 +
113 + @Override
114 + public void setLspDbSyncStatus(PcepSyncStatus syncStatus) {
115 + this.lspDbSyncStatus = syncStatus;
116 + }
117 +
118 + @Override
119 + public PcepSyncStatus lspDbSyncStatus() {
120 + return lspDbSyncStatus;
121 + }
122 +
123 + @Override
124 + public void setLabelDbSyncStatus(PcepSyncStatus syncStatus) {
125 + this.labelDbSyncStatus = syncStatus;
126 + }
127 +
128 + @Override
129 + public PcepSyncStatus labelDbSyncStatus() {
130 + return labelDbSyncStatus;
131 + }
132 +
133 + @Override
134 + public void setCapability(ClientCapability capability) {
135 + this.capability = capability;
136 + }
137 +
138 + @Override
139 + public ClientCapability capability() {
140 + return capability;
141 + }
142 +
143 + @Override
144 + public void addNode(PcepClient pc) {
145 + }
146 +
147 + @Override
148 + public void deleteNode(PccId pccId) {
149 + }
150 +}
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.provider.pcep.topology.impl;
17 +
18 +import java.util.Collection;
19 +import java.util.Collections;
20 +import java.util.HashSet;
21 +import java.util.LinkedList;
22 +import java.util.Set;
23 +import java.util.concurrent.ConcurrentHashMap;
24 +
25 +import org.apache.felix.scr.annotations.Activate;
26 +import org.apache.felix.scr.annotations.Deactivate;
27 +import org.onlab.packet.IpAddress;
28 +import org.onosproject.pcep.controller.ClientCapability;
29 +import org.onosproject.pcep.controller.PccId;
30 +import org.onosproject.pcep.controller.PcepClient;
31 +import org.onosproject.pcep.controller.PcepClientController;
32 +import org.onosproject.pcep.controller.PcepClientListener;
33 +import org.onosproject.pcep.controller.PcepEventListener;
34 +import org.onosproject.pcep.controller.PcepNodeListener;
35 +import org.onosproject.pcep.controller.driver.PcepAgent;
36 +import org.onosproject.pcepio.protocol.PcepError;
37 +import org.onosproject.pcepio.protocol.PcepErrorInfo;
38 +import org.onosproject.pcepio.protocol.PcepErrorMsg;
39 +import org.onosproject.pcepio.protocol.PcepErrorObject;
40 +import org.onosproject.pcepio.protocol.PcepFactory;
41 +import org.onosproject.pcepio.protocol.PcepMessage;
42 +import org.onosproject.pcepio.protocol.PcepVersion;
43 +
44 +import com.google.common.collect.Sets;
45 +
46 +import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_TYPE_19;
47 +import static org.onosproject.pcepio.types.PcepErrorDetailInfo.ERROR_VALUE_5;
48 +
49 +/**
50 + * Representation of PCEP client controller adapter.
51 + */
52 +public class PcepClientControllerAdapter implements PcepClientController {
53 +
54 + protected ConcurrentHashMap<PccId, PcepClient> connectedClients =
55 + new ConcurrentHashMap<PccId, PcepClient>();
56 +
57 + protected PcepClientAgent agent = new PcepClientAgent();
58 + protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
59 +
60 + protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
61 + public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
62 +
63 + @Activate
64 + public void activate() {
65 + }
66 +
67 + @Deactivate
68 + public void deactivate() {
69 + }
70 +
71 + @Override
72 + public Collection<PcepClient> getClients() {
73 + return connectedClients.values();
74 + }
75 +
76 + @Override
77 + public PcepClient getClient(PccId pccId) {
78 + if (null != connectedClients.get(pccId)) {
79 + return connectedClients.get(pccId);
80 + }
81 + PcepClientAdapter pc = new PcepClientAdapter();
82 + if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103))
83 + || pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) {
84 + pc.setCapability(new ClientCapability(true, false, false, false, false));
85 + } else {
86 + pc.setCapability(new ClientCapability(true, true, true, false, false));
87 + }
88 + pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
89 + connectedClients.put(pccId, pc);
90 + return pc;
91 + }
92 +
93 + @Override
94 + public void addListener(PcepClientListener listener) {
95 + if (!pcepClientListener.contains(listener)) {
96 + this.pcepClientListener.add(listener);
97 + }
98 + }
99 +
100 + @Override
101 + public void addNodeListener(PcepNodeListener listener) {
102 + pcepNodeListener.add(listener);
103 + }
104 +
105 + @Override
106 + public void removeNodeListener(PcepNodeListener listener) {
107 + pcepNodeListener.remove(listener);
108 + }
109 +
110 + @Override
111 + public void removeListener(PcepClientListener listener) {
112 + this.pcepClientListener.remove(listener);
113 + }
114 +
115 + @Override
116 + public void addEventListener(PcepEventListener listener) {
117 + pcepEventListener.add(listener);
118 + }
119 +
120 + @Override
121 + public void removeEventListener(PcepEventListener listener) {
122 + pcepEventListener.remove(listener);
123 + }
124 +
125 + @Override
126 + public void writeMessage(PccId pccId, PcepMessage msg) {
127 + this.getClient(pccId).sendMessage(msg);
128 + }
129 +
130 + @Override
131 + public void processClientMessage(PccId pccId, PcepMessage msg) {
132 +
133 + PcepClient pc = getClient(pccId);
134 +
135 + switch (msg.getType()) {
136 + case NONE:
137 + break;
138 + case OPEN:
139 + break;
140 + case KEEP_ALIVE:
141 + //log.debug("Sending Keep Alive Message to {" + pccIpAddress.toString() + "}");
142 + pc.sendMessage(Collections.singletonList(pc.factory().buildKeepaliveMsg().build()));
143 + break;
144 + case PATH_COMPUTATION_REQUEST:
145 + break;
146 + case PATH_COMPUTATION_REPLY:
147 + break;
148 + case NOTIFICATION:
149 + break;
150 + case ERROR:
151 + break;
152 + case CLOSE:
153 + //log.debug("Sending Close Message to { }", pccIpAddress.toString());
154 + pc.sendMessage(Collections.singletonList(pc.factory().buildCloseMsg().build()));
155 + break;
156 + case INITIATE:
157 + if (!pc.capability().pcInstantiationCapability()) {
158 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
159 + ERROR_TYPE_19, ERROR_VALUE_5)));
160 + }
161 + break;
162 + case REPORT:
163 + //Only update the listener if respective capability is supported else send PCEP-ERR msg
164 + if (pc.capability().statefulPceCapability()) {
165 + for (PcepEventListener l : pcepEventListener) {
166 + l.handleMessage(pccId, msg);
167 + }
168 + } else {
169 + // Send PCEP-ERROR message.
170 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
171 + ERROR_TYPE_19, ERROR_VALUE_5)));
172 + }
173 + break;
174 + case UPDATE:
175 + if (!pc.capability().statefulPceCapability()) {
176 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
177 + ERROR_TYPE_19, ERROR_VALUE_5)));
178 + }
179 + break;
180 + case LABEL_UPDATE:
181 + if (!pc.capability().pceccCapability()) {
182 + pc.sendMessage(Collections.singletonList(getErrMsg(pc.factory(),
183 + ERROR_TYPE_19, ERROR_VALUE_5)));
184 + }
185 + break;
186 + case MAX:
187 + break;
188 + case END:
189 + break;
190 + default:
191 + break;
192 + }
193 + }
194 +
195 + @Override
196 + public void closeConnectedClients() {
197 + PcepClient pc;
198 + for (PccId id : connectedClients.keySet()) {
199 + pc = getClient(id);
200 + pc.disconnectClient();
201 + }
202 + }
203 +
204 + private PcepErrorMsg getErrMsg(PcepFactory factory, byte errorType, byte errorValue) {
205 + LinkedList<PcepError> llPcepErr = new LinkedList<>();
206 +
207 + LinkedList<PcepErrorObject> llerrObj = new LinkedList<>();
208 + PcepErrorMsg errMsg;
209 +
210 + PcepErrorObject errObj = factory.buildPcepErrorObject().setErrorValue(errorValue).setErrorType(errorType)
211 + .build();
212 +
213 + llerrObj.add(errObj);
214 + PcepError pcepErr = factory.buildPcepError().setErrorObjList(llerrObj).build();
215 +
216 + llPcepErr.add(pcepErr);
217 +
218 + PcepErrorInfo errInfo = factory.buildPcepErrorInfo().setPcepErrorList(llPcepErr).build();
219 +
220 + errMsg = factory.buildPcepErrorMsg().setPcepErrorInfo(errInfo).build();
221 + return errMsg;
222 + }
223 +
224 + /**
225 + * Implementation of an Pcep Agent which is responsible for
226 + * keeping track of connected clients and the state in which
227 + * they are.
228 + */
229 + public class PcepClientAgent implements PcepAgent {
230 +
231 + @Override
232 + public boolean addConnectedClient(PccId pccId, PcepClient pc) {
233 +
234 + if (connectedClients.get(pccId) != null) {
235 + return false;
236 + } else {
237 + connectedClients.put(pccId, pc);
238 + for (PcepClientListener l : pcepClientListener) {
239 + l.clientConnected(pccId);
240 + }
241 + return true;
242 + }
243 + }
244 +
245 + @Override
246 + public boolean validActivation(PccId pccId) {
247 + if (connectedClients.get(pccId) == null) {
248 + //log.error("Trying to activate client but is not in "
249 + // + "connected switches: pccIp {}. Aborting ..", pccIpAddress.toString());
250 + return false;
251 + }
252 +
253 + return true;
254 + }
255 +
256 + @Override
257 + public void removeConnectedClient(PccId pccId) {
258 + connectedClients.remove(pccId);
259 + for (PcepClientListener l : pcepClientListener) {
260 + //log.warn("removal for {}", pccIpAddress.toString());
261 + l.clientDisconnected(pccId);
262 + }
263 + }
264 +
265 + @Override
266 + public void processPcepMessage(PccId pccId, PcepMessage m) {
267 + processClientMessage(pccId, m);
268 + }
269 +
270 + @Override
271 + public void addNode(PcepClient pc) {
272 + for (PcepNodeListener l : pcepNodeListener) {
273 + l.addNode(pc);
274 + }
275 + }
276 +
277 + @Override
278 + public void deleteNode(PccId pccId) {
279 + for (PcepNodeListener l : pcepNodeListener) {
280 + l.deleteNode(pccId);
281 + }
282 + }
283 + }
284 +}
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 +
17 +package org.onosproject.provider.pcep.topology.impl;
18 +
19 +import org.onosproject.net.DeviceId;
20 +import org.onosproject.pcep.api.PcepController;
21 +import org.onosproject.pcep.api.PcepDpid;
22 +import org.onosproject.pcep.api.PcepLinkListener;
23 +import org.onosproject.pcep.api.PcepSwitch;
24 +import org.onosproject.pcep.api.PcepSwitchListener;
25 +import org.onosproject.pcep.api.PcepTunnel;
26 +import org.onosproject.pcep.api.PcepTunnelListener;
27 +
28 +/**
29 + * Implementation of PCEP controller.
30 + */
31 +public class PcepControllerAdapter implements PcepController {
32 +
33 + @Override
34 + public Iterable<PcepSwitch> getSwitches() {
35 + return null;
36 + }
37 +
38 + @Override
39 + public PcepSwitch getSwitch(PcepDpid did) {
40 + return null;
41 + }
42 +
43 + @Override
44 + public void addListener(PcepSwitchListener listener) {
45 +
46 + }
47 +
48 + @Override
49 + public void removeListener(PcepSwitchListener listener) {
50 + }
51 +
52 + @Override
53 + public void addLinkListener(PcepLinkListener listener) {
54 + }
55 +
56 + @Override
57 + public void removeLinkListener(PcepLinkListener listener) {
58 + }
59 +
60 + @Override
61 + public void addTunnelListener(PcepTunnelListener listener) {
62 + }
63 +
64 + @Override
65 + public void removeTunnelListener(PcepTunnelListener listener) {
66 + }
67 +
68 + @Override
69 + public PcepTunnel applyTunnel(DeviceId srcDid, DeviceId dstDid, long srcPort, long dstPort, long bandwidth,
70 + String name) {
71 + return null;
72 + }
73 +
74 + @Override
75 + public Boolean deleteTunnel(String id) {
76 + return null;
77 + }
78 +
79 + @Override
80 + public Boolean updateTunnelBandwidth(String id, long bandwidth) {
81 + return null;
82 + }
83 +
84 + @Override
85 + public void getTunnelStatistics(String pcepTunnelId) {
86 +
87 + }
88 +}
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 + * the License. You may obtain a copy of the License at
6 + *
7 + * http://www.apache.org/licenses/LICENSE-2.0
8 + *
9 + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 + * specific language governing permissions and limitations under the License.
12 + */
13 +package org.onosproject.provider.pcep.topology.impl;
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;
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 +
23 +import java.util.Collection;
24 +import java.util.HashMap;
25 +import java.util.HashSet;
26 +import java.util.List;
27 +import java.util.Map;
28 +import java.util.Set;
29 +
30 +import org.junit.After;
31 +import org.junit.Before;
32 +import org.junit.Test;
33 +import org.onlab.packet.ChassisId;
34 +import org.onlab.packet.IpAddress;
35 +import org.onosproject.net.ConnectPoint;
36 +import org.onosproject.net.DefaultDevice;
37 +import org.onosproject.net.DefaultLink;
38 +import org.onosproject.net.Device;
39 +import org.onosproject.net.DeviceId;
40 +import org.onosproject.net.Link;
41 +import org.onosproject.net.MastershipRole;
42 +import org.onosproject.net.device.DeviceDescription;
43 +import org.onosproject.net.device.DeviceProvider;
44 +import org.onosproject.net.device.DeviceProviderRegistry;
45 +import org.onosproject.net.device.DeviceProviderService;
46 +import org.onosproject.net.device.DeviceServiceAdapter;
47 +import org.onosproject.net.device.PortDescription;
48 +import org.onosproject.net.device.PortStatistics;
49 +import org.onosproject.net.link.LinkDescription;
50 +import org.onosproject.net.link.LinkProvider;
51 +import org.onosproject.net.link.LinkProviderRegistry;
52 +import org.onosproject.net.link.LinkProviderService;
53 +import org.onosproject.net.provider.ProviderId;
54 +import org.onosproject.pcep.controller.ClientCapability;
55 +import org.onosproject.pcep.controller.PccId;
56 +import org.onosproject.pcep.controller.PcepClient;
57 +import org.onosproject.pcep.controller.PcepNodeListener;
58 +
59 +/**
60 + * Test for PCEP topology provider.
61 + */
62 +public class PcepTopologyProviderTest {
63 + private static final String UNKNOWN = new String("unknown");
64 + public static ProviderId providerId = new ProviderId("l3", "foo");
65 + private final PcepClientControllerAdapter clientController = new PcepClientControllerAdapter();
66 + private final PcepTopologyProvider provider = new PcepTopologyProvider();
67 + private final MockDeviceRegistry nodeRegistry = new MockDeviceRegistry();
68 + private final PcepControllerAdapter controller = new PcepControllerAdapter();
69 + private final MockLinkRegistry linkRegistry = new MockLinkRegistry();
70 + private final MockDeviceService deviceService = new MockDeviceService();
71 + private Map<DeviceId, Device> deviceMap = new HashMap<>();
72 +
73 + @Before
74 + public void startUp() {
75 + provider.pcepClientController = clientController;
76 + provider.deviceProviderRegistry = nodeRegistry;
77 + provider.linkProviderRegistry = linkRegistry;
78 + provider.controller = controller;
79 + provider.deviceService = deviceService;
80 + provider.activate();
81 + }
82 +
83 + @After
84 + public void tearDown() {
85 + provider.deactivate();
86 + provider.deviceProviderRegistry = null;
87 + provider.pcepClientController = null;
88 + provider.linkProviderRegistry = null;
89 + provider.controller = null;
90 + provider.deviceService = null;
91 + }
92 +
93 + /* Class implement device test registry */
94 + private class MockLinkRegistry implements LinkProviderRegistry {
95 + LinkProvider linkProvider;
96 + Set<Link> links = new HashSet<>();
97 +
98 + @Override
99 + public LinkProviderService register(LinkProvider provider) {
100 + this.linkProvider = provider;
101 + return new MockProviderService();
102 + }
103 +
104 + @Override
105 + public void unregister(LinkProvider provider) {
106 + // TODO Auto-generated method stub
107 + }
108 +
109 + @Override
110 + public Set<ProviderId> getProviders() {
111 + return null;
112 + }
113 +
114 + private class MockProviderService implements LinkProviderService {
115 +
116 + @Override
117 + public void linkDetected(LinkDescription linkDescription) {
118 + links.add(DefaultLink.builder().src(linkDescription.src())
119 + .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
120 + .providerId(ProviderId.NONE).build());
121 + }
122 +
123 + @Override
124 + public void linkVanished(LinkDescription linkDescription) {
125 + links.remove(DefaultLink.builder().src(linkDescription.src())
126 + .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
127 + .providerId(ProviderId.NONE).build());
128 + }
129 +
130 + @Override
131 + public void linksVanished(ConnectPoint connectPoint) {
132 + // TODO Auto-generated method stub
133 + }
134 +
135 + @Override
136 + public void linksVanished(DeviceId deviceId) {
137 + // TODO Auto-generated method stub
138 + }
139 +
140 + @Override
141 + public LinkProvider provider() {
142 + // TODO Auto-generated method stub
143 + return null;
144 + }
145 + }
146 + }
147 +
148 + /* Class implement device test registry */
149 + private class MockDeviceRegistry implements DeviceProviderRegistry {
150 + DeviceProvider provider;
151 +
152 + Set<DeviceId> connected = new HashSet<>();
153 +
154 + @Override
155 + public DeviceProviderService register(DeviceProvider provider) {
156 + this.provider = provider;
157 + return new MockProviderService();
158 + }
159 +
160 + @Override
161 + public void unregister(DeviceProvider provider) {
162 + }
163 +
164 + @Override
165 + public Set<ProviderId> getProviders() {
166 + return null;
167 + }
168 +
169 + private class MockProviderService implements DeviceProviderService {
170 +
171 + @Override
172 + public DeviceProvider provider() {
173 + return null;
174 + }
175 +
176 + @Override
177 + public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
178 + connected.add(deviceId);
179 + Device device = new DefaultDevice(ProviderId.NONE, deviceId, Device.Type.ROUTER, UNKNOWN, UNKNOWN,
180 + UNKNOWN, UNKNOWN, new ChassisId(), deviceDescription.annotations());
181 + deviceMap.put(deviceId, device);
182 + }
183 +
184 + @Override
185 + public void deviceDisconnected(DeviceId deviceId) {
186 + connected.remove(deviceId);
187 + deviceMap.remove(deviceId);
188 + }
189 +
190 + @Override
191 + public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
192 + // TODO Auto-generated method stub
193 + }
194 +
195 + @Override
196 + public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) {
197 + // TODO Auto-generated method stub
198 + }
199 +
200 + @Override
201 + public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) {
202 + // TODO Auto-generated method stub
203 + }
204 +
205 + @Override
206 + public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
207 + // TODO Auto-generated method stub
208 + }
209 + }
210 + }
211 +
212 + /* Mock test for device service */
213 + private class MockDeviceService extends DeviceServiceAdapter {
214 + @Override
215 + public Device getDevice(DeviceId deviceId) {
216 + return deviceMap.get(deviceId);
217 + }
218 + }
219 +
220 + /**
221 + * Adds the PCEP device and removes it.
222 + */
223 + @Test
224 + public void testPcepTopologyProviderTestAddDevice1() {
225 + PcepClient pc = clientController.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1")));
226 + for (PcepNodeListener l : clientController.pcepNodeListener) {
227 + pc.setCapability(new ClientCapability(true, true, false, true, true));
228 + l.addNode(pc);
229 + assertThat(nodeRegistry.connected.size(), is(1));
230 + assertThat(deviceMap.keySet().iterator().next(), is(DeviceId.deviceId("l3:1.1.1.1")));
231 + assertThat(deviceMap.values().iterator().next().annotations().value(LABEL_STACK_CAPABILITY), is("true"));
232 + assertThat(deviceMap.values().iterator().next().annotations().value(LSRID), is("1.1.1.1"));
233 + assertThat(deviceMap.values().iterator().next().annotations().value(PCECC_CAPABILITY), is("true"));
234 + assertThat(deviceMap.values().iterator().next().annotations().value(SR_CAPABILITY), is("true"));
235 +
236 + l.deleteNode(pc.getPccId());
237 + assertThat(nodeRegistry.connected.size(), is(0));
238 + }
239 + }
240 +}
...@@ -139,4 +139,12 @@ public class PcepClientAdapter implements PcepClient { ...@@ -139,4 +139,12 @@ public class PcepClientAdapter implements PcepClient {
139 public ClientCapability capability() { 139 public ClientCapability capability() {
140 return capability; 140 return capability;
141 } 141 }
142 +
143 + @Override
144 + public void addNode(PcepClient pc) {
145 + }
146 +
147 + @Override
148 + public void deleteNode(PccId pccId) {
149 + }
142 } 150 }
......
...@@ -31,6 +31,7 @@ import org.onosproject.pcep.controller.PcepClient; ...@@ -31,6 +31,7 @@ import org.onosproject.pcep.controller.PcepClient;
31 import org.onosproject.pcep.controller.PcepClientController; 31 import org.onosproject.pcep.controller.PcepClientController;
32 import org.onosproject.pcep.controller.PcepClientListener; 32 import org.onosproject.pcep.controller.PcepClientListener;
33 import org.onosproject.pcep.controller.PcepEventListener; 33 import org.onosproject.pcep.controller.PcepEventListener;
34 +import org.onosproject.pcep.controller.PcepNodeListener;
34 import org.onosproject.pcep.controller.driver.PcepAgent; 35 import org.onosproject.pcep.controller.driver.PcepAgent;
35 import org.onosproject.pcepio.protocol.PcepError; 36 import org.onosproject.pcepio.protocol.PcepError;
36 import org.onosproject.pcepio.protocol.PcepErrorInfo; 37 import org.onosproject.pcepio.protocol.PcepErrorInfo;
...@@ -57,6 +58,7 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -57,6 +58,7 @@ public class PcepClientControllerAdapter implements PcepClientController {
57 protected Set<PcepClientListener> pcepClientListener = new HashSet<>(); 58 protected Set<PcepClientListener> pcepClientListener = new HashSet<>();
58 59
59 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); 60 protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet();
61 + public Set<PcepNodeListener> pcepNodeListener = Sets.newHashSet();
60 62
61 @Activate 63 @Activate
62 public void activate() { 64 public void activate() {
...@@ -79,9 +81,9 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -79,9 +81,9 @@ public class PcepClientControllerAdapter implements PcepClientController {
79 PcepClientAdapter pc = new PcepClientAdapter(); 81 PcepClientAdapter pc = new PcepClientAdapter();
80 if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103)) 82 if (pccId.ipAddress().equals(IpAddress.valueOf(0xC010103))
81 || pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) { 83 || pccId.ipAddress().equals(IpAddress.valueOf(0xB6024E22))) {
82 - pc.setCapability(new ClientCapability(true, false, false)); 84 + pc.setCapability(new ClientCapability(true, false, false, false, false));
83 } else { 85 } else {
84 - pc.setCapability(new ClientCapability(true, true, true)); 86 + pc.setCapability(new ClientCapability(true, true, true, false, false));
85 } 87 }
86 pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1); 88 pc.init(PccId.pccId(pccId.ipAddress()), PcepVersion.PCEP_1);
87 connectedClients.put(pccId, pc); 89 connectedClients.put(pccId, pc);
...@@ -96,6 +98,16 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -96,6 +98,16 @@ public class PcepClientControllerAdapter implements PcepClientController {
96 } 98 }
97 99
98 @Override 100 @Override
101 + public void addNodeListener(PcepNodeListener listener) {
102 + pcepNodeListener.add(listener);
103 + }
104 +
105 + @Override
106 + public void removeNodeListener(PcepNodeListener listener) {
107 + pcepNodeListener.remove(listener);
108 + }
109 +
110 + @Override
99 public void removeListener(PcepClientListener listener) { 111 public void removeListener(PcepClientListener listener) {
100 this.pcepClientListener.remove(listener); 112 this.pcepClientListener.remove(listener);
101 } 113 }
...@@ -254,5 +266,19 @@ public class PcepClientControllerAdapter implements PcepClientController { ...@@ -254,5 +266,19 @@ public class PcepClientControllerAdapter implements PcepClientController {
254 public void processPcepMessage(PccId pccId, PcepMessage m) { 266 public void processPcepMessage(PccId pccId, PcepMessage m) {
255 processClientMessage(pccId, m); 267 processClientMessage(pccId, m);
256 } 268 }
269 +
270 + @Override
271 + public void addNode(PcepClient pc) {
272 + for (PcepNodeListener l : pcepNodeListener) {
273 + l.addNode(pc);
274 + }
275 + }
276 +
277 + @Override
278 + public void deleteNode(PccId pccId) {
279 + for (PcepNodeListener l : pcepNodeListener) {
280 + l.deleteNode(pccId);
281 + }
282 + }
257 } 283 }
258 } 284 }
......
...@@ -261,7 +261,7 @@ public class PcepTunnelAddedTest { ...@@ -261,7 +261,7 @@ public class PcepTunnelAddedTest {
261 tunnelService.setupTunnel(null, null, tunnel, null); 261 tunnelService.setupTunnel(null, null, tunnel, null);
262 262
263 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400)); 263 PccId pccId = PccId.pccId(IpAddress.valueOf(0x4e1f0400));
264 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true)); 264 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false));
265 controller.getClient(pccId).setLspDbSyncStatus(SYNCED); 265 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
266 266
267 // Process update message. 267 // Process update message.
...@@ -310,7 +310,7 @@ public class PcepTunnelAddedTest { ...@@ -310,7 +310,7 @@ public class PcepTunnelAddedTest {
310 310
311 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 311 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
312 controller.getClient(pccId).setLspDbSyncStatus(SYNCED); 312 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
313 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true)); 313 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false));
314 controller.processClientMessage(pccId, message); 314 controller.processClientMessage(pccId, message);
315 315
316 assertThat(registry.tunnelIdCounter, is((long) 1)); 316 assertThat(registry.tunnelIdCounter, is((long) 1));
...@@ -356,7 +356,7 @@ public class PcepTunnelAddedTest { ...@@ -356,7 +356,7 @@ public class PcepTunnelAddedTest {
356 PcepMessage message1 = reader1.readFrom(buffer1); 356 PcepMessage message1 = reader1.readFrom(buffer1);
357 357
358 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 358 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
359 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true)); 359 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false));
360 controller.processClientMessage(pccId, message1); 360 controller.processClientMessage(pccId, message1);
361 361
362 /* create 2nd LSP */ 362 /* create 2nd LSP */
...@@ -495,7 +495,7 @@ public class PcepTunnelAddedTest { ...@@ -495,7 +495,7 @@ public class PcepTunnelAddedTest {
495 PcepMessage message1 = reader1.readFrom(buffer1); 495 PcepMessage message1 = reader1.readFrom(buffer1);
496 496
497 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1")); 497 PccId pccId = PccId.pccId(IpAddress.valueOf("1.1.1.1"));
498 - controller.getClient(pccId).setCapability(new ClientCapability(true, true, true)); 498 + controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, false, false));
499 controller.processClientMessage(pccId, message1); 499 controller.processClientMessage(pccId, message1);
500 500
501 /* create 2nd LSP */ 501 /* create 2nd LSP */
......