blob: 5c10eb628bf71ec45e7015096659fb4d9e99fb6d [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Charles Chand6832882015-10-05 17:50:33 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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 */
sanghob35a6192015-04-01 13:05:26 -070016package org.onosproject.segmentrouting;
17
sangho1e575652015-05-14 00:39:53 -070018import com.google.common.collect.Lists;
sanghob35a6192015-04-01 13:05:26 -070019import org.onlab.packet.Ip4Address;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070020import org.onlab.packet.Ip4Prefix;
sanghob35a6192015-04-01 13:05:26 -070021import org.onlab.packet.MacAddress;
Charles Chan4636be02015-10-07 14:21:45 -070022import org.onosproject.incubator.net.config.basics.ConfigException;
23import org.onosproject.incubator.net.config.basics.InterfaceConfig;
24import org.onosproject.incubator.net.intf.Interface;
25import org.onosproject.net.ConnectPoint;
Charles Chand6832882015-10-05 17:50:33 -070026import org.onosproject.net.config.NetworkConfigRegistry;
Charles Chan4636be02015-10-07 14:21:45 -070027import org.onosproject.net.host.InterfaceIpAddress;
Charles Chand6832882015-10-05 17:50:33 -070028import org.onosproject.segmentrouting.config.SegmentRoutingConfig;
29import org.onosproject.segmentrouting.config.SegmentRoutingConfig.AdjacencySid;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070030import org.onosproject.segmentrouting.grouphandler.DeviceProperties;
sanghob35a6192015-04-01 13:05:26 -070031import org.onosproject.net.DeviceId;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070032import org.onosproject.net.PortNumber;
sanghob35a6192015-04-01 13:05:26 -070033import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
35
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070036import java.util.ArrayList;
sanghob35a6192015-04-01 13:05:26 -070037import java.util.HashMap;
38import java.util.List;
39import java.util.Map;
Charles Chand6832882015-10-05 17:50:33 -070040import java.util.Set;
Saurav Das0e99e2b2015-10-28 12:39:42 -070041import java.util.concurrent.ConcurrentHashMap;
sanghob35a6192015-04-01 13:05:26 -070042
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070043/**
44 * Segment Routing configuration component that reads the
45 * segment routing related configuration from Network Configuration Manager
46 * component and organizes in more accessible formats.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070047 */
sanghob35a6192015-04-01 13:05:26 -070048public class DeviceConfiguration implements DeviceProperties {
49
50 private static final Logger log = LoggerFactory
51 .getLogger(DeviceConfiguration.class);
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -070052 private final List<Integer> allSegmentIds = new ArrayList<>();
Saurav Das0e99e2b2015-10-28 12:39:42 -070053 private final ConcurrentHashMap<DeviceId, SegmentRouterInfo> deviceConfigMap
54 = new ConcurrentHashMap<>();
sanghob35a6192015-04-01 13:05:26 -070055
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070056 private class SegmentRouterInfo {
57 int nodeSid;
58 DeviceId deviceId;
59 Ip4Address ip;
60 MacAddress mac;
61 boolean isEdge;
62 HashMap<PortNumber, Ip4Address> gatewayIps;
63 HashMap<PortNumber, Ip4Prefix> subnets;
Charles Chand6832882015-10-05 17:50:33 -070064 List<AdjacencySid> adjacencySids;
Charles Chanb8e10c82015-10-14 11:24:40 -070065
66 public SegmentRouterInfo() {
67 this.gatewayIps = new HashMap<>();
68 this.subnets = new HashMap<>();
69 }
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070070 }
sanghob35a6192015-04-01 13:05:26 -070071
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070072 /**
73 * Constructor. Reads all the configuration for all devices of type
74 * Segment Router and organizes into various maps for easier access.
Brian O'Connor52515622015-10-09 17:03:44 -070075 *
76 * @param cfgService config service
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070077 */
Charles Chand6832882015-10-05 17:50:33 -070078 public DeviceConfiguration(NetworkConfigRegistry cfgService) {
Charles Chan4636be02015-10-07 14:21:45 -070079 // Read config from device subject, excluding gatewayIps and subnets.
80 Set<DeviceId> deviceSubjects =
Charles Chand6832882015-10-05 17:50:33 -070081 cfgService.getSubjects(DeviceId.class, SegmentRoutingConfig.class);
Charles Chan4636be02015-10-07 14:21:45 -070082 deviceSubjects.forEach(subject -> {
Charles Chand6832882015-10-05 17:50:33 -070083 SegmentRoutingConfig config =
84 cfgService.getConfig(subject, SegmentRoutingConfig.class);
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070085 SegmentRouterInfo info = new SegmentRouterInfo();
Charles Chand6832882015-10-05 17:50:33 -070086 info.deviceId = subject;
Charles Chan4636be02015-10-07 14:21:45 -070087 info.nodeSid = config.getSid();
Charles Chand6832882015-10-05 17:50:33 -070088 info.ip = config.getIp();
89 info.mac = config.getMac();
90 info.isEdge = config.isEdgeRouter();
Charles Chan4636be02015-10-07 14:21:45 -070091 info.adjacencySids = config.getAdjacencySids();
Charles Chand6832882015-10-05 17:50:33 -070092
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070093 this.deviceConfigMap.put(info.deviceId, info);
94 this.allSegmentIds.add(info.nodeSid);
Charles Chand6832882015-10-05 17:50:33 -070095 });
Charles Chan4636be02015-10-07 14:21:45 -070096
97 // Read gatewayIps and subnets from port subject.
98 Set<ConnectPoint> portSubjects =
99 cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
100 portSubjects.forEach(subject -> {
101 InterfaceConfig config =
102 cfgService.getConfig(subject, InterfaceConfig.class);
103 Set<Interface> networkInterfaces;
104 try {
105 networkInterfaces = config.getInterfaces();
106 } catch (ConfigException e) {
107 log.error("Error loading port configuration");
108 return;
109 }
110 networkInterfaces.forEach(networkInterface -> {
111 DeviceId dpid = networkInterface.connectPoint().deviceId();
112 PortNumber port = networkInterface.connectPoint().port();
113 SegmentRouterInfo info = this.deviceConfigMap.get(dpid);
114
Charles Chanb8e10c82015-10-14 11:24:40 -0700115 // skip if there is no corresponding device for this ConenctPoint
116 if (info != null) {
117 Set<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddresses();
118 interfaceAddresses.forEach(interfaceAddress -> {
119 info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address());
120 info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix());
121 });
122 }
Charles Chan4636be02015-10-07 14:21:45 -0700123 });
124
125 });
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700126 }
127
128 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700129 * Returns the Node segment id of a segment router.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700130 *
131 * @param deviceId device identifier
132 * @return segment id
133 */
sanghob35a6192015-04-01 13:05:26 -0700134 @Override
135 public int getSegmentId(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700136 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
137 if (srinfo != null) {
138 log.trace("getSegmentId for device{} is {}", deviceId, srinfo.nodeSid);
139 return srinfo.nodeSid;
sanghob35a6192015-04-01 13:05:26 -0700140 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700141 log.warn("getSegmentId for device {} "
142 + "throwing IllegalStateException "
143 + "because device does not exist in config", deviceId);
sanghob35a6192015-04-01 13:05:26 -0700144 throw new IllegalStateException();
145 }
146 }
147
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700148 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700149 * Returns the Node segment id of a segment router given its Router mac address.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700150 *
151 * @param routerMac router mac address
Saurav Das0e99e2b2015-10-28 12:39:42 -0700152 * @return node segment id, or -1 if not found in config
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700153 */
154 public int getSegmentId(MacAddress routerMac) {
155 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
156 deviceConfigMap.entrySet()) {
157 if (entry.getValue().mac.equals(routerMac)) {
158 return entry.getValue().nodeSid;
159 }
160 }
sanghob35a6192015-04-01 13:05:26 -0700161
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700162 return -1;
163 }
164
165 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700166 * Returns the Node segment id of a segment router given its Router ip address.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700167 *
168 * @param routerAddress router ip address
Saurav Das0e99e2b2015-10-28 12:39:42 -0700169 * @return node segment id, or -1 if not found in config
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700170 */
171 public int getSegmentId(Ip4Address routerAddress) {
172 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
173 deviceConfigMap.entrySet()) {
174 if (entry.getValue().ip.equals(routerAddress)) {
175 return entry.getValue().nodeSid;
176 }
177 }
178
179 return -1;
180 }
181
182 /**
183 * Returns the router mac of a segment router.
184 *
185 * @param deviceId device identifier
186 * @return router mac address
187 */
sanghob35a6192015-04-01 13:05:26 -0700188 @Override
189 public MacAddress getDeviceMac(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700190 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
191 if (srinfo != null) {
192 log.trace("getDeviceMac for device{} is {}", deviceId, srinfo.mac);
193 return srinfo.mac;
sanghob35a6192015-04-01 13:05:26 -0700194 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700195 log.warn("getDeviceMac for device {} "
196 + "throwing IllegalStateException "
197 + "because device does not exist in config", deviceId);
sanghob35a6192015-04-01 13:05:26 -0700198 throw new IllegalStateException();
199 }
200 }
201
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700202 /**
203 * Returns the router ip address of a segment router.
204 *
205 * @param deviceId device identifier
206 * @return router ip address
207 */
208 public Ip4Address getRouterIp(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700209 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
210 if (srinfo != null) {
211 log.trace("getDeviceIp for device{} is {}", deviceId, srinfo.ip);
212 return srinfo.ip;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700213 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700214 log.warn("getRouterIp for device {} "
215 + "throwing IllegalStateException "
216 + "because device does not exist in config", deviceId);
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700217 throw new IllegalStateException();
sanghob35a6192015-04-01 13:05:26 -0700218 }
sanghob35a6192015-04-01 13:05:26 -0700219 }
220
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700221 /**
222 * Indicates if the segment router is a edge router or
Saurav Das822c4e22015-10-23 10:51:11 -0700223 * a core/backbone router.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700224 *
225 * @param deviceId device identifier
226 * @return boolean
227 */
228 @Override
229 public boolean isEdgeDevice(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700230 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
231 if (srinfo != null) {
232 log.trace("isEdgeDevice for device{} is {}", deviceId, srinfo.isEdge);
233 return srinfo.isEdge;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700234 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700235 log.warn("isEdgeDevice for device {} "
236 + "throwing IllegalStateException "
237 + "because device does not exist in config", deviceId);
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700238 throw new IllegalStateException();
239 }
240 }
241
242 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700243 * Returns the node segment ids of all configured segment routers.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700244 *
Saurav Das822c4e22015-10-23 10:51:11 -0700245 * @return list of node segment ids
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700246 */
sanghob35a6192015-04-01 13:05:26 -0700247 @Override
248 public List<Integer> getAllDeviceSegmentIds() {
249 return allSegmentIds;
250 }
251
Charles Chanc42e84e2015-10-20 16:24:19 -0700252 @Override
253 public Map<Ip4Prefix, List<PortNumber>> getSubnetPortsMap(DeviceId deviceId) {
254 Map<Ip4Prefix, List<PortNumber>> subnetPortMap = new HashMap<>();
255
256 // Construct subnet-port mapping from port-subnet mapping
257 Map<PortNumber, Ip4Prefix> portSubnetMap =
258 this.deviceConfigMap.get(deviceId).subnets;
259 portSubnetMap.forEach((port, subnet) -> {
260 if (subnetPortMap.containsKey(subnet)) {
261 subnetPortMap.get(subnet).add(port);
262 } else {
263 ArrayList<PortNumber> ports = new ArrayList<>();
264 ports.add(port);
265 subnetPortMap.put(subnet, ports);
266 }
267 });
268
269 return subnetPortMap;
270 }
271
sanghob35a6192015-04-01 13:05:26 -0700272 /**
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700273 * Returns the device identifier or data plane identifier (dpid)
274 * of a segment router given its segment id.
sanghob35a6192015-04-01 13:05:26 -0700275 *
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700276 * @param sid segment id
277 * @return deviceId device identifier
sanghob35a6192015-04-01 13:05:26 -0700278 */
279 public DeviceId getDeviceId(int sid) {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700280 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
281 deviceConfigMap.entrySet()) {
282 if (entry.getValue().nodeSid == sid) {
283 return entry.getValue().deviceId;
sanghob35a6192015-04-01 13:05:26 -0700284 }
285 }
286
287 return null;
288 }
289
290 /**
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700291 * Returns the device identifier or data plane identifier (dpid)
292 * of a segment router given its router ip address.
sanghob35a6192015-04-01 13:05:26 -0700293 *
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700294 * @param ipAddress router ip address
295 * @return deviceId device identifier
sanghob35a6192015-04-01 13:05:26 -0700296 */
297 public DeviceId getDeviceId(Ip4Address ipAddress) {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700298 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
299 deviceConfigMap.entrySet()) {
300 if (entry.getValue().ip.equals(ipAddress)) {
301 return entry.getValue().deviceId;
sanghob35a6192015-04-01 13:05:26 -0700302 }
303 }
304
305 return null;
306 }
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700307
308 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700309 * Returns the configured port ip addresses for a segment router.
310 * These addresses serve as gateway IP addresses for the subnets configured
311 * on those ports.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700312 *
313 * @param deviceId device identifier
Saurav Das0e99e2b2015-10-28 12:39:42 -0700314 * @return list of ip addresses configured on the ports or null if not found
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700315 */
Saurav Das822c4e22015-10-23 10:51:11 -0700316 public List<Ip4Address> getPortIPs(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700317 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
318 if (srinfo != null) {
319 log.trace("getSubnetGatewayIps for device{} is {}", deviceId,
320 srinfo.gatewayIps.values());
321 return new ArrayList<>(srinfo.gatewayIps.values());
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700322 }
Saurav Das0e99e2b2015-10-28 12:39:42 -0700323 return null;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700324 }
325
326 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700327 * Returns the configured IP addresses per port
328 * for a segment router.
329 *
330 * @param deviceId device identifier
Saurav Das0e99e2b2015-10-28 12:39:42 -0700331 * @return map of port to gateway IP addresses or null if not found
Saurav Das822c4e22015-10-23 10:51:11 -0700332 */
333 public Map<PortNumber, Ip4Address> getPortIPMap(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700334 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
335 if (srinfo != null) {
336 return srinfo.gatewayIps;
Saurav Das822c4e22015-10-23 10:51:11 -0700337 }
338 return null;
339 }
340
341 /**
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700342 * Returns the configured subnet prefixes for a segment router.
343 *
344 * @param deviceId device identifier
Saurav Das0e99e2b2015-10-28 12:39:42 -0700345 * @return list of ip prefixes or null if not found
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700346 */
347 public List<Ip4Prefix> getSubnets(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700348 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
349 if (srinfo != null) {
350 log.trace("getSubnets for device{} is {}", deviceId,
351 srinfo.subnets.values());
352 return new ArrayList<>(srinfo.subnets.values());
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700353 }
Saurav Das0e99e2b2015-10-28 12:39:42 -0700354 return null;
355 }
356
357 /**
358 * Returns the configured subnet on the given port, or null if no
359 * subnet has been configured on the port.
360 *
361 * @param deviceId device identifier
362 * @param pnum port identifier
363 * @return configured subnet on port, or null
364 */
365 public Ip4Prefix getPortSubnet(DeviceId deviceId, PortNumber pnum) {
366 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
367 if (srinfo != null) {
368 return srinfo.subnets.get(pnum);
369 }
370 return null;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700371 }
372
373 /**
374 * Returns the router ip address of segment router that has the
375 * specified ip address in its subnets.
376 *
377 * @param destIpAddress target ip address
378 * @return router ip address
379 */
380 public Ip4Address getRouterIpAddressForASubnetHost(Ip4Address destIpAddress) {
381 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
382 deviceConfigMap.entrySet()) {
383 for (Ip4Prefix prefix:entry.getValue().subnets.values()) {
384 if (prefix.contains(destIpAddress)) {
385 return entry.getValue().ip;
386 }
387 }
388 }
389
390 log.debug("No router was found for {}", destIpAddress);
391 return null;
392 }
393
394 /**
395 * Returns the router mac address of segment router that has the
396 * specified ip address as one of its subnet gateway ip address.
397 *
398 * @param gatewayIpAddress router gateway ip address
Saurav Das0e99e2b2015-10-28 12:39:42 -0700399 * @return router mac address or null if not found
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700400 */
401 public MacAddress getRouterMacForAGatewayIp(Ip4Address gatewayIpAddress) {
402 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
403 deviceConfigMap.entrySet()) {
404 if (entry.getValue().gatewayIps.
405 values().contains(gatewayIpAddress)) {
406 return entry.getValue().mac;
407 }
408 }
409
410 log.debug("Cannot find a router for {}", gatewayIpAddress);
411 return null;
412 }
sangho666cd6d2015-04-14 16:27:13 -0700413
414
415 /**
416 * Checks if the host is in the subnet defined in the router with the
417 * device ID given.
418 *
419 * @param deviceId device identification of the router
420 * @param hostIp host IP address to check
421 * @return true if the host is within the subnet of the router,
422 * false if no subnet is defined under the router or if the host is not
423 * within the subnet defined in the router
424 */
425 public boolean inSameSubnet(DeviceId deviceId, Ip4Address hostIp) {
426
427 List<Ip4Prefix> subnets = getSubnets(deviceId);
428 if (subnets == null) {
429 return false;
430 }
431
432 for (Ip4Prefix subnet: subnets) {
433 if (subnet.contains(hostIp)) {
434 return true;
435 }
436 }
437
438 return false;
439 }
sangho1e575652015-05-14 00:39:53 -0700440
441 /**
442 * Returns the ports corresponding to the adjacency Sid given.
443 *
444 * @param deviceId device identification of the router
445 * @param sid adjacency Sid
446 * @return list of port numbers
447 */
448 public List<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700449 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
450 if (srinfo != null) {
451 for (AdjacencySid asid : srinfo.adjacencySids) {
Charles Chan4636be02015-10-07 14:21:45 -0700452 if (asid.getAsid() == sid) {
sangho1e575652015-05-14 00:39:53 -0700453 return asid.getPorts();
454 }
455 }
456 }
457
458 return Lists.newArrayList();
459 }
460
461 /**
462 * Check if the Sid given is whether adjacency Sid of the router device or not.
463 *
464 * @param deviceId device identification of the router
465 * @param sid Sid to check
466 * @return true if the Sid given is the adjacency Sid of the device,
467 * otherwise false
468 */
469 public boolean isAdjacencySid(DeviceId deviceId, int sid) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700470 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
471 if (srinfo != null) {
472 if (srinfo.adjacencySids.isEmpty()) {
sangho1e575652015-05-14 00:39:53 -0700473 return false;
474 } else {
Charles Chand6832882015-10-05 17:50:33 -0700475 for (AdjacencySid asid:
Saurav Das0e99e2b2015-10-28 12:39:42 -0700476 srinfo.adjacencySids) {
Charles Chan4636be02015-10-07 14:21:45 -0700477 if (asid.getAsid() == sid) {
sangho1e575652015-05-14 00:39:53 -0700478 return true;
479 }
480 }
481 return false;
482 }
483 }
484
485 return false;
486 }
Charles Chand6832882015-10-05 17:50:33 -0700487}