Mahesh Poojary Huawei

[ONOS-4164] PceManager device and link event handling

Change-Id: I55d8f60e0fcc0e23f4c14045a8e20bd89f635913
(cherry picked from commit 1d17cadb)
...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
19 19
20 import java.util.Collection; 20 import java.util.Collection;
21 import java.util.Collections; 21 import java.util.Collections;
22 +import java.util.HashMap;
22 import java.util.Iterator; 23 import java.util.Iterator;
23 import java.util.LinkedList; 24 import java.util.LinkedList;
24 import java.util.List; 25 import java.util.List;
...@@ -60,6 +61,8 @@ import org.onosproject.incubator.net.tunnel.TunnelListener; ...@@ -60,6 +61,8 @@ import org.onosproject.incubator.net.tunnel.TunnelListener;
60 import org.onosproject.incubator.net.tunnel.TunnelName; 61 import org.onosproject.incubator.net.tunnel.TunnelName;
61 import org.onosproject.incubator.net.tunnel.TunnelService; 62 import org.onosproject.incubator.net.tunnel.TunnelService;
62 import org.onosproject.mastership.MastershipService; 63 import org.onosproject.mastership.MastershipService;
64 +import org.onosproject.net.config.NetworkConfigEvent;
65 +import org.onosproject.net.config.NetworkConfigListener;
63 import org.onosproject.net.config.NetworkConfigService; 66 import org.onosproject.net.config.NetworkConfigService;
64 import org.onosproject.net.DefaultAnnotations; 67 import org.onosproject.net.DefaultAnnotations;
65 import org.onosproject.net.DefaultAnnotations.Builder; 68 import org.onosproject.net.DefaultAnnotations.Builder;
...@@ -67,12 +70,17 @@ import org.onosproject.net.Device; ...@@ -67,12 +70,17 @@ import org.onosproject.net.Device;
67 import org.onosproject.net.DeviceId; 70 import org.onosproject.net.DeviceId;
68 import org.onosproject.net.Link; 71 import org.onosproject.net.Link;
69 import org.onosproject.net.Path; 72 import org.onosproject.net.Path;
73 +import org.onosproject.net.device.DeviceEvent;
74 +import org.onosproject.net.device.DeviceListener;
70 import org.onosproject.net.device.DeviceService; 75 import org.onosproject.net.device.DeviceService;
71 import org.onosproject.net.flowobjective.FlowObjectiveService; 76 import org.onosproject.net.flowobjective.FlowObjectiveService;
72 import org.onosproject.net.flowobjective.Objective; 77 import org.onosproject.net.flowobjective.Objective;
73 import org.onosproject.net.intent.Constraint; 78 import org.onosproject.net.intent.Constraint;
74 import org.onosproject.net.intent.constraint.BandwidthConstraint; 79 import org.onosproject.net.intent.constraint.BandwidthConstraint;
80 +import org.onosproject.net.link.LinkListener;
75 import org.onosproject.net.link.LinkEvent; 81 import org.onosproject.net.link.LinkEvent;
82 +import org.onosproject.net.link.LinkService;
83 +import org.onosproject.net.MastershipRole;
76 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint; 84 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint;
77 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType; 85 import org.onosproject.pce.pceservice.constraint.CapabilityConstraint.CapabilityType;
78 import org.onosproject.pce.pceservice.constraint.CostConstraint; 86 import org.onosproject.pce.pceservice.constraint.CostConstraint;
...@@ -134,8 +142,14 @@ import org.onosproject.net.packet.PacketService; ...@@ -134,8 +142,14 @@ import org.onosproject.net.packet.PacketService;
134 public class PceManager implements PceService { 142 public class PceManager implements PceService {
135 private static final Logger log = LoggerFactory.getLogger(PceManager.class); 143 private static final Logger log = LoggerFactory.getLogger(PceManager.class);
136 144
145 + public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
146 + public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
147 + private static final String DEVICE_NULL = "Device-cannot be null";
148 + private static final String LINK_NULL = "Link-cannot be null";
137 public static final String PCE_SERVICE_APP = "org.onosproject.pce"; 149 public static final String PCE_SERVICE_APP = "org.onosproject.pce";
138 private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id"; 150 private static final String LOCAL_LSP_ID_GEN_TOPIC = "pcep-local-lsp-id";
151 + public static final String DEVICE_TYPE = "type";
152 + public static final String L3_DEVICE = "L3";
139 private static final int PREFIX_LENGTH = 32; 153 private static final int PREFIX_LENGTH = 32;
140 154
141 private static final String TUNNEL_CONSUMER_ID_GEN_TOPIC = "pcep-tunnel-consumer-id"; 155 private static final String TUNNEL_CONSUMER_ID_GEN_TOPIC = "pcep-tunnel-consumer-id";
...@@ -150,6 +164,10 @@ public class PceManager implements PceService { ...@@ -150,6 +164,10 @@ public class PceManager implements PceService {
150 private IdGenerator localLspIdIdGen; 164 private IdGenerator localLspIdIdGen;
151 protected DistributedSet<Short> localLspIdFreeList; 165 protected DistributedSet<Short> localLspIdFreeList;
152 166
167 + // LSR-id and device-id mapping for checking capability if L3 device is not
168 + // having its capability
169 + private Map<String, DeviceId> lsrIdDeviceIdMap = new HashMap<>();
170 +
153 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 171 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
154 protected CoreService coreService; 172 protected CoreService coreService;
155 173
...@@ -178,6 +196,9 @@ public class PceManager implements PceService { ...@@ -178,6 +196,9 @@ public class PceManager implements PceService {
178 protected DeviceService deviceService; 196 protected DeviceService deviceService;
179 197
180 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 198 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
199 + protected LinkService linkService;
200 +
201 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
181 protected NetworkConfigService netCfgService; 202 protected NetworkConfigService netCfgService;
182 203
183 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 204 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -196,6 +217,9 @@ public class PceManager implements PceService { ...@@ -196,6 +217,9 @@ public class PceManager implements PceService {
196 protected TopologyService topologyService; 217 protected TopologyService topologyService;
197 218
198 private TunnelListener listener = new InnerTunnelListener(); 219 private TunnelListener listener = new InnerTunnelListener();
220 + private DeviceListener deviceListener = new InternalDeviceListener();
221 + private LinkListener linkListener = new InternalLinkListener();
222 + private InternalConfigListener cfgListener = new InternalConfigListener();
199 private BasicPceccHandler crHandler; 223 private BasicPceccHandler crHandler;
200 private PceccSrTeBeHandler srTeHandler; 224 private PceccSrTeBeHandler srTeHandler;
201 private ApplicationId appId; 225 private ApplicationId appId;
...@@ -220,9 +244,13 @@ public class PceManager implements PceService { ...@@ -220,9 +244,13 @@ public class PceManager implements PceService {
220 crHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore); 244 crHandler.initialize(labelRsrcService, flowObjectiveService, appId, pceStore);
221 245
222 srTeHandler = PceccSrTeBeHandler.getInstance(); 246 srTeHandler = PceccSrTeBeHandler.getInstance();
223 - srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore); 247 + srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore,
248 + deviceService);
224 249
225 tunnelService.addListener(listener); 250 tunnelService.addListener(listener);
251 + deviceService.addListener(deviceListener);
252 + linkService.addListener(linkListener);
253 + netCfgService.addListener(cfgListener);
226 254
227 tunnelConsumerIdGen = coreService.getIdGenerator(TUNNEL_CONSUMER_ID_GEN_TOPIC); 255 tunnelConsumerIdGen = coreService.getIdGenerator(TUNNEL_CONSUMER_ID_GEN_TOPIC);
228 localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC); 256 localLspIdIdGen = coreService.getIdGenerator(LOCAL_LSP_ID_GEN_TOPIC);
...@@ -237,15 +265,24 @@ public class PceManager implements PceService { ...@@ -237,15 +265,24 @@ public class PceManager implements PceService {
237 executor = Executors.newSingleThreadScheduledExecutor(); 265 executor = Executors.newSingleThreadScheduledExecutor();
238 //Start a timer when the component is up, with initial delay of 30min and periodic delays at 30min 266 //Start a timer when the component is up, with initial delay of 30min and periodic delays at 30min
239 executor.scheduleAtFixedRate(new GlobalOptimizationTimer(), INITIAL_DELAY, PERIODIC_DELAY, TimeUnit.MINUTES); 267 executor.scheduleAtFixedRate(new GlobalOptimizationTimer(), INITIAL_DELAY, PERIODIC_DELAY, TimeUnit.MINUTES);
268 +
269 + // Reserve global node pool
270 + if (!srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX)) {
271 + log.debug("Global node pool was already reserved.");
272 + }
273 +
240 log.info("Started"); 274 log.info("Started");
241 } 275 }
242 276
243 @Deactivate 277 @Deactivate
244 protected void deactivate() { 278 protected void deactivate() {
245 tunnelService.removeListener(listener); 279 tunnelService.removeListener(listener);
280 + deviceService.removeListener(deviceListener);
281 + linkService.removeListener(linkListener);
282 + netCfgService.removeListener(cfgListener);
246 packetService.removeProcessor(processor); 283 packetService.removeProcessor(processor);
247 topologyService.removeListener(topologyListener); 284 topologyService.removeListener(topologyListener);
248 - //Shutdown the thread when component is deactivated 285 + // Shutdown the thread when component is deactivated
249 executor.shutdown(); 286 executor.shutdown();
250 log.info("Stopped"); 287 log.info("Stopped");
251 } 288 }
...@@ -819,6 +856,234 @@ public class PceManager implements PceService { ...@@ -819,6 +856,234 @@ public class PceManager implements PceService {
819 resource = Resources.continuous(link.src().deviceId(), link.src().port(), Bandwidth.class) 856 resource = Resources.continuous(link.src().deviceId(), link.src().port(), Bandwidth.class)
820 .resource(bandwidth); 857 .resource(bandwidth);
821 resourceService.allocate(consumer, resource); // Reusing new tunnel's TunnelConsumerId intentionally. 858 resourceService.allocate(consumer, resource); // Reusing new tunnel's TunnelConsumerId intentionally.
859 +
860 + }
861 + }
862 +
863 + /**
864 + * Allocates node label to specific device.
865 + *
866 + * @param specificDevice device to which node label needs to be allocated
867 + */
868 + public void allocateNodeLabel(Device specificDevice) {
869 + checkNotNull(specificDevice, DEVICE_NULL);
870 +
871 + DeviceId deviceId = specificDevice.id();
872 +
873 + // Retrieve lsrId of a specific device
874 + if (specificDevice.annotations() == null) {
875 + log.debug("Device {} does not have annotations.", specificDevice.toString());
876 + return;
877 + }
878 +
879 + String lsrId = specificDevice.annotations().value(LSRID);
880 + if (lsrId == null) {
881 + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
882 + return;
883 + }
884 +
885 + // Get capability config from netconfig
886 + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
887 + if (cfg == null) {
888 + log.error("Unable to find corresponding capability for a lsrd {} from NetConfig.", lsrId);
889 + // Save info. When PCEP session is comes up then allocate node-label
890 + lsrIdDeviceIdMap.put(lsrId, specificDevice.id());
891 + return;
892 + }
893 +
894 + // Check whether device has SR-TE Capability
895 + if (cfg.labelStackCap()) {
896 + if (!srTeHandler.allocateNodeLabel(deviceId, lsrId)) {
897 + log.error("Node label allocation for a device id {} has failed.", deviceId.toString());
898 + }
899 + }
900 + }
901 +
902 + /**
903 + * Releases node label of a specific device.
904 + *
905 + * @param specificDevice this device label and lsr-id information will be
906 + * released in other existing devices
907 + */
908 + public void releaseNodeLabel(Device specificDevice) {
909 + checkNotNull(specificDevice, DEVICE_NULL);
910 +
911 + DeviceId deviceId = specificDevice.id();
912 +
913 + // Retrieve lsrId of a specific device
914 + if (specificDevice.annotations() == null) {
915 + log.debug("Device {} does not have annotations.", specificDevice.toString());
916 + return;
917 + }
918 +
919 + String lsrId = specificDevice.annotations().value(LSRID);
920 + if (lsrId == null) {
921 + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
922 + return;
923 + }
924 +
925 + // Get capability config from netconfig
926 + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
927 + if (cfg == null) {
928 + log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
929 + return;
930 + }
931 +
932 + // Check whether device has SR-TE Capability
933 + if (cfg.labelStackCap()) {
934 + if (!srTeHandler.releaseNodeLabel(deviceId, lsrId)) {
935 + log.error("Unable to release node label for a device id {}.", deviceId.toString());
936 + }
937 + }
938 + }
939 +
940 + /**
941 + * Allocates adjacency label for a link.
942 + *
943 + * @param link link
944 + */
945 + public void allocateAdjacencyLabel(Link link) {
946 + checkNotNull(link, LINK_NULL);
947 +
948 + Device specificDevice = deviceService.getDevice(link.src().deviceId());
949 + DeviceId deviceId = specificDevice.id();
950 +
951 + // Retrieve lsrId of a specific device
952 + if (specificDevice.annotations() == null) {
953 + log.debug("Device {} does not have annotations.", specificDevice.toString());
954 + return;
955 + }
956 +
957 + String lsrId = specificDevice.annotations().value(LSRID);
958 + if (lsrId == null) {
959 + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
960 + return;
961 + }
962 +
963 + // Get capability config from netconfig
964 + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
965 + if (cfg == null) {
966 + log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
967 + // Save info. When PCEP session comes up then allocate adjacency
968 + // label
969 + if (lsrIdDeviceIdMap.get(lsrId) != null) {
970 + lsrIdDeviceIdMap.put(lsrId, specificDevice.id());
971 + }
972 + return;
973 + }
974 +
975 + // Check whether device has SR-TE Capability
976 + if (cfg.labelStackCap()) {
977 + if (!srTeHandler.allocateAdjacencyLabel(link)) {
978 + log.error("Unable to allocate adjacency label for a link {}.", link.toString());
979 + return;
980 + }
981 + }
982 +
983 + return;
984 + }
985 +
986 + /**
987 + * Releases allocated adjacency label of a link.
988 + *
989 + * @param link link
990 + */
991 + public void releaseAdjacencyLabel(Link link) {
992 + checkNotNull(link, LINK_NULL);
993 +
994 + Device specificDevice = deviceService.getDevice(link.src().deviceId());
995 + DeviceId deviceId = specificDevice.id();
996 +
997 + // Retrieve lsrId of a specific device
998 + if (specificDevice.annotations() == null) {
999 + log.debug("Device {} does not have annotations.", specificDevice.toString());
1000 + return;
1001 + }
1002 +
1003 + String lsrId = specificDevice.annotations().value(LSRID);
1004 + if (lsrId == null) {
1005 + log.debug("Unable to retrieve lsr-id of a device {}.", specificDevice.toString());
1006 + return;
1007 + }
1008 +
1009 + // Get capability config from netconfig
1010 + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
1011 + if (cfg == null) {
1012 + log.error("Unable to find corresponding capabilty for a lsrd {} from NetConfig.", lsrId);
1013 + return;
1014 + }
1015 +
1016 + // Check whether device has SR-TE Capability
1017 + if (cfg.labelStackCap()) {
1018 + if (!srTeHandler.releaseAdjacencyLabel(link)) {
1019 + log.error("Unable to release adjacency labels for a link {}.", link.toString());
1020 + return;
1021 + }
1022 + }
1023 +
1024 + return;
1025 + }
1026 +
1027 + /*
1028 + * Handle device events.
1029 + */
1030 + private class InternalDeviceListener implements DeviceListener {
1031 + @Override
1032 + public void event(DeviceEvent event) {
1033 + Device specificDevice = (Device) event.subject();
1034 + if (specificDevice == null) {
1035 + log.error("Unable to find device from device event.");
1036 + return;
1037 + }
1038 +
1039 + switch (event.type()) {
1040 +
1041 + case DEVICE_ADDED:
1042 + // Node-label allocation is being done during Label DB Sync.
1043 + // So, when device is detected, no need to do node-label
1044 + // allocation.
1045 + break;
1046 +
1047 + case DEVICE_REMOVED:
1048 + // Release node-label
1049 + if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) {
1050 + releaseNodeLabel(specificDevice);
1051 + }
1052 + break;
1053 +
1054 + default:
1055 + break;
1056 + }
1057 + }
1058 + }
1059 +
1060 + /*
1061 + * Handle link events.
1062 + */
1063 + private class InternalLinkListener implements LinkListener {
1064 + @Override
1065 + public void event(LinkEvent event) {
1066 + Link link = (Link) event.subject();
1067 +
1068 + switch (event.type()) {
1069 +
1070 + case LINK_ADDED:
1071 + // Allocate adjacency label
1072 + if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) {
1073 + allocateAdjacencyLabel(link);
1074 + }
1075 + break;
1076 +
1077 + case LINK_REMOVED:
1078 + // Release adjacency label
1079 + if (mastershipService.getLocalRole(link.src().deviceId()) == MastershipRole.MASTER) {
1080 + releaseAdjacencyLabel(link);
1081 + }
1082 + break;
1083 +
1084 + default:
1085 + break;
1086 + }
822 } 1087 }
823 } 1088 }
824 1089
...@@ -851,8 +1116,11 @@ public class PceManager implements PceService { ...@@ -851,8 +1116,11 @@ public class PceManager implements PceService {
851 1116
852 case TUNNEL_UPDATED: 1117 case TUNNEL_UPDATED:
853 // Allocate/send labels for basic PCECC tunnels. 1118 // Allocate/send labels for basic PCECC tunnels.
854 - if ((tunnel.state() == ESTABLISHED) && (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR)) { 1119 + if ((tunnel.state() == ESTABLISHED) && (lspType == WITHOUT_SIGNALLING_AND_WITHOUT_SR)
855 - crHandler.allocateLabel(tunnel); 1120 + && (mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER)) {
1121 + if (!crHandler.allocateLabel(tunnel)) {
1122 + log.error("Unable to allocate labels for a tunnel {}.", tunnel.toString());
1123 + }
856 } 1124 }
857 1125
858 if (tunnel.state() == UNSTABLE) { 1126 if (tunnel.state() == UNSTABLE) {
...@@ -899,7 +1167,9 @@ public class PceManager implements PceService { ...@@ -899,7 +1167,9 @@ public class PceManager implements PceService {
899 // Delete stored tunnel consumer id from PCE store (while still retaining label list.) 1167 // Delete stored tunnel consumer id from PCE store (while still retaining label list.)
900 PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId()); 1168 PceccTunnelInfo pceccTunnelInfo = pceStore.getTunnelInfo(tunnel.tunnelId());
901 pceccTunnelInfo.tunnelConsumerId(null); 1169 pceccTunnelInfo.tunnelConsumerId(null);
1170 + if (mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) {
902 crHandler.releaseLabel(tunnel); 1171 crHandler.releaseLabel(tunnel);
1172 + }
903 } else { 1173 } else {
904 pceStore.removeTunnelInfo(tunnel.tunnelId()); 1174 pceStore.removeTunnelInfo(tunnel.tunnelId());
905 } 1175 }
...@@ -914,8 +1184,62 @@ public class PceManager implements PceService { ...@@ -914,8 +1184,62 @@ public class PceManager implements PceService {
914 } 1184 }
915 } 1185 }
916 1186
1187 + private class InternalConfigListener implements NetworkConfigListener {
1188 +
1189 + @Override
1190 + public void event(NetworkConfigEvent event) {
1191 +
1192 + if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED)
1193 + && event.configClass().equals(DeviceCapability.class)) {
1194 +
1195 + DeviceId deviceIdLsrId = (DeviceId) event.subject();
1196 + String lsrId = deviceIdLsrId.toString();
1197 + DeviceId deviceId = lsrIdDeviceIdMap.get(lsrId);
1198 + if (deviceId == null) {
1199 + log.debug("Unable to find device id for a lsr-id {} from lsr-id and device-id map.", lsrId);
1200 + return;
1201 + }
1202 +
1203 + DeviceCapability cfg = netCfgService.getConfig(DeviceId.deviceId(lsrId), DeviceCapability.class);
1204 + if (cfg == null) {
1205 + log.error("Unable to find corresponding capabilty for a lsrd {}.", lsrId);
1206 + return;
1207 + }
1208 +
1209 + if (cfg.labelStackCap()) {
1210 + if (mastershipService.getLocalRole(deviceId) == MastershipRole.MASTER) {
1211 + // Allocate node-label
1212 + if (!srTeHandler.allocateNodeLabel(deviceId, lsrId)) {
1213 + log.error("Node label allocation for a device id {} has failed.", deviceId.toString());
1214 + }
1215 +
1216 + // Allocate adjacency label to links which are
1217 + // originated from this specific device id
1218 + Set<Link> links = linkService.getDeviceEgressLinks(deviceId);
1219 + for (Link link : links) {
1220 + if (!srTeHandler.allocateAdjacencyLabel(link)) {
1221 + log.debug("Unable to allocate adjacency labels for a link {}.", link.toString());
1222 + return;
1223 + }
1224 + }
1225 + }
1226 + }
1227 +
1228 + // Remove lsrId info from map
1229 + lsrIdDeviceIdMap.remove(lsrId);
1230 + }
1231 + }
1232 + }
1233 +
917 private boolean syncLabelDb(DeviceId deviceId) { 1234 private boolean syncLabelDb(DeviceId deviceId) {
918 checkNotNull(deviceId); 1235 checkNotNull(deviceId);
1236 +
1237 + Device specificDevice = deviceService.getDevice(deviceId);
1238 + if (specificDevice == null) {
1239 + log.error("Unable to find device for specific device id {}.", deviceId.toString());
1240 + return false;
1241 + }
1242 +
919 Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels(); 1243 Map<DeviceId, LabelResourceId> globalNodeLabelMap = pceStore.getGlobalNodeLabels();
920 1244
921 for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) { 1245 for (Entry<DeviceId, LabelResourceId> entry : globalNodeLabelMap.entrySet()) {
...@@ -957,6 +1281,18 @@ public class PceManager implements PceService { ...@@ -957,6 +1281,18 @@ public class PceManager implements PceService {
957 LabelResourceId.labelResourceId(0), 1281 LabelResourceId.labelResourceId(0),
958 IpPrefix.valueOf(END_OF_SYNC_IP_PREFIX), 1282 IpPrefix.valueOf(END_OF_SYNC_IP_PREFIX),
959 Objective.Operation.ADD, true); 1283 Objective.Operation.ADD, true);
1284 + if (mastershipService.getLocalRole(specificDevice.id()) == MastershipRole.MASTER) {
1285 + // Allocate node-label to this specific device.
1286 + allocateNodeLabel(specificDevice);
1287 +
1288 + // Allocate adjacency label
1289 + Set<Link> links = linkService.getDeviceEgressLinks(specificDevice.id());
1290 + if (links != null) {
1291 + for (Link link : links) {
1292 + allocateAdjacencyLabel(link);
1293 + }
1294 + }
1295 + }
960 1296
961 return true; 1297 return true;
962 } 1298 }
......
...@@ -37,6 +37,8 @@ import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; ...@@ -37,6 +37,8 @@ import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
37 import org.onosproject.incubator.net.resource.label.LabelResourceService; 37 import org.onosproject.incubator.net.resource.label.LabelResourceService;
38 import org.onosproject.incubator.net.tunnel.DefaultLabelStack; 38 import org.onosproject.incubator.net.tunnel.DefaultLabelStack;
39 import org.onosproject.incubator.net.tunnel.LabelStack; 39 import org.onosproject.incubator.net.tunnel.LabelStack;
40 +import org.onosproject.net.device.DeviceService;
41 +import org.onosproject.net.Device;
40 import org.onosproject.net.DeviceId; 42 import org.onosproject.net.DeviceId;
41 import org.onosproject.pce.pcestore.api.PceStore; 43 import org.onosproject.pce.pcestore.api.PceStore;
42 import org.onosproject.net.Link; 44 import org.onosproject.net.Link;
...@@ -69,10 +71,8 @@ public final class PceccSrTeBeHandler { ...@@ -69,10 +71,8 @@ public final class PceccSrTeBeHandler {
69 private static final String LABEL_RESOURCE_ADMIN_SERVICE_NULL = "Label Resource Admin Service cannot be null"; 71 private static final String LABEL_RESOURCE_ADMIN_SERVICE_NULL = "Label Resource Admin Service cannot be null";
70 private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null"; 72 private static final String LABEL_RESOURCE_SERVICE_NULL = "Label Resource Service cannot be null";
71 private static final String PCE_STORE_NULL = "PCE Store cannot be null"; 73 private static final String PCE_STORE_NULL = "PCE Store cannot be null";
72 - private static final String DEVICE_SERVICE_NULL = "Device Service cannot be null";
73 private static final String DEVICE_ID_NULL = "Device-Id cannot be null"; 74 private static final String DEVICE_ID_NULL = "Device-Id cannot be null";
74 private static final String LSR_ID_NULL = "LSR-Id cannot be null"; 75 private static final String LSR_ID_NULL = "LSR-Id cannot be null";
75 - private static final String DEVICE_ID_LSR_ID_MAP_NULL = "Device-Id and LSR-Id map cannot be null";
76 private static final String LINK_NULL = "Link cannot be null"; 76 private static final String LINK_NULL = "Link cannot be null";
77 private static final String PATH_NULL = "Path cannot be null"; 77 private static final String PATH_NULL = "Path cannot be null";
78 private static final String LSR_ID = "lsrId"; 78 private static final String LSR_ID = "lsrId";
...@@ -81,6 +81,7 @@ public final class PceccSrTeBeHandler { ...@@ -81,6 +81,7 @@ public final class PceccSrTeBeHandler {
81 private LabelResourceAdminService labelRsrcAdminService; 81 private LabelResourceAdminService labelRsrcAdminService;
82 private LabelResourceService labelRsrcService; 82 private LabelResourceService labelRsrcService;
83 private FlowObjectiveService flowObjectiveService; 83 private FlowObjectiveService flowObjectiveService;
84 + private DeviceService deviceService;
84 private PceStore pceStore; 85 private PceStore pceStore;
85 private ApplicationId appId; 86 private ApplicationId appId;
86 87
...@@ -110,16 +111,17 @@ public final class PceccSrTeBeHandler { ...@@ -110,16 +111,17 @@ public final class PceccSrTeBeHandler {
110 * @param flowObjectiveService flow objective service to push device label information 111 * @param flowObjectiveService flow objective service to push device label information
111 * @param appId application id 112 * @param appId application id
112 * @param pceStore PCE label store 113 * @param pceStore PCE label store
114 + * @param deviceService device service
113 */ 115 */
114 - public void initialize(LabelResourceAdminService labelRsrcAdminService, 116 + public void initialize(LabelResourceAdminService labelRsrcAdminService, LabelResourceService labelRsrcService,
115 - LabelResourceService labelRsrcService, 117 + FlowObjectiveService flowObjectiveService, ApplicationId appId, PceStore pceStore,
116 - FlowObjectiveService flowObjectiveService, 118 + DeviceService deviceService) {
117 - ApplicationId appId, PceStore pceStore) {
118 this.labelRsrcAdminService = labelRsrcAdminService; 119 this.labelRsrcAdminService = labelRsrcAdminService;
119 this.labelRsrcService = labelRsrcService; 120 this.labelRsrcService = labelRsrcService;
120 this.flowObjectiveService = flowObjectiveService; 121 this.flowObjectiveService = flowObjectiveService;
121 this.pceStore = pceStore; 122 this.pceStore = pceStore;
122 this.appId = appId; 123 this.appId = appId;
124 + this.deviceService = deviceService;
123 } 125 }
124 126
125 /** 127 /**
...@@ -136,26 +138,57 @@ public final class PceccSrTeBeHandler { ...@@ -136,26 +138,57 @@ public final class PceccSrTeBeHandler {
136 } 138 }
137 139
138 /** 140 /**
141 + * Retrieve lsr-id from device annotation.
142 + *
143 + * @param deviceId specific device id from which lsr-id needs to be retrieved
144 + * @return lsr-id of a device
145 + */
146 + public String getLsrId(DeviceId deviceId) {
147 + checkNotNull(deviceId, DEVICE_ID_NULL);
148 + Device device = deviceService.getDevice(deviceId);
149 + if (device == null) {
150 + log.debug("Device is not available for device id {} in device service.", deviceId.toString());
151 + return null;
152 + }
153 +
154 + // Retrieve lsr-id from device
155 + if (device.annotations() == null) {
156 + log.debug("Device {} does not have annotation.", device.toString());
157 + return null;
158 + }
159 +
160 + String lsrId = device.annotations().value(LSR_ID);
161 + if (lsrId == null) {
162 + log.debug("The lsr-id of device {} is null.", device.toString());
163 + return null;
164 + }
165 + return lsrId;
166 + }
167 +
168 + /**
139 * Allocates node label from global node label pool to specific device. 169 * Allocates node label from global node label pool to specific device.
140 * Configure this device with labels and lsrid mapping of all other devices and vice versa. 170 * Configure this device with labels and lsrid mapping of all other devices and vice versa.
141 * 171 *
142 * @param specificDeviceId node label needs to be allocated to specific device 172 * @param specificDeviceId node label needs to be allocated to specific device
143 * @param specificLsrId lsrid of specific device 173 * @param specificLsrId lsrid of specific device
144 - * @param deviceIdLsrIdMap deviceid and lsrid mapping
145 * @return success or failure 174 * @return success or failure
146 */ 175 */
147 - public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId, 176 + public boolean allocateNodeLabel(DeviceId specificDeviceId, String specificLsrId) {
148 - Map<DeviceId, String> deviceIdLsrIdMap) {
149 long applyNum = 1; // For each node only one node label 177 long applyNum = 1; // For each node only one node label
150 LabelResourceId specificLabelId = null; 178 LabelResourceId specificLabelId = null;
151 179
152 checkNotNull(specificDeviceId, DEVICE_ID_NULL); 180 checkNotNull(specificDeviceId, DEVICE_ID_NULL);
153 checkNotNull(specificLsrId, LSR_ID_NULL); 181 checkNotNull(specificLsrId, LSR_ID_NULL);
154 - checkNotNull(deviceIdLsrIdMap, DEVICE_ID_LSR_ID_MAP_NULL);
155 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); 182 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
156 checkNotNull(pceStore, PCE_STORE_NULL); 183 checkNotNull(pceStore, PCE_STORE_NULL);
157 184
158 - // The specificDeviceId is the new device and is not there in the deviceIdLsrIdMap. 185 + // Check whether node-label was already configured for this specific device.
186 + if (pceStore.getGlobalNodeLabel(specificDeviceId) != null) {
187 + log.error("Node label was already configured for device {}.", specificDeviceId.toString());
188 + return false;
189 + }
190 +
191 + // The specificDeviceId is the new device and is not there in the pce store.
159 // So, first generate its label and configure label and its lsr-id to it. 192 // So, first generate its label and configure label and its lsr-id to it.
160 Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum); 193 Collection<LabelResource> result = labelRsrcService.applyFromGlobalPool(applyNum);
161 if (result.size() > 0) { 194 if (result.size() > 0) {
...@@ -172,36 +205,35 @@ public final class PceccSrTeBeHandler { ...@@ -172,36 +205,35 @@ public final class PceccSrTeBeHandler {
172 return false; 205 return false;
173 } 206 }
174 207
208 + // store it
175 pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId); 209 pceStore.addGlobalNodeLabel(specificDeviceId, specificLabelId);
210 +
176 // Push its label information into specificDeviceId 211 // Push its label information into specificDeviceId
177 advertiseNodeLabelRule(specificDeviceId, specificLabelId, 212 advertiseNodeLabelRule(specificDeviceId, specificLabelId,
178 IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH), 213 IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
179 Objective.Operation.ADD, false); 214 Objective.Operation.ADD, false);
180 215
181 - // Configure (node-label, lsr-id) mapping of each devices in list to specific device and vice versa. 216 + // Configure (node-label, lsr-id) mapping of each devices into specific device and vice versa.
182 - for (Map.Entry<DeviceId, String> element:deviceIdLsrIdMap.entrySet()) { 217 + for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) {
183 DeviceId otherDevId = element.getKey(); 218 DeviceId otherDevId = element.getKey();
184 - String otherLsrId = element.getValue(); 219 + LabelResourceId otherLabelId = element.getValue();
220 +
221 + // Get lsr-id of a device
222 + String otherLsrId = getLsrId(otherDevId);
185 if (otherLsrId == null) { 223 if (otherLsrId == null) {
186 log.error("The lsr-id of device id {} is null.", otherDevId.toString()); 224 log.error("The lsr-id of device id {} is null.", otherDevId.toString());
187 - releaseNodeLabel(specificDeviceId, specificLsrId, deviceIdLsrIdMap); 225 + releaseNodeLabel(specificDeviceId, specificLsrId);
188 - return false;
189 - }
190 -
191 - // Label for other device in list should be already allocated.
192 - LabelResourceId otherLabelId = pceStore.getGlobalNodeLabel(otherDevId);
193 - if (otherLabelId == null) {
194 - log.error("Unable to find global node label in store for a device id {}.", otherDevId.toString());
195 - releaseNodeLabel(specificDeviceId, specificLsrId, deviceIdLsrIdMap);
196 return false; 226 return false;
197 } 227 }
198 228
199 // Push to device 229 // Push to device
200 // Push label information of specificDeviceId to otherDevId in list and vice versa. 230 // Push label information of specificDeviceId to otherDevId in list and vice versa.
201 - advertiseNodeLabelRule(otherDevId, specificLabelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), 231 + advertiseNodeLabelRule(otherDevId, specificLabelId,
202 - PREFIX_LENGTH), Objective.Operation.ADD, false); 232 + IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
203 - advertiseNodeLabelRule(specificDeviceId, otherLabelId, IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), 233 + Objective.Operation.ADD, false);
204 - PREFIX_LENGTH), Objective.Operation.ADD, false); 234 + advertiseNodeLabelRule(specificDeviceId, otherLabelId,
235 + IpPrefix.valueOf(IpAddress.valueOf(otherLsrId), PREFIX_LENGTH),
236 + Objective.Operation.ADD, false);
205 } 237 }
206 238
207 return true; 239 return true;
...@@ -213,14 +245,11 @@ public final class PceccSrTeBeHandler { ...@@ -213,14 +245,11 @@ public final class PceccSrTeBeHandler {
213 * 245 *
214 * @param specificDeviceId node label needs to be released for specific device 246 * @param specificDeviceId node label needs to be released for specific device
215 * @param specificLsrId lsrid of specific device 247 * @param specificLsrId lsrid of specific device
216 - * @param deviceIdLsrIdMap deviceid and lsrid mapping
217 * @return success or failure 248 * @return success or failure
218 */ 249 */
219 - public boolean releaseNodeLabel(DeviceId specificDeviceId, String specificLsrId, 250 + public boolean releaseNodeLabel(DeviceId specificDeviceId, String specificLsrId) {
220 - Map<DeviceId, String> deviceIdLsrIdMap) {
221 checkNotNull(specificDeviceId, DEVICE_ID_NULL); 251 checkNotNull(specificDeviceId, DEVICE_ID_NULL);
222 checkNotNull(specificLsrId, LSR_ID_NULL); 252 checkNotNull(specificLsrId, LSR_ID_NULL);
223 - checkNotNull(deviceIdLsrIdMap, DEVICE_ID_LSR_ID_MAP_NULL);
224 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); 253 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
225 checkNotNull(pceStore, PCE_STORE_NULL); 254 checkNotNull(pceStore, PCE_STORE_NULL);
226 boolean retValue = true; 255 boolean retValue = true;
...@@ -233,15 +262,16 @@ public final class PceccSrTeBeHandler { ...@@ -233,15 +262,16 @@ public final class PceccSrTeBeHandler {
233 return false; 262 return false;
234 } 263 }
235 264
236 - // Go through all devices in the map and remove label entry 265 + // Go through all devices in the pce store and remove label entry from device
237 - for (Map.Entry<DeviceId, String> element:deviceIdLsrIdMap.entrySet()) { 266 + for (Map.Entry<DeviceId, LabelResourceId> element : pceStore.getGlobalNodeLabels().entrySet()) {
238 DeviceId otherDevId = element.getKey(); 267 DeviceId otherDevId = element.getKey();
239 268
240 // Remove this specific device label information from all other nodes except 269 // Remove this specific device label information from all other nodes except
241 // this specific node where connection already lost. 270 // this specific node where connection already lost.
242 if (!specificDeviceId.equals(otherDevId)) { 271 if (!specificDeviceId.equals(otherDevId)) {
243 - advertiseNodeLabelRule(otherDevId, labelId, IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), 272 + advertiseNodeLabelRule(otherDevId, labelId,
244 - PREFIX_LENGTH), Objective.Operation.REMOVE, false); 273 + IpPrefix.valueOf(IpAddress.valueOf(specificLsrId), PREFIX_LENGTH),
274 + Objective.Operation.REMOVE, false);
245 } 275 }
246 } 276 }
247 277
...@@ -277,6 +307,13 @@ public final class PceccSrTeBeHandler { ...@@ -277,6 +307,13 @@ public final class PceccSrTeBeHandler {
277 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL); 307 checkNotNull(labelRsrcService, LABEL_RESOURCE_SERVICE_NULL);
278 checkNotNull(pceStore, PCE_STORE_NULL); 308 checkNotNull(pceStore, PCE_STORE_NULL);
279 309
310 + // Checks whether adjacency label was already allocated
311 + LabelResourceId labelId = pceStore.getAdjLabel(link);
312 + if (labelId != null) {
313 + log.debug("Adjacency label {} was already allocated for a link {}.", labelId.toString(), link.toString());
314 + return false;
315 + }
316 +
280 // Allocate adjacency label to a link from label manager. 317 // Allocate adjacency label to a link from label manager.
281 // Take label from source device pool to allocate. 318 // Take label from source device pool to allocate.
282 labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum); 319 labelList = labelRsrcService.applyFromDevicePool(srcDeviceId, applyNum);
...@@ -288,13 +325,12 @@ public final class PceccSrTeBeHandler { ...@@ -288,13 +325,12 @@ public final class PceccSrTeBeHandler {
288 // Currently only one label to a device. So, no need to iterate through list 325 // Currently only one label to a device. So, no need to iterate through list
289 Iterator<LabelResource> iterator = labelList.iterator(); 326 Iterator<LabelResource> iterator = labelList.iterator();
290 DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next(); 327 DefaultLabelResource defaultLabelResource = (DefaultLabelResource) iterator.next();
291 - LabelResourceId labelId = defaultLabelResource.labelResourceId(); 328 + labelId = defaultLabelResource.labelResourceId();
292 if (labelId == null) { 329 if (labelId == null) {
293 log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString()); 330 log.error("Unable to allocate label to a device id {}.", srcDeviceId.toString());
294 return false; 331 return false;
295 } 332 }
296 - log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), 333 + log.debug("Allocated adjacency label {} to a link {}.", labelId.toString(), link.toString());
297 - link.toString());
298 334
299 // Push adjacency label to device 335 // Push adjacency label to device
300 installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD); 336 installAdjLabelRule(srcDeviceId, labelId, link.src().port(), link.dst().port(), Objective.Operation.ADD);
...@@ -418,15 +454,11 @@ public final class PceccSrTeBeHandler { ...@@ -418,15 +454,11 @@ public final class PceccSrTeBeHandler {
418 454
419 selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); 455 selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue()));
420 456
421 - TrafficTreatment treatment = DefaultTrafficTreatment.builder() 457 + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
422 - .build();
423 458
424 ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() 459 ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
425 - .withSelector(selectorBuilder.build()) 460 + .withSelector(selectorBuilder.build()).withTreatment(treatment)
426 - .withTreatment(treatment) 461 + .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
427 - .withFlag(ForwardingObjective.Flag.VERSATILE)
428 - .fromApp(appId)
429 - .makePermanent();
430 462
431 if (type.equals(Objective.Operation.ADD)) { 463 if (type.equals(Objective.Operation.ADD)) {
432 464
...@@ -445,8 +477,8 @@ public final class PceccSrTeBeHandler { ...@@ -445,8 +477,8 @@ public final class PceccSrTeBeHandler {
445 * @param type type of operation 477 * @param type type of operation
446 * @param bBos is this the end of sync push 478 * @param bBos is this the end of sync push
447 */ 479 */
448 - public void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, 480 + public void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, IpPrefix ipPrefix,
449 - IpPrefix ipPrefix, Objective.Operation type, boolean bBos) { 481 + Objective.Operation type, boolean bBos) {
450 checkNotNull(flowObjectiveService); 482 checkNotNull(flowObjectiveService);
451 checkNotNull(appId); 483 checkNotNull(appId);
452 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); 484 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
...@@ -458,15 +490,11 @@ public final class PceccSrTeBeHandler { ...@@ -458,15 +490,11 @@ public final class PceccSrTeBeHandler {
458 selectorBuilder.matchMplsBos(bBos); 490 selectorBuilder.matchMplsBos(bBos);
459 } 491 }
460 492
461 - TrafficTreatment treatment = DefaultTrafficTreatment.builder() 493 + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
462 - .build();
463 494
464 ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() 495 ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
465 - .withSelector(selectorBuilder.build()) 496 + .withSelector(selectorBuilder.build()).withTreatment(treatment)
466 - .withTreatment(treatment) 497 + .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
467 - .withFlag(ForwardingObjective.Flag.VERSATILE)
468 - .fromApp(appId)
469 - .makePermanent();
470 498
471 if (type.equals(Objective.Operation.ADD)) { 499 if (type.equals(Objective.Operation.ADD)) {
472 flowObjectiveService.forward(deviceId, forwardingObjective.add()); 500 flowObjectiveService.forward(deviceId, forwardingObjective.add());
...@@ -484,9 +512,8 @@ public final class PceccSrTeBeHandler { ...@@ -484,9 +512,8 @@ public final class PceccSrTeBeHandler {
484 * @param dstPortNum remote port of the adjacency 512 * @param dstPortNum remote port of the adjacency
485 * @param type type of operation 513 * @param type type of operation
486 */ 514 */
487 - public void installAdjLabelRule(DeviceId deviceId, LabelResourceId labelId, 515 + public void installAdjLabelRule(DeviceId deviceId, LabelResourceId labelId, PortNumber srcPortNum,
488 - PortNumber srcPortNum, PortNumber dstPortNum, 516 + PortNumber dstPortNum, Objective.Operation type) {
489 - Objective.Operation type) {
490 checkNotNull(flowObjectiveService); 517 checkNotNull(flowObjectiveService);
491 checkNotNull(appId); 518 checkNotNull(appId);
492 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); 519 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
...@@ -495,15 +522,11 @@ public final class PceccSrTeBeHandler { ...@@ -495,15 +522,11 @@ public final class PceccSrTeBeHandler {
495 selectorBuilder.matchTcpSrc(TpPort.tpPort((int) srcPortNum.toLong())); 522 selectorBuilder.matchTcpSrc(TpPort.tpPort((int) srcPortNum.toLong()));
496 selectorBuilder.matchTcpDst(TpPort.tpPort((int) dstPortNum.toLong())); 523 selectorBuilder.matchTcpDst(TpPort.tpPort((int) dstPortNum.toLong()));
497 524
498 - TrafficTreatment treatment = DefaultTrafficTreatment.builder() 525 + TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
499 - .build();
500 526
501 ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() 527 ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder()
502 - .withSelector(selectorBuilder.build()) 528 + .withSelector(selectorBuilder.build()).withTreatment(treatment)
503 - .withTreatment(treatment) 529 + .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent();
504 - .withFlag(ForwardingObjective.Flag.VERSATILE)
505 - .fromApp(appId)
506 - .makePermanent();
507 530
508 if (type.equals(Objective.Operation.ADD)) { 531 if (type.equals(Objective.Operation.ADD)) {
509 flowObjectiveService.forward(deviceId, forwardingObjective.add()); 532 flowObjectiveService.forward(deviceId, forwardingObjective.add());
......
1 package org.onosproject.pce.pceservice; 1 package org.onosproject.pce.pceservice;
2 2
3 import static org.hamcrest.MatcherAssert.assertThat; 3 import static org.hamcrest.MatcherAssert.assertThat;
4 +import static org.hamcrest.Matchers.notNullValue;
5 +import static org.hamcrest.Matchers.nullValue;
4 import static org.hamcrest.core.Is.is; 6 import static org.hamcrest.core.Is.is;
5 import static org.onlab.graph.GraphPathSearch.ALL_PATHS; 7 import static org.onlab.graph.GraphPathSearch.ALL_PATHS;
8 +import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
9 +import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
6 import static org.onosproject.net.Link.State.ACTIVE; 10 import static org.onosproject.net.Link.State.ACTIVE;
7 import static org.onosproject.net.Link.Type.DIRECT; 11 import static org.onosproject.net.Link.Type.DIRECT;
8 -import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST; 12 +import static org.onosproject.net.MastershipRole.MASTER;
9 -import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
10 import static org.onosproject.net.resource.Resources.continuous; 13 import static org.onosproject.net.resource.Resources.continuous;
11 import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; 14 import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
12 import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; 15 import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
...@@ -19,11 +22,11 @@ import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1; ...@@ -19,11 +22,11 @@ import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE1;
19 import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2; 22 import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE2;
20 import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3; 23 import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE3;
21 import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4; 24 import static org.onosproject.pce.pceservice.PathComputationTest.DEVICE4;
25 +import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
22 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID; 26 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.LOCAL_LSP_ID;
23 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID; 27 import static org.onosproject.pce.pceservice.PcepAnnotationKeys.PLSP_ID;
24 -import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; 28 +import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.COST;
25 -import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; 29 +import static org.onosproject.pce.pceservice.constraint.CostConstraint.Type.TE_COST;
26 -import static org.onosproject.net.MastershipRole.MASTER;
27 30
28 import java.net.URISyntaxException; 31 import java.net.URISyntaxException;
29 import java.util.Collection; 32 import java.util.Collection;
...@@ -51,6 +54,7 @@ import org.onosproject.core.CoreServiceAdapter; ...@@ -51,6 +54,7 @@ import org.onosproject.core.CoreServiceAdapter;
51 import org.onosproject.core.DefaultApplicationId; 54 import org.onosproject.core.DefaultApplicationId;
52 import org.onosproject.core.IdGenerator; 55 import org.onosproject.core.IdGenerator;
53 import org.onosproject.event.Event; 56 import org.onosproject.event.Event;
57 +import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
54 import org.onosproject.incubator.net.resource.label.LabelResourceId; 58 import org.onosproject.incubator.net.resource.label.LabelResourceId;
55 import org.onosproject.incubator.net.resource.label.LabelResourceService; 59 import org.onosproject.incubator.net.resource.label.LabelResourceService;
56 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 60 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
...@@ -65,23 +69,25 @@ import org.onosproject.net.AnnotationKeys; ...@@ -65,23 +69,25 @@ import org.onosproject.net.AnnotationKeys;
65 import org.onosproject.net.Annotations; 69 import org.onosproject.net.Annotations;
66 import org.onosproject.net.ConnectPoint; 70 import org.onosproject.net.ConnectPoint;
67 import org.onosproject.net.DefaultAnnotations; 71 import org.onosproject.net.DefaultAnnotations;
72 +import org.onosproject.net.DefaultAnnotations.Builder;
68 import org.onosproject.net.DefaultDevice; 73 import org.onosproject.net.DefaultDevice;
69 import org.onosproject.net.DefaultLink; 74 import org.onosproject.net.DefaultLink;
70 import org.onosproject.net.Device; 75 import org.onosproject.net.Device;
71 -import org.onosproject.net.DefaultAnnotations.Builder;
72 -import org.onosproject.net.MastershipRole;
73 -import org.onosproject.net.device.DeviceServiceAdapter;
74 -import org.onosproject.net.flowobjective.ForwardingObjective;
75 import org.onosproject.net.DeviceId; 76 import org.onosproject.net.DeviceId;
76 import org.onosproject.net.ElementId; 77 import org.onosproject.net.ElementId;
77 import org.onosproject.net.Link; 78 import org.onosproject.net.Link;
79 +import org.onosproject.net.MastershipRole;
78 import org.onosproject.net.Path; 80 import org.onosproject.net.Path;
79 import org.onosproject.net.PortNumber; 81 import org.onosproject.net.PortNumber;
80 import org.onosproject.net.SparseAnnotations; 82 import org.onosproject.net.SparseAnnotations;
83 +import org.onosproject.net.device.DeviceEvent;
84 +import org.onosproject.net.device.DeviceListener;
85 +import org.onosproject.net.flowobjective.ForwardingObjective;
81 import org.onosproject.net.intent.Constraint; 86 import org.onosproject.net.intent.Constraint;
82 import org.onosproject.net.intent.IntentId; 87 import org.onosproject.net.intent.IntentId;
83 import org.onosproject.net.intent.constraint.BandwidthConstraint; 88 import org.onosproject.net.intent.constraint.BandwidthConstraint;
84 import org.onosproject.net.link.LinkEvent; 89 import org.onosproject.net.link.LinkEvent;
90 +import org.onosproject.net.link.LinkListener;
85 import org.onosproject.net.packet.DefaultInboundPacket; 91 import org.onosproject.net.packet.DefaultInboundPacket;
86 import org.onosproject.net.packet.DefaultPacketContext; 92 import org.onosproject.net.packet.DefaultPacketContext;
87 import org.onosproject.net.packet.InboundPacket; 93 import org.onosproject.net.packet.InboundPacket;
...@@ -106,15 +112,16 @@ import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryA ...@@ -106,15 +112,16 @@ import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryA
106 import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService; 112 import org.onosproject.pce.pceservice.PathComputationTest.MockPathResourceService;
107 import org.onosproject.pce.pceservice.constraint.CostConstraint; 113 import org.onosproject.pce.pceservice.constraint.CostConstraint;
108 import org.onosproject.pce.pcestore.api.PceStore; 114 import org.onosproject.pce.pcestore.api.PceStore;
115 +import org.onosproject.pce.util.FlowObjServiceAdapter;
109 import org.onosproject.pce.util.LabelResourceAdapter; 116 import org.onosproject.pce.util.LabelResourceAdapter;
117 +import org.onosproject.pce.util.MockDeviceService;
118 +import org.onosproject.pce.util.MockLinkService;
110 import org.onosproject.pce.util.PceStoreAdapter; 119 import org.onosproject.pce.util.PceStoreAdapter;
111 import org.onosproject.pce.util.TunnelServiceAdapter; 120 import org.onosproject.pce.util.TunnelServiceAdapter;
112 import org.onosproject.pcep.api.DeviceCapability; 121 import org.onosproject.pcep.api.DeviceCapability;
113 -import org.onosproject.pce.util.FlowObjServiceAdapter;
114 import org.onosproject.store.service.TestStorageService; 122 import org.onosproject.store.service.TestStorageService;
115 123
116 import com.google.common.collect.ImmutableSet; 124 import com.google.common.collect.ImmutableSet;
117 -import static org.onosproject.pce.pceservice.PceManager.PCEP_PORT;
118 125
119 /** 126 /**
120 * Tests the functions of PceManager. 127 * Tests the functions of PceManager.
...@@ -133,16 +140,22 @@ public class PceManagerTest { ...@@ -133,16 +140,22 @@ public class PceManagerTest {
133 private PacketService packetService = new MockPacketService(); 140 private PacketService packetService = new MockPacketService();
134 private MockDeviceService deviceService = new MockDeviceService(); 141 private MockDeviceService deviceService = new MockDeviceService();
135 private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter(); 142 private MockNetConfigRegistryAdapter netConfigRegistry = new PathComputationTest.MockNetConfigRegistryAdapter();
143 + private MockLinkService linkService = new MockLinkService();
136 private MockFlowObjService flowObjectiveService = new MockFlowObjService(); 144 private MockFlowObjService flowObjectiveService = new MockFlowObjService();
137 private PceStore pceStore = new PceStoreAdapter(); 145 private PceStore pceStore = new PceStoreAdapter();
138 private LabelResourceService labelResourceService = new LabelResourceAdapter(); 146 private LabelResourceService labelResourceService = new LabelResourceAdapter();
147 + private LabelResourceAdminService labelRsrcAdminService = new LabelResourceAdapter();
139 148
140 public static ProviderId providerId = new ProviderId("pce", "foo"); 149 public static ProviderId providerId = new ProviderId("pce", "foo");
141 private static final String L3 = "L3"; 150 private static final String L3 = "L3";
142 private static final String LSRID = "lsrId"; 151 private static final String LSRID = "lsrId";
152 + private static final String PCECC_CAPABILITY = "pceccCapability";
153 + private static final String SR_CAPABILITY = "srCapability";
154 + private static final String LABEL_STACK_CAPABILITY = "labelStackCapability";
143 155
144 private TopologyGraph graph = null; 156 private TopologyGraph graph = null;
145 private Device deviceD1, deviceD2, deviceD3, deviceD4; 157 private Device deviceD1, deviceD2, deviceD3, deviceD4;
158 + private Device pcepDeviceD1, pcepDeviceD2, pcepDeviceD3, pcepDeviceD4;
146 private Link link1, link2, link3, link4; 159 private Link link1, link2, link3, link4;
147 protected static int flowsDownloaded; 160 protected static int flowsDownloaded;
148 private TunnelListener tunnelListener; 161 private TunnelListener tunnelListener;
...@@ -162,7 +175,9 @@ public class PceManagerTest { ...@@ -162,7 +175,9 @@ public class PceManagerTest {
162 pceManager.storageService = storageService; 175 pceManager.storageService = storageService;
163 pceManager.packetService = packetService; 176 pceManager.packetService = packetService;
164 pceManager.deviceService = deviceService; 177 pceManager.deviceService = deviceService;
178 + pceManager.linkService = linkService;
165 pceManager.netCfgService = netConfigRegistry; 179 pceManager.netCfgService = netConfigRegistry;
180 + pceManager.labelRsrcAdminService = labelRsrcAdminService;
166 pceManager.labelRsrcService = labelResourceService; 181 pceManager.labelRsrcService = labelResourceService;
167 pceManager.flowObjectiveService = flowObjectiveService; 182 pceManager.flowObjectiveService = flowObjectiveService;
168 pceManager.pceStore = pceStore; 183 pceManager.pceStore = pceStore;
...@@ -219,6 +234,7 @@ public class PceManagerTest { ...@@ -219,6 +234,7 @@ public class PceManagerTest {
219 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder(); 234 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
220 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder(); 235 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
221 236
237 + // Making L3 devices
222 builderDev1.set(AnnotationKeys.TYPE, L3); 238 builderDev1.set(AnnotationKeys.TYPE, L3);
223 builderDev1.set(LSRID, "1.1.1.1"); 239 builderDev1.set(LSRID, "1.1.1.1");
224 240
...@@ -1254,6 +1270,86 @@ public class PceManagerTest { ...@@ -1254,6 +1270,86 @@ public class PceManagerTest {
1254 assertThat(pathService.paths().iterator().next().cost(), is((double) 180)); 1270 assertThat(pathService.paths().iterator().next().cost(), is((double) 180));
1255 } 1271 }
1256 1272
1273 + /*
1274 + * Tests node label allocation/removal in SR-TE case based on device event.
1275 + */
1276 + @Test
1277 + public void deviceEventTest() {
1278 + // Make four router topology with SR-TE capabilities.
1279 + build4RouterTopo(true, false, true, true, 0);
1280 +
1281 + // Add new L3 device
1282 + DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
1283 + builderDev5.set(AnnotationKeys.TYPE, L3);
1284 + builderDev5.set(LSRID, "5.5.5.5");
1285 +
1286 + Device dev5 = new MockDevice(DeviceId.deviceId("P005"), builderDev5.build());
1287 + deviceService.addDevice(dev5);
1288 +
1289 + // Add capability
1290 + DeviceCapability device5Cap = netConfigRegistry.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
1291 + device5Cap.setLabelStackCap(true)
1292 + .setLocalLabelCap(false)
1293 + .setSrCap(true)
1294 + .apply();
1295 +
1296 + // Get listener
1297 + DeviceListener listener = deviceService.getListener();
1298 +
1299 + // Generate Remove events
1300 + deviceService.removeDevice(dev5);
1301 + DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, dev5);
1302 + listener.event(event);
1303 +
1304 + assertThat(pceStore.getGlobalNodeLabel(dev5.id()), is(nullValue()));
1305 + }
1306 +
1307 + /**
1308 + * Tests adjacency label allocation/removal in SR-TE case based on link event.
1309 + */
1310 + @Test
1311 + public void linkEventTest() {
1312 + // Make four router topology with SR-TE capabilities.
1313 + build4RouterTopo(true, false, true, true, 0);
1314 +
1315 + // Get listener
1316 + LinkListener listener = linkService.getListener();
1317 +
1318 + // Adding link3
1319 + linkService.addLink(link3);
1320 +
1321 + // Generate events
1322 + LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link3);
1323 + listener.event(event);
1324 +
1325 + assertThat(pceStore.getAdjLabel(link3), is(notNullValue()));
1326 +
1327 + // Adding link4
1328 + linkService.addLink(link4);
1329 +
1330 + event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link4);
1331 + listener.event(event);
1332 +
1333 + assertThat(pceStore.getAdjLabel(link4), is(notNullValue()));
1334 +
1335 + // Remove link3
1336 + linkService.removeLink(link3);
1337 +
1338 + // Generate events
1339 + event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link3);
1340 + listener.event(event);
1341 +
1342 + assertThat(pceStore.getAdjLabel(link3), is(nullValue()));
1343 +
1344 + // Remove link4
1345 + linkService.removeLink(link4);
1346 +
1347 + event = new LinkEvent(LinkEvent.Type.LINK_REMOVED, link4);
1348 + listener.event(event);
1349 +
1350 + assertThat(pceStore.getAdjLabel(link4), is(nullValue()));
1351 + }
1352 +
1257 @After 1353 @After
1258 public void tearDown() { 1354 public void tearDown() {
1259 pceManager.deactivate(); 1355 pceManager.deactivate();
...@@ -1264,6 +1360,9 @@ public class PceManagerTest { ...@@ -1264,6 +1360,9 @@ public class PceManagerTest {
1264 pceManager.storageService = null; 1360 pceManager.storageService = null;
1265 pceManager.packetService = null; 1361 pceManager.packetService = null;
1266 pceManager.deviceService = null; 1362 pceManager.deviceService = null;
1363 + pceManager.linkService = null;
1364 + pceManager.netCfgService = null;
1365 + pceManager.labelRsrcAdminService = null;
1267 pceManager.labelRsrcService = null; 1366 pceManager.labelRsrcService = null;
1268 pceManager.flowObjectiveService = null; 1367 pceManager.flowObjectiveService = null;
1269 pceManager.pceStore = null; 1368 pceManager.pceStore = null;
...@@ -1441,6 +1540,7 @@ public class PceManagerTest { ...@@ -1441,6 +1540,7 @@ public class PceManagerTest {
1441 1540
1442 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result); 1541 return result.size() == 0 ? Collections.emptySet() : ImmutableSet.copyOf(result);
1443 } 1542 }
1543 +
1444 @Override 1544 @Override
1445 public Iterable<Tunnel> getTunnels(DeviceId deviceId) { 1545 public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
1446 List<Tunnel> tunnelList = new LinkedList<>(); 1546 List<Tunnel> tunnelList = new LinkedList<>();
...@@ -1483,29 +1583,6 @@ public class PceManagerTest { ...@@ -1483,29 +1583,6 @@ public class PceManagerTest {
1483 } 1583 }
1484 } 1584 }
1485 1585
1486 - private class MockDeviceService extends DeviceServiceAdapter {
1487 - List<Device> devices = new LinkedList<>();
1488 -
1489 - private void addDevice(Device dev) {
1490 - devices.add(dev);
1491 - }
1492 -
1493 - @Override
1494 - public Device getDevice(DeviceId deviceId) {
1495 - for (Device dev : devices) {
1496 - if (dev.id().equals(deviceId)) {
1497 - return dev;
1498 - }
1499 - }
1500 - return null;
1501 - }
1502 -
1503 - @Override
1504 - public Iterable<Device> getAvailableDevices() {
1505 - return devices;
1506 - }
1507 - }
1508 -
1509 private PacketProcessor pktProcessor = null; 1586 private PacketProcessor pktProcessor = null;
1510 1587
1511 private class MockPacketService extends PacketServiceAdapter { 1588 private class MockPacketService extends PacketServiceAdapter {
......
...@@ -19,36 +19,44 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -19,36 +19,44 @@ import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is; 19 import static org.hamcrest.Matchers.is;
20 import static org.hamcrest.Matchers.notNullValue; 20 import static org.hamcrest.Matchers.notNullValue;
21 import static org.hamcrest.Matchers.nullValue; 21 import static org.hamcrest.Matchers.nullValue;
22 -
23 import static org.onosproject.net.Link.Type.DIRECT; 22 import static org.onosproject.net.Link.Type.DIRECT;
23 +import static org.onosproject.pce.pceservice.PathComputationTest.D1;
24 +import static org.onosproject.pce.pceservice.PathComputationTest.D2;
25 +import static org.onosproject.pce.pceservice.PathComputationTest.D3;
26 +import static org.onosproject.pce.pceservice.PathComputationTest.D4;
27 +import static org.onosproject.pce.pceservice.PathComputationTest.D5;
24 28
25 -import java.util.HashMap;
26 import java.util.Iterator; 29 import java.util.Iterator;
27 -import java.util.Map;
28 import java.util.List; 30 import java.util.List;
29 import java.util.LinkedList; 31 import java.util.LinkedList;
30 32
31 import org.junit.After; 33 import org.junit.After;
32 import org.junit.Before; 34 import org.junit.Before;
33 import org.junit.Test; 35 import org.junit.Test;
34 -
35 import org.onosproject.incubator.net.resource.label.LabelResourceId; 36 import org.onosproject.incubator.net.resource.label.LabelResourceId;
36 import org.onosproject.core.ApplicationId; 37 import org.onosproject.core.ApplicationId;
37 import org.onosproject.core.CoreService; 38 import org.onosproject.core.CoreService;
38 import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; 39 import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
39 import org.onosproject.incubator.net.resource.label.LabelResourceService; 40 import org.onosproject.incubator.net.resource.label.LabelResourceService;
40 import org.onosproject.incubator.net.tunnel.LabelStack; 41 import org.onosproject.incubator.net.tunnel.LabelStack;
42 +import org.onosproject.net.AnnotationKeys;
43 +import org.onosproject.net.Annotations;
41 import org.onosproject.net.ConnectPoint; 44 import org.onosproject.net.ConnectPoint;
42 import org.onosproject.net.DefaultAnnotations; 45 import org.onosproject.net.DefaultAnnotations;
46 +import org.onosproject.net.DefaultDevice;
43 import org.onosproject.net.DefaultPath; 47 import org.onosproject.net.DefaultPath;
48 +import org.onosproject.net.Device;
44 import org.onosproject.net.DeviceId; 49 import org.onosproject.net.DeviceId;
45 import org.onosproject.net.PortNumber; 50 import org.onosproject.net.PortNumber;
46 import org.onosproject.net.flowobjective.FlowObjectiveService; 51 import org.onosproject.net.flowobjective.FlowObjectiveService;
47 import org.onosproject.net.Path; 52 import org.onosproject.net.Path;
53 +import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
48 import org.onosproject.pce.pcestore.api.PceStore; 54 import org.onosproject.pce.pcestore.api.PceStore;
49 import org.onosproject.net.provider.ProviderId; 55 import org.onosproject.net.provider.ProviderId;
50 import org.onosproject.pce.util.LabelResourceAdapter; 56 import org.onosproject.pce.util.LabelResourceAdapter;
51 import org.onosproject.pce.util.PceStoreAdapter; 57 import org.onosproject.pce.util.PceStoreAdapter;
58 +import org.onosproject.pce.util.MockDeviceService;
59 +import org.onosproject.pcep.api.DeviceCapability;
52 import org.onosproject.net.DefaultLink; 60 import org.onosproject.net.DefaultLink;
53 import org.onosproject.net.Link; 61 import org.onosproject.net.Link;
54 62
...@@ -59,20 +67,24 @@ public class PceccSrTeBeHandlerTest { ...@@ -59,20 +67,24 @@ public class PceccSrTeBeHandlerTest {
59 67
60 public static final long GLOBAL_LABEL_SPACE_MIN = 4097; 68 public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
61 public static final long GLOBAL_LABEL_SPACE_MAX = 5121; 69 public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
70 + private static final String L3 = "L3";
71 + private static final String LSRID = "lsrId";
62 72
63 private PceccSrTeBeHandler srTeHandler; 73 private PceccSrTeBeHandler srTeHandler;
64 - protected LabelResourceAdminService labelRsrcAdminService;
65 - protected LabelResourceService labelRsrcService;
66 - protected PceStore pceStore;
67 - private FlowObjectiveService flowObjectiveService;
68 private CoreService coreService; 74 private CoreService coreService;
75 + private LabelResourceAdminService labelRsrcAdminService;
76 + private LabelResourceService labelRsrcService;
77 + private PceStore pceStore;
78 + private MockDeviceService deviceService;
79 + private FlowObjectiveService flowObjectiveService;
80 + private MockNetConfigRegistryAdapter netCfgService = new PathComputationTest.MockNetConfigRegistryAdapter();
69 private ApplicationId appId; 81 private ApplicationId appId;
70 private ProviderId providerId; 82 private ProviderId providerId;
71 - private DeviceId deviceId1; 83 + private Device deviceD1;
72 - private DeviceId deviceId2; 84 + private Device deviceD2;
73 - private DeviceId deviceId3; 85 + private Device deviceD3;
74 - private DeviceId deviceId4; 86 + private Device deviceD4;
75 - private DeviceId deviceId5; 87 + private Device deviceD5;
76 private PortNumber port1; 88 private PortNumber port1;
77 private PortNumber port2; 89 private PortNumber port2;
78 private PortNumber port3; 90 private PortNumber port3;
...@@ -84,9 +96,6 @@ public class PceccSrTeBeHandlerTest { ...@@ -84,9 +96,6 @@ public class PceccSrTeBeHandlerTest {
84 private Link link4; 96 private Link link4;
85 private Path path1; 97 private Path path1;
86 LabelResourceId labelId; 98 LabelResourceId labelId;
87 - private LabelResourceId labelId1 = LabelResourceId.labelResourceId(4098);
88 - private LabelResourceId labelId2 = LabelResourceId.labelResourceId(4099);
89 - private Map<DeviceId, String> deviceIdLsrIdMap;
90 99
91 @Before 100 @Before
92 public void setUp() throws Exception { 101 public void setUp() throws Exception {
...@@ -98,16 +107,64 @@ public class PceccSrTeBeHandlerTest { ...@@ -98,16 +107,64 @@ public class PceccSrTeBeHandlerTest {
98 coreService = new PceManagerTest.MockCoreService(); 107 coreService = new PceManagerTest.MockCoreService();
99 appId = coreService.registerApplication("org.onosproject.pce"); 108 appId = coreService.registerApplication("org.onosproject.pce");
100 pceStore = new PceStoreAdapter(); 109 pceStore = new PceStoreAdapter();
101 - srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore); 110 + deviceService = new MockDeviceService();
111 + srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore,
112 + deviceService);
102 113
103 // Creates path 114 // Creates path
104 // Creates list of links 115 // Creates list of links
105 providerId = new ProviderId("of", "foo"); 116 providerId = new ProviderId("of", "foo");
106 - deviceId1 = DeviceId.deviceId("of:A"); 117 +
107 - deviceId2 = DeviceId.deviceId("of:B"); 118 + // Devices
108 - deviceId3 = DeviceId.deviceId("of:C"); 119 + DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
109 - deviceId4 = DeviceId.deviceId("of:D"); 120 + DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
110 - deviceId5 = DeviceId.deviceId("of:E"); 121 + DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
122 + DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
123 + DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
124 +
125 + builderDev1.set(AnnotationKeys.TYPE, L3);
126 + builderDev1.set(LSRID, "1.1.1.1");
127 +
128 + builderDev2.set(AnnotationKeys.TYPE, L3);
129 + builderDev2.set(LSRID, "2.2.2.2");
130 +
131 + builderDev3.set(AnnotationKeys.TYPE, L3);
132 + builderDev3.set(LSRID, "3.3.3.3");
133 +
134 + builderDev4.set(AnnotationKeys.TYPE, L3);
135 + builderDev4.set(LSRID, "4.4.4.4");
136 +
137 + builderDev5.set(AnnotationKeys.TYPE, L3);
138 + builderDev5.set(LSRID, "5.5.5.5");
139 +
140 + deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build());
141 + deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build());
142 + deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build());
143 + deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build());
144 + deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build());
145 +
146 + deviceService.addDevice(deviceD1);
147 + deviceService.addDevice(deviceD2);
148 + deviceService.addDevice(deviceD3);
149 + deviceService.addDevice(deviceD4);
150 + deviceService.addDevice(deviceD5);
151 +
152 + DeviceCapability device1Cap = netCfgService.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class);
153 + device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
154 +
155 + DeviceCapability device2Cap = netCfgService.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class);
156 + device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
157 +
158 + DeviceCapability device3Cap = netCfgService.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class);
159 + device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
160 +
161 + DeviceCapability device4Cap = netCfgService.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class);
162 + device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
163 +
164 + DeviceCapability device5Cap = netCfgService.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class);
165 + device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
166 +
167 + // Port Numbers
111 port1 = PortNumber.portNumber(1); 168 port1 = PortNumber.portNumber(1);
112 port2 = PortNumber.portNumber(2); 169 port2 = PortNumber.portNumber(2);
113 port3 = PortNumber.portNumber(3); 170 port3 = PortNumber.portNumber(3);
...@@ -115,41 +172,25 @@ public class PceccSrTeBeHandlerTest { ...@@ -115,41 +172,25 @@ public class PceccSrTeBeHandlerTest {
115 port5 = PortNumber.portNumber(5); 172 port5 = PortNumber.portNumber(5);
116 List<Link> linkList = new LinkedList<>(); 173 List<Link> linkList = new LinkedList<>();
117 174
118 - link1 = DefaultLink.builder() 175 + link1 = DefaultLink.builder().providerId(providerId)
119 - .providerId(providerId)
120 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) 176 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
121 - .src(new ConnectPoint(deviceId1, port1)) 177 + .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT)
122 - .dst(new ConnectPoint(deviceId2, port2)) 178 + .state(Link.State.ACTIVE).build();
123 - .type(DIRECT)
124 - .state(Link.State.ACTIVE)
125 - .build();
126 linkList.add(link1); 179 linkList.add(link1);
127 - link2 = DefaultLink.builder() 180 + link2 = DefaultLink.builder().providerId(providerId)
128 - .providerId(providerId)
129 .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build()) 181 .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
130 - .src(new ConnectPoint(deviceId2, port2)) 182 + .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT)
131 - .dst(new ConnectPoint(deviceId3, port3)) 183 + .state(Link.State.ACTIVE).build();
132 - .type(DIRECT)
133 - .state(Link.State.ACTIVE)
134 - .build();
135 linkList.add(link2); 184 linkList.add(link2);
136 - link3 = DefaultLink.builder() 185 + link3 = DefaultLink.builder().providerId(providerId)
137 - .providerId(providerId)
138 .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build()) 186 .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
139 - .src(new ConnectPoint(deviceId3, port3)) 187 + .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT)
140 - .dst(new ConnectPoint(deviceId4, port4)) 188 + .state(Link.State.ACTIVE).build();
141 - .type(DIRECT)
142 - .state(Link.State.ACTIVE)
143 - .build();
144 linkList.add(link3); 189 linkList.add(link3);
145 - link4 = DefaultLink.builder() 190 + link4 = DefaultLink.builder().providerId(providerId)
146 - .providerId(providerId)
147 .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build()) 191 .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
148 - .src(new ConnectPoint(deviceId4, port4)) 192 + .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT)
149 - .dst(new ConnectPoint(deviceId5, port5)) 193 + .state(Link.State.ACTIVE).build();
150 - .type(DIRECT)
151 - .state(Link.State.ACTIVE)
152 - .build();
153 linkList.add(link4); 194 linkList.add(link4);
154 195
155 // Path 196 // Path
...@@ -174,127 +215,60 @@ public class PceccSrTeBeHandlerTest { ...@@ -174,127 +215,60 @@ public class PceccSrTeBeHandlerTest {
174 */ 215 */
175 @Test 216 @Test
176 public void testReserveGlobalPool() { 217 public void testReserveGlobalPool() {
177 - assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, 218 + assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true));
178 - GLOBAL_LABEL_SPACE_MAX), is(true));
179 - }
180 -
181 - /**
182 - * Checks the operation of allocateNodeLabel() method on node label.
183 - * Considered some nodes are already available before PceManager came up.
184 - */
185 - @Test
186 - public void testAllocateNodeLabel1() {
187 - // Specific device deviceId1
188 -
189 - // Devices mapping with lsr-id
190 - deviceIdLsrIdMap = new HashMap<>();
191 -
192 - //device 1
193 - String lsrId1 = "11.1.1.1";
194 - deviceIdLsrIdMap.put(deviceId1, lsrId1);
195 -
196 - // device 2
197 - String lsrId2 = "12.1.1.1";
198 - deviceIdLsrIdMap.put(deviceId2, lsrId2);
199 -
200 - // device 3
201 - String lsrId3 = "13.1.1.1";
202 - deviceIdLsrIdMap.put(deviceId3, lsrId3);
203 -
204 - // device 4
205 - String lsrId4 = "14.1.1.1";
206 - deviceIdLsrIdMap.put(deviceId4, lsrId4);
207 -
208 - // device 5
209 - String lsrId5 = "15.1.1.1";
210 - deviceIdLsrIdMap.put(deviceId5, lsrId5);
211 -
212 - // Considered devices are stored in deviceIdLsrIdMap.
213 - // Creating temporary tempDeviceIdLsrIdMap to pass to allocateNodeLabel()
214 - Map<DeviceId, String> tempDeviceIdLsrIdMap = new HashMap<>();
215 - for (Map.Entry element : deviceIdLsrIdMap.entrySet()) {
216 - DeviceId devId = (DeviceId) element.getKey();
217 - String lsrId = (String) element.getValue();
218 -
219 - // Allocate node label for specific device devId
220 - assertThat(srTeHandler.allocateNodeLabel(devId, lsrId, tempDeviceIdLsrIdMap), is(true));
221 -
222 - // Retrieve label from store
223 - LabelResourceId labelId = pceStore.getGlobalNodeLabel(devId);
224 -
225 - // Check whether label is generated for this device devId
226 - assertThat(labelId, is(notNullValue()));
227 -
228 - //Now add device to tempDeviceIdLsrIdMap
229 - tempDeviceIdLsrIdMap.put(devId, lsrId);
230 - }
231 } 219 }
232 220
233 /** 221 /**
234 * Checks the operation of allocateNodeLabel() method on node label. 222 * Checks the operation of allocateNodeLabel() method on node label.
235 - * Considered initially map is empty and keep on getting new devices from event.
236 */ 223 */
237 @Test 224 @Test
238 - public void testAllocateNodeLabel2() { 225 + public void testAllocateNodeLabel() {
239 - // Specific device deviceId1 226 + // Specific device D1.deviceId
240 -
241 - // Device-id mapping with lsr-id
242 - deviceIdLsrIdMap = new HashMap<>();
243 227
244 //device 1 228 //device 1
245 String lsrId1 = "11.1.1.1"; 229 String lsrId1 = "11.1.1.1";
246 - // Allocate node label for specific device deviceId1 230 + // Allocate node label for specific device D1deviceId
247 - assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1, deviceIdLsrIdMap), is(true)); 231 + assertThat(srTeHandler.allocateNodeLabel(D1.deviceId(), lsrId1), is(true));
248 // Retrieve label from store 232 // Retrieve label from store
249 - LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); 233 + LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId());
250 - // Check whether label is generated for this device deviceId1 234 + // Check whether label is generated for this device D1.deviceId()
251 assertThat(labelId, is(notNullValue())); 235 assertThat(labelId, is(notNullValue()));
252 - //Now add device to deviceIdLsrIdMap
253 - deviceIdLsrIdMap.put(deviceId1, lsrId1);
254 236
255 // device 2 237 // device 2
256 String lsrId2 = "12.1.1.1"; 238 String lsrId2 = "12.1.1.1";
257 - // Allocate node label for specific device deviceId2 239 + // Allocate node label for specific device D2.deviceId()
258 - assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2, deviceIdLsrIdMap), is(true)); 240 + assertThat(srTeHandler.allocateNodeLabel(D2.deviceId(), lsrId2), is(true));
259 // Retrieve label from store 241 // Retrieve label from store
260 - labelId = pceStore.getGlobalNodeLabel(deviceId2); 242 + labelId = pceStore.getGlobalNodeLabel(D2.deviceId());
261 - // Check whether label is generated for this device deviceId2 243 + // Check whether label is generated for this device D2.deviceId()
262 assertThat(labelId, is(notNullValue())); 244 assertThat(labelId, is(notNullValue()));
263 - //Now add device to deviceIdLsrIdMap
264 - deviceIdLsrIdMap.put(deviceId2, lsrId2);
265 245
266 // device 3 246 // device 3
267 String lsrId3 = "13.1.1.1"; 247 String lsrId3 = "13.1.1.1";
268 - // Allocate node label for specific device deviceId3 248 + // Allocate node label for specific device D3.deviceId()
269 - assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3, deviceIdLsrIdMap), is(true)); 249 + assertThat(srTeHandler.allocateNodeLabel(D3.deviceId(), lsrId3), is(true));
270 // Retrieve label from store 250 // Retrieve label from store
271 - labelId = pceStore.getGlobalNodeLabel(deviceId3); 251 + labelId = pceStore.getGlobalNodeLabel(D3.deviceId());
272 - // Check whether label is generated for this device deviceId3 252 + // Check whether label is generated for this device D3.deviceId()
273 assertThat(labelId, is(notNullValue())); 253 assertThat(labelId, is(notNullValue()));
274 - //Now add device to deviceIdLsrIdMap
275 - deviceIdLsrIdMap.put(deviceId3, lsrId3);
276 254
277 // device 4 255 // device 4
278 String lsrId4 = "14.1.1.1"; 256 String lsrId4 = "14.1.1.1";
279 - // Allocate node label for specific device deviceId4 257 + // Allocate node label for specific device D4.deviceId()
280 - assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4, deviceIdLsrIdMap), is(true)); 258 + assertThat(srTeHandler.allocateNodeLabel(D4.deviceId(), lsrId4), is(true));
281 // Retrieve label from store 259 // Retrieve label from store
282 - labelId = pceStore.getGlobalNodeLabel(deviceId4); 260 + labelId = pceStore.getGlobalNodeLabel(D4.deviceId());
283 - // Check whether label is generated for this device deviceId4 261 + // Check whether label is generated for this device D4.deviceId()
284 assertThat(labelId, is(notNullValue())); 262 assertThat(labelId, is(notNullValue()));
285 - //Now add device to deviceIdLsrIdMap
286 - deviceIdLsrIdMap.put(deviceId4, lsrId4);
287 263
288 // device 5 264 // device 5
289 String lsrId5 = "15.1.1.1"; 265 String lsrId5 = "15.1.1.1";
290 - // Allocate node label for specific device deviceId5 266 + // Allocate node label for specific device D5.deviceId()
291 - assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5, deviceIdLsrIdMap), is(true)); 267 + assertThat(srTeHandler.allocateNodeLabel(D5.deviceId(), lsrId5), is(true));
292 // Retrieve label from store 268 // Retrieve label from store
293 - labelId = pceStore.getGlobalNodeLabel(deviceId5); 269 + labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
294 - // Check whether label is generated for this device deviceId5 270 + // Check whether label is generated for this device D5.deviceId()
295 assertThat(labelId, is(notNullValue())); 271 assertThat(labelId, is(notNullValue()));
296 - //Now add device to deviceIdLsrIdMap
297 - deviceIdLsrIdMap.put(deviceId5, lsrId5);
298 } 272 }
299 273
300 /** 274 /**
...@@ -302,69 +276,59 @@ public class PceccSrTeBeHandlerTest { ...@@ -302,69 +276,59 @@ public class PceccSrTeBeHandlerTest {
302 */ 276 */
303 @Test 277 @Test
304 public void testReleaseNodeLabelSuccess() { 278 public void testReleaseNodeLabelSuccess() {
305 - testAllocateNodeLabel2(); 279 + testAllocateNodeLabel();
306 - // Specific device deviceId1 280 + // Specific device D1.deviceId()
307 281
308 //device 1 282 //device 1
309 String lsrId1 = "11.1.1.1"; 283 String lsrId1 = "11.1.1.1";
310 // Check whether successfully released node label 284 // Check whether successfully released node label
311 - assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1, deviceIdLsrIdMap), is(true)); 285 + assertThat(srTeHandler.releaseNodeLabel(D1.deviceId(), lsrId1), is(true));
312 // Check whether successfully removed label from store 286 // Check whether successfully removed label from store
313 - LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1); 287 + LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId());
314 assertThat(labelId, is(nullValue())); 288 assertThat(labelId, is(nullValue()));
315 - // Remove released deviceId1
316 - deviceIdLsrIdMap.remove(deviceId1);
317 289
318 //device 2 290 //device 2
319 String lsrId2 = "12.1.1.1"; 291 String lsrId2 = "12.1.1.1";
320 // Check whether successfully released node label 292 // Check whether successfully released node label
321 - assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2, deviceIdLsrIdMap), is(true)); 293 + assertThat(srTeHandler.releaseNodeLabel(D2.deviceId(), lsrId2), is(true));
322 // Check whether successfully removed label from store 294 // Check whether successfully removed label from store
323 - labelId = pceStore.getGlobalNodeLabel(deviceId2); 295 + labelId = pceStore.getGlobalNodeLabel(D2.deviceId());
324 assertThat(labelId, is(nullValue())); 296 assertThat(labelId, is(nullValue()));
325 - // Remove released deviceId2
326 - deviceIdLsrIdMap.remove(deviceId2);
327 297
328 //device 3 298 //device 3
329 String lsrId3 = "13.1.1.1"; 299 String lsrId3 = "13.1.1.1";
330 // Check whether successfully released node label 300 // Check whether successfully released node label
331 - assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3, deviceIdLsrIdMap), is(true)); 301 + assertThat(srTeHandler.releaseNodeLabel(D3.deviceId(), lsrId3), is(true));
332 // Check whether successfully removed label from store 302 // Check whether successfully removed label from store
333 - labelId = pceStore.getGlobalNodeLabel(deviceId3); 303 + labelId = pceStore.getGlobalNodeLabel(D3.deviceId());
334 assertThat(labelId, is(nullValue())); 304 assertThat(labelId, is(nullValue()));
335 - // Remove released deviceId3
336 - deviceIdLsrIdMap.remove(deviceId3);
337 305
338 //device 4 306 //device 4
339 String lsrId4 = "14.1.1.1"; 307 String lsrId4 = "14.1.1.1";
340 // Check whether successfully released node label 308 // Check whether successfully released node label
341 - assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4, deviceIdLsrIdMap), is(true)); 309 + assertThat(srTeHandler.releaseNodeLabel(D4.deviceId(), lsrId4), is(true));
342 // Check whether successfully removed label from store 310 // Check whether successfully removed label from store
343 - labelId = pceStore.getGlobalNodeLabel(deviceId4); 311 + labelId = pceStore.getGlobalNodeLabel(D4.deviceId());
344 assertThat(labelId, is(nullValue())); 312 assertThat(labelId, is(nullValue()));
345 - // Remove released deviceId4
346 - deviceIdLsrIdMap.remove(deviceId4);
347 313
348 //device 5 314 //device 5
349 String lsrId5 = "15.1.1.1"; 315 String lsrId5 = "15.1.1.1";
350 // Check whether successfully released node label 316 // Check whether successfully released node label
351 - assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5, deviceIdLsrIdMap), is(true)); 317 + assertThat(srTeHandler.releaseNodeLabel(D5.deviceId(), lsrId5), is(true));
352 // Check whether successfully removed label from store 318 // Check whether successfully removed label from store
353 - labelId = pceStore.getGlobalNodeLabel(deviceId5); 319 + labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
354 assertThat(labelId, is(nullValue())); 320 assertThat(labelId, is(nullValue()));
355 - // Remove released deviceId5
356 - deviceIdLsrIdMap.remove(deviceId5);
357 } 321 }
358 322
359 @Test 323 @Test
360 public void testReleaseNodeLabelFailure() { 324 public void testReleaseNodeLabelFailure() {
361 - testAllocateNodeLabel2(); 325 + testAllocateNodeLabel();
362 326
363 //device 6 327 //device 6
364 String lsrId6 = "16.1.1.1"; 328 String lsrId6 = "16.1.1.1";
365 // Check whether successfully released node label 329 // Check whether successfully released node label
366 DeviceId deviceId6 = DeviceId.deviceId("foo6"); 330 DeviceId deviceId6 = DeviceId.deviceId("foo6");
367 - assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6, deviceIdLsrIdMap), is(false)); 331 + assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false));
368 } 332 }
369 333
370 /** 334 /**
...@@ -430,15 +394,15 @@ public class PceccSrTeBeHandlerTest { ...@@ -430,15 +394,15 @@ public class PceccSrTeBeHandlerTest {
430 public void testComputeLabelStack() { 394 public void testComputeLabelStack() {
431 // Allocate node labels to each devices 395 // Allocate node labels to each devices
432 labelId = LabelResourceId.labelResourceId(4097); 396 labelId = LabelResourceId.labelResourceId(4097);
433 - pceStore.addGlobalNodeLabel(deviceId1, labelId); 397 + pceStore.addGlobalNodeLabel(D1.deviceId(), labelId);
434 labelId = LabelResourceId.labelResourceId(4098); 398 labelId = LabelResourceId.labelResourceId(4098);
435 - pceStore.addGlobalNodeLabel(deviceId2, labelId); 399 + pceStore.addGlobalNodeLabel(D2.deviceId(), labelId);
436 labelId = LabelResourceId.labelResourceId(4099); 400 labelId = LabelResourceId.labelResourceId(4099);
437 - pceStore.addGlobalNodeLabel(deviceId3, labelId); 401 + pceStore.addGlobalNodeLabel(D3.deviceId(), labelId);
438 labelId = LabelResourceId.labelResourceId(4100); 402 labelId = LabelResourceId.labelResourceId(4100);
439 - pceStore.addGlobalNodeLabel(deviceId4, labelId); 403 + pceStore.addGlobalNodeLabel(D4.deviceId(), labelId);
440 labelId = LabelResourceId.labelResourceId(4101); 404 labelId = LabelResourceId.labelResourceId(4101);
441 - pceStore.addGlobalNodeLabel(deviceId5, labelId); 405 + pceStore.addGlobalNodeLabel(D5.deviceId(), labelId);
442 406
443 // Allocate adjacency labels to each devices 407 // Allocate adjacency labels to each devices
444 labelId = LabelResourceId.labelResourceId(5122); 408 labelId = LabelResourceId.labelResourceId(5122);
...@@ -453,42 +417,48 @@ public class PceccSrTeBeHandlerTest { ...@@ -453,42 +417,48 @@ public class PceccSrTeBeHandlerTest {
453 // Compute label stack 417 // Compute label stack
454 LabelStack labelStack = srTeHandler.computeLabelStack(path1); 418 LabelStack labelStack = srTeHandler.computeLabelStack(path1);
455 419
456 - // check node-label of deviceId1 420 + // check node-label of D1.deviceId()
457 List<LabelResourceId> labelList = labelStack.labelResources(); 421 List<LabelResourceId> labelList = labelStack.labelResources();
458 Iterator<LabelResourceId> iterator = labelList.iterator(); 422 Iterator<LabelResourceId> iterator = labelList.iterator();
459 labelId = iterator.next(); 423 labelId = iterator.next();
460 assertThat(labelId, is(LabelResourceId.labelResourceId(4097))); 424 assertThat(labelId, is(LabelResourceId.labelResourceId(4097)));
461 425
462 - // check adjacency label of deviceId1 426 + // check adjacency label of D1.deviceId()
463 labelId = iterator.next(); 427 labelId = iterator.next();
464 assertThat(labelId, is(LabelResourceId.labelResourceId(5122))); 428 assertThat(labelId, is(LabelResourceId.labelResourceId(5122)));
465 429
466 - // check node-label of deviceId2 430 + // check node-label of D2.deviceId()
467 labelId = iterator.next(); 431 labelId = iterator.next();
468 assertThat(labelId, is(LabelResourceId.labelResourceId(4098))); 432 assertThat(labelId, is(LabelResourceId.labelResourceId(4098)));
469 433
470 - // check adjacency label of deviceId2 434 + // check adjacency label of D2.deviceId()
471 labelId = iterator.next(); 435 labelId = iterator.next();
472 assertThat(labelId, is(LabelResourceId.labelResourceId(5123))); 436 assertThat(labelId, is(LabelResourceId.labelResourceId(5123)));
473 437
474 - // check node-label of deviceId3 438 + // check node-label of D3.deviceId()
475 labelId = iterator.next(); 439 labelId = iterator.next();
476 assertThat(labelId, is(LabelResourceId.labelResourceId(4099))); 440 assertThat(labelId, is(LabelResourceId.labelResourceId(4099)));
477 441
478 - // check adjacency label of deviceId3 442 + // check adjacency label of D3.deviceId()
479 labelId = iterator.next(); 443 labelId = iterator.next();
480 assertThat(labelId, is(LabelResourceId.labelResourceId(5124))); 444 assertThat(labelId, is(LabelResourceId.labelResourceId(5124)));
481 445
482 - // check node-label of deviceId4 446 + // check node-label of D4.deviceId()
483 labelId = iterator.next(); 447 labelId = iterator.next();
484 assertThat(labelId, is(LabelResourceId.labelResourceId(4100))); 448 assertThat(labelId, is(LabelResourceId.labelResourceId(4100)));
485 449
486 - // check adjacency label of deviceId4 450 + // check adjacency label of D4.deviceId()
487 labelId = iterator.next(); 451 labelId = iterator.next();
488 assertThat(labelId, is(LabelResourceId.labelResourceId(5125))); 452 assertThat(labelId, is(LabelResourceId.labelResourceId(5125)));
489 453
490 - // check node-label of deviceId5 454 + // check node-label of D5.deviceId()
491 labelId = iterator.next(); 455 labelId = iterator.next();
492 assertThat(labelId, is(LabelResourceId.labelResourceId(4101))); 456 assertThat(labelId, is(LabelResourceId.labelResourceId(4101)));
493 } 457 }
458 +
459 + private class MockDevice extends DefaultDevice {
460 + MockDevice(DeviceId id, Annotations annotations) {
461 + super(null, id, null, null, null, null, null, null, annotations);
462 + }
463 + }
494 } 464 }
......
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.pce.util;
17 +
18 +import java.util.Set;
19 +
20 +import org.onosproject.net.ConnectPoint;
21 +import org.onosproject.net.DeviceId;
22 +import org.onosproject.net.Link;
23 +import org.onosproject.net.link.LinkListener;
24 +import org.onosproject.net.link.LinkService;
25 +import org.onosproject.net.Link.State;
26 +
27 +import com.google.common.collect.FluentIterable;
28 +
29 +/**
30 + * Test adapter for link service.
31 + */
32 +public class LinkServiceAdapter implements LinkService {
33 + @Override
34 + public int getLinkCount() {
35 + return 0;
36 + }
37 +
38 + @Override
39 + public Iterable<Link> getLinks() {
40 + return null;
41 + }
42 +
43 + @Override
44 + public Iterable<Link> getActiveLinks() {
45 + return FluentIterable.from(getLinks())
46 + .filter(input -> input.state() == State.ACTIVE);
47 + }
48 +
49 + @Override
50 + public Set<Link> getDeviceLinks(DeviceId deviceId) {
51 + return null;
52 + }
53 +
54 + @Override
55 + public Set<Link> getDeviceEgressLinks(DeviceId deviceId) {
56 + return null;
57 + }
58 +
59 + @Override
60 + public Set<Link> getDeviceIngressLinks(DeviceId deviceId) {
61 + return null;
62 + }
63 +
64 + @Override
65 + public Set<Link> getLinks(ConnectPoint connectPoint) {
66 + return null;
67 + }
68 +
69 + @Override
70 + public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
71 + return null;
72 + }
73 +
74 + @Override
75 + public Set<Link> getIngressLinks(ConnectPoint connectPoint) {
76 + return null;
77 + }
78 +
79 + @Override
80 + public Link getLink(ConnectPoint src, ConnectPoint dst) {
81 + return null;
82 + }
83 +
84 + @Override
85 + public void addListener(LinkListener listener) {
86 + }
87 +
88 + @Override
89 + public void removeListener(LinkListener listener) {
90 + }
91 +}
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.pce.util;
17 +
18 +import java.util.LinkedList;
19 +import java.util.List;
20 +
21 +import org.onosproject.net.device.DeviceListener;
22 +import org.onosproject.net.device.DeviceServiceAdapter;
23 +import org.onosproject.net.Device;
24 +import org.onosproject.net.DeviceId;
25 +
26 +/**
27 + * Test fixture for the device service.
28 + */
29 +public class MockDeviceService extends DeviceServiceAdapter {
30 + private List<Device> devices = new LinkedList<>();
31 + private DeviceListener listener;
32 +
33 + public void addDevice(Device dev) {
34 + devices.add(dev);
35 + }
36 +
37 + public void removeDevice(Device dev) {
38 + devices.remove(dev);
39 + }
40 +
41 + @Override
42 + public Device getDevice(DeviceId deviceId) {
43 + for (Device dev : devices) {
44 + if (dev.id().equals(deviceId)) {
45 + return dev;
46 + }
47 + }
48 + return null;
49 + }
50 +
51 + @Override
52 + public Iterable<Device> getAvailableDevices() {
53 + return devices;
54 + }
55 +
56 + @Override
57 + public void addListener(DeviceListener listener) {
58 + this.listener = listener;
59 + }
60 +
61 + /**
62 + * Get the listener.
63 + */
64 + public DeviceListener getListener() {
65 + return listener;
66 + }
67 +}
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.pce.util;
17 +
18 +import org.onosproject.net.Link;
19 +import org.onosproject.net.link.LinkServiceAdapter;
20 +import org.onosproject.net.link.LinkListener;
21 +
22 +import java.util.ArrayList;
23 +import java.util.List;
24 +
25 +/**
26 + * Test fixture for the link service.
27 + */
28 +public class MockLinkService extends LinkServiceAdapter {
29 + List<Link> links = new ArrayList<>();
30 + LinkListener listener;
31 +
32 + @Override
33 + public int getLinkCount() {
34 + return links.size();
35 + }
36 +
37 + @Override
38 + public Iterable<Link> getLinks() {
39 + return links;
40 + }
41 +
42 + @Override
43 + public void addListener(LinkListener listener) {
44 + this.listener = listener;
45 + }
46 +
47 + /**
48 + * Get listener.
49 + */
50 + public LinkListener getListener() {
51 + return listener;
52 + }
53 +
54 + /**
55 + * Add link.
56 + *
57 + * @param link needs to be added to list
58 + */
59 + public void addLink(Link link) {
60 + links.add(link);
61 + }
62 +
63 + /**
64 + * Delete link.
65 + *
66 + * @param link needs to be deleted from list
67 + */
68 + public void removeLink(Link link) {
69 + links.remove(link);
70 + }
71 +}