blob: 6b51ff374472834a73f6e651c048d55500d3380d [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
Charles Chan9f676b62015-10-29 14:58:10 -070018import com.google.common.collect.ImmutableSet;
sangho1e575652015-05-14 00:39:53 -070019import com.google.common.collect.Lists;
sanghob35a6192015-04-01 13:05:26 -070020import org.onlab.packet.Ip4Address;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070021import org.onlab.packet.Ip4Prefix;
sanghob35a6192015-04-01 13:05:26 -070022import org.onlab.packet.MacAddress;
Charles Chan4636be02015-10-07 14:21:45 -070023import org.onosproject.incubator.net.config.basics.ConfigException;
24import org.onosproject.incubator.net.config.basics.InterfaceConfig;
25import org.onosproject.incubator.net.intf.Interface;
26import org.onosproject.net.ConnectPoint;
Charles Chand6832882015-10-05 17:50:33 -070027import org.onosproject.net.config.NetworkConfigRegistry;
Charles Chan4636be02015-10-07 14:21:45 -070028import org.onosproject.net.host.InterfaceIpAddress;
Charles Chand6832882015-10-05 17:50:33 -070029import org.onosproject.segmentrouting.config.SegmentRoutingConfig;
30import org.onosproject.segmentrouting.config.SegmentRoutingConfig.AdjacencySid;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070031import org.onosproject.segmentrouting.grouphandler.DeviceProperties;
sanghob35a6192015-04-01 13:05:26 -070032import org.onosproject.net.DeviceId;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070033import org.onosproject.net.PortNumber;
sanghob35a6192015-04-01 13:05:26 -070034import org.slf4j.Logger;
35import org.slf4j.LoggerFactory;
36
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070037import java.util.ArrayList;
sanghob35a6192015-04-01 13:05:26 -070038import java.util.HashMap;
39import java.util.List;
40import java.util.Map;
Charles Chand6832882015-10-05 17:50:33 -070041import java.util.Set;
Saurav Das0e99e2b2015-10-28 12:39:42 -070042import java.util.concurrent.ConcurrentHashMap;
sanghob35a6192015-04-01 13:05:26 -070043
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070044/**
45 * Segment Routing configuration component that reads the
46 * segment routing related configuration from Network Configuration Manager
47 * component and organizes in more accessible formats.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070048 */
sanghob35a6192015-04-01 13:05:26 -070049public class DeviceConfiguration implements DeviceProperties {
50
51 private static final Logger log = LoggerFactory
52 .getLogger(DeviceConfiguration.class);
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -070053 private final List<Integer> allSegmentIds = new ArrayList<>();
Saurav Das0e99e2b2015-10-28 12:39:42 -070054 private final ConcurrentHashMap<DeviceId, SegmentRouterInfo> deviceConfigMap
55 = new ConcurrentHashMap<>();
sanghob35a6192015-04-01 13:05:26 -070056
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070057 private class SegmentRouterInfo {
58 int nodeSid;
59 DeviceId deviceId;
60 Ip4Address ip;
61 MacAddress mac;
62 boolean isEdge;
63 HashMap<PortNumber, Ip4Address> gatewayIps;
64 HashMap<PortNumber, Ip4Prefix> subnets;
Charles Chand6832882015-10-05 17:50:33 -070065 List<AdjacencySid> adjacencySids;
Charles Chanb8e10c82015-10-14 11:24:40 -070066
67 public SegmentRouterInfo() {
68 this.gatewayIps = new HashMap<>();
69 this.subnets = new HashMap<>();
70 }
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070071 }
sanghob35a6192015-04-01 13:05:26 -070072
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070073 /**
74 * Constructor. Reads all the configuration for all devices of type
75 * Segment Router and organizes into various maps for easier access.
Brian O'Connor52515622015-10-09 17:03:44 -070076 *
77 * @param cfgService config service
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070078 */
Charles Chand6832882015-10-05 17:50:33 -070079 public DeviceConfiguration(NetworkConfigRegistry cfgService) {
Charles Chan4636be02015-10-07 14:21:45 -070080 // Read config from device subject, excluding gatewayIps and subnets.
81 Set<DeviceId> deviceSubjects =
Charles Chand6832882015-10-05 17:50:33 -070082 cfgService.getSubjects(DeviceId.class, SegmentRoutingConfig.class);
Charles Chan4636be02015-10-07 14:21:45 -070083 deviceSubjects.forEach(subject -> {
Charles Chand6832882015-10-05 17:50:33 -070084 SegmentRoutingConfig config =
85 cfgService.getConfig(subject, SegmentRoutingConfig.class);
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070086 SegmentRouterInfo info = new SegmentRouterInfo();
Charles Chand6832882015-10-05 17:50:33 -070087 info.deviceId = subject;
Charles Chan4636be02015-10-07 14:21:45 -070088 info.nodeSid = config.getSid();
Charles Chand6832882015-10-05 17:50:33 -070089 info.ip = config.getIp();
90 info.mac = config.getMac();
91 info.isEdge = config.isEdgeRouter();
Charles Chan4636be02015-10-07 14:21:45 -070092 info.adjacencySids = config.getAdjacencySids();
Charles Chand6832882015-10-05 17:50:33 -070093
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070094 this.deviceConfigMap.put(info.deviceId, info);
95 this.allSegmentIds.add(info.nodeSid);
Charles Chand6832882015-10-05 17:50:33 -070096 });
Charles Chan4636be02015-10-07 14:21:45 -070097
98 // Read gatewayIps and subnets from port subject.
99 Set<ConnectPoint> portSubjects =
100 cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
101 portSubjects.forEach(subject -> {
102 InterfaceConfig config =
103 cfgService.getConfig(subject, InterfaceConfig.class);
104 Set<Interface> networkInterfaces;
105 try {
106 networkInterfaces = config.getInterfaces();
107 } catch (ConfigException e) {
108 log.error("Error loading port configuration");
109 return;
110 }
111 networkInterfaces.forEach(networkInterface -> {
112 DeviceId dpid = networkInterface.connectPoint().deviceId();
113 PortNumber port = networkInterface.connectPoint().port();
114 SegmentRouterInfo info = this.deviceConfigMap.get(dpid);
115
Charles Chanb8e10c82015-10-14 11:24:40 -0700116 // skip if there is no corresponding device for this ConenctPoint
117 if (info != null) {
118 Set<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddresses();
119 interfaceAddresses.forEach(interfaceAddress -> {
120 info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address());
121 info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix());
122 });
123 }
Charles Chan4636be02015-10-07 14:21:45 -0700124 });
125
126 });
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700127 }
128
129 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700130 * Returns the Node segment id of a segment router.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700131 *
132 * @param deviceId device identifier
133 * @return segment id
134 */
sanghob35a6192015-04-01 13:05:26 -0700135 @Override
136 public int getSegmentId(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700137 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
138 if (srinfo != null) {
139 log.trace("getSegmentId for device{} is {}", deviceId, srinfo.nodeSid);
140 return srinfo.nodeSid;
sanghob35a6192015-04-01 13:05:26 -0700141 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700142 log.warn("getSegmentId for device {} "
143 + "throwing IllegalStateException "
144 + "because device does not exist in config", deviceId);
sanghob35a6192015-04-01 13:05:26 -0700145 throw new IllegalStateException();
146 }
147 }
148
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700149 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700150 * Returns the Node segment id of a segment router given its Router mac address.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700151 *
152 * @param routerMac router mac address
Saurav Das0e99e2b2015-10-28 12:39:42 -0700153 * @return node segment id, or -1 if not found in config
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700154 */
155 public int getSegmentId(MacAddress routerMac) {
156 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
157 deviceConfigMap.entrySet()) {
158 if (entry.getValue().mac.equals(routerMac)) {
159 return entry.getValue().nodeSid;
160 }
161 }
sanghob35a6192015-04-01 13:05:26 -0700162
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700163 return -1;
164 }
165
166 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700167 * Returns the Node segment id of a segment router given its Router ip address.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700168 *
169 * @param routerAddress router ip address
Saurav Das0e99e2b2015-10-28 12:39:42 -0700170 * @return node segment id, or -1 if not found in config
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700171 */
172 public int getSegmentId(Ip4Address routerAddress) {
173 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
174 deviceConfigMap.entrySet()) {
175 if (entry.getValue().ip.equals(routerAddress)) {
176 return entry.getValue().nodeSid;
177 }
178 }
179
180 return -1;
181 }
182
183 /**
184 * Returns the router mac of a segment router.
185 *
186 * @param deviceId device identifier
187 * @return router mac address
188 */
sanghob35a6192015-04-01 13:05:26 -0700189 @Override
190 public MacAddress getDeviceMac(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700191 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
192 if (srinfo != null) {
193 log.trace("getDeviceMac for device{} is {}", deviceId, srinfo.mac);
194 return srinfo.mac;
sanghob35a6192015-04-01 13:05:26 -0700195 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700196 log.warn("getDeviceMac for device {} "
197 + "throwing IllegalStateException "
198 + "because device does not exist in config", deviceId);
sanghob35a6192015-04-01 13:05:26 -0700199 throw new IllegalStateException();
200 }
201 }
202
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700203 /**
204 * Returns the router ip address of a segment router.
205 *
206 * @param deviceId device identifier
207 * @return router ip address
208 */
209 public Ip4Address getRouterIp(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700210 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
211 if (srinfo != null) {
212 log.trace("getDeviceIp for device{} is {}", deviceId, srinfo.ip);
213 return srinfo.ip;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700214 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700215 log.warn("getRouterIp for device {} "
216 + "throwing IllegalStateException "
217 + "because device does not exist in config", deviceId);
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700218 throw new IllegalStateException();
sanghob35a6192015-04-01 13:05:26 -0700219 }
sanghob35a6192015-04-01 13:05:26 -0700220 }
221
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700222 /**
223 * Indicates if the segment router is a edge router or
Saurav Das822c4e22015-10-23 10:51:11 -0700224 * a core/backbone router.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700225 *
226 * @param deviceId device identifier
227 * @return boolean
228 */
229 @Override
230 public boolean isEdgeDevice(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700231 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
232 if (srinfo != null) {
233 log.trace("isEdgeDevice for device{} is {}", deviceId, srinfo.isEdge);
234 return srinfo.isEdge;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700235 } else {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700236 log.warn("isEdgeDevice for device {} "
237 + "throwing IllegalStateException "
238 + "because device does not exist in config", deviceId);
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700239 throw new IllegalStateException();
240 }
241 }
242
243 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700244 * Returns the node segment ids of all configured segment routers.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700245 *
Saurav Das822c4e22015-10-23 10:51:11 -0700246 * @return list of node segment ids
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700247 */
sanghob35a6192015-04-01 13:05:26 -0700248 @Override
249 public List<Integer> getAllDeviceSegmentIds() {
250 return allSegmentIds;
251 }
252
Charles Chanc42e84e2015-10-20 16:24:19 -0700253 @Override
254 public Map<Ip4Prefix, List<PortNumber>> getSubnetPortsMap(DeviceId deviceId) {
255 Map<Ip4Prefix, List<PortNumber>> subnetPortMap = new HashMap<>();
256
257 // Construct subnet-port mapping from port-subnet mapping
258 Map<PortNumber, Ip4Prefix> portSubnetMap =
259 this.deviceConfigMap.get(deviceId).subnets;
260 portSubnetMap.forEach((port, subnet) -> {
261 if (subnetPortMap.containsKey(subnet)) {
262 subnetPortMap.get(subnet).add(port);
263 } else {
264 ArrayList<PortNumber> ports = new ArrayList<>();
265 ports.add(port);
266 subnetPortMap.put(subnet, ports);
267 }
268 });
269
270 return subnetPortMap;
271 }
272
sanghob35a6192015-04-01 13:05:26 -0700273 /**
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700274 * Returns the device identifier or data plane identifier (dpid)
275 * of a segment router given its segment id.
sanghob35a6192015-04-01 13:05:26 -0700276 *
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700277 * @param sid segment id
278 * @return deviceId device identifier
sanghob35a6192015-04-01 13:05:26 -0700279 */
280 public DeviceId getDeviceId(int sid) {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700281 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
282 deviceConfigMap.entrySet()) {
283 if (entry.getValue().nodeSid == sid) {
284 return entry.getValue().deviceId;
sanghob35a6192015-04-01 13:05:26 -0700285 }
286 }
287
288 return null;
289 }
290
291 /**
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700292 * Returns the device identifier or data plane identifier (dpid)
293 * of a segment router given its router ip address.
sanghob35a6192015-04-01 13:05:26 -0700294 *
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700295 * @param ipAddress router ip address
296 * @return deviceId device identifier
sanghob35a6192015-04-01 13:05:26 -0700297 */
298 public DeviceId getDeviceId(Ip4Address ipAddress) {
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700299 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
300 deviceConfigMap.entrySet()) {
301 if (entry.getValue().ip.equals(ipAddress)) {
302 return entry.getValue().deviceId;
sanghob35a6192015-04-01 13:05:26 -0700303 }
304 }
305
306 return null;
307 }
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700308
309 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700310 * Returns the configured port ip addresses for a segment router.
311 * These addresses serve as gateway IP addresses for the subnets configured
312 * on those ports.
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700313 *
314 * @param deviceId device identifier
Saurav Das0e99e2b2015-10-28 12:39:42 -0700315 * @return list of ip addresses configured on the ports or null if not found
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700316 */
Saurav Das822c4e22015-10-23 10:51:11 -0700317 public List<Ip4Address> getPortIPs(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700318 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
319 if (srinfo != null) {
320 log.trace("getSubnetGatewayIps for device{} is {}", deviceId,
321 srinfo.gatewayIps.values());
322 return new ArrayList<>(srinfo.gatewayIps.values());
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700323 }
Saurav Das0e99e2b2015-10-28 12:39:42 -0700324 return null;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700325 }
326
327 /**
Saurav Das822c4e22015-10-23 10:51:11 -0700328 * Returns the configured IP addresses per port
329 * for a segment router.
330 *
331 * @param deviceId device identifier
Saurav Das0e99e2b2015-10-28 12:39:42 -0700332 * @return map of port to gateway IP addresses or null if not found
Saurav Das822c4e22015-10-23 10:51:11 -0700333 */
334 public Map<PortNumber, Ip4Address> getPortIPMap(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700335 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
336 if (srinfo != null) {
337 return srinfo.gatewayIps;
Saurav Das822c4e22015-10-23 10:51:11 -0700338 }
339 return null;
340 }
341
342 /**
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700343 * Returns the configured subnet prefixes for a segment router.
344 *
345 * @param deviceId device identifier
Saurav Das0e99e2b2015-10-28 12:39:42 -0700346 * @return list of ip prefixes or null if not found
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700347 */
Charles Chan9f676b62015-10-29 14:58:10 -0700348 public Set<Ip4Prefix> getSubnets(DeviceId deviceId) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700349 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
350 if (srinfo != null) {
351 log.trace("getSubnets for device{} is {}", deviceId,
352 srinfo.subnets.values());
Charles Chan9f676b62015-10-29 14:58:10 -0700353 return ImmutableSet.copyOf(srinfo.subnets.values());
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700354 }
Saurav Das0e99e2b2015-10-28 12:39:42 -0700355 return null;
356 }
357
358 /**
359 * Returns the configured subnet on the given port, or null if no
360 * subnet has been configured on the port.
361 *
362 * @param deviceId device identifier
363 * @param pnum port identifier
364 * @return configured subnet on port, or null
365 */
366 public Ip4Prefix getPortSubnet(DeviceId deviceId, PortNumber pnum) {
367 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
368 if (srinfo != null) {
369 return srinfo.subnets.get(pnum);
370 }
371 return null;
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700372 }
373
374 /**
375 * Returns the router ip address of segment router that has the
376 * specified ip address in its subnets.
377 *
378 * @param destIpAddress target ip address
379 * @return router ip address
380 */
381 public Ip4Address getRouterIpAddressForASubnetHost(Ip4Address destIpAddress) {
382 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
383 deviceConfigMap.entrySet()) {
384 for (Ip4Prefix prefix:entry.getValue().subnets.values()) {
385 if (prefix.contains(destIpAddress)) {
386 return entry.getValue().ip;
387 }
388 }
389 }
390
391 log.debug("No router was found for {}", destIpAddress);
392 return null;
393 }
394
395 /**
396 * Returns the router mac address of segment router that has the
397 * specified ip address as one of its subnet gateway ip address.
398 *
399 * @param gatewayIpAddress router gateway ip address
Saurav Das0e99e2b2015-10-28 12:39:42 -0700400 * @return router mac address or null if not found
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -0700401 */
402 public MacAddress getRouterMacForAGatewayIp(Ip4Address gatewayIpAddress) {
403 for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
404 deviceConfigMap.entrySet()) {
405 if (entry.getValue().gatewayIps.
406 values().contains(gatewayIpAddress)) {
407 return entry.getValue().mac;
408 }
409 }
410
411 log.debug("Cannot find a router for {}", gatewayIpAddress);
412 return null;
413 }
sangho666cd6d2015-04-14 16:27:13 -0700414
415
416 /**
417 * Checks if the host is in the subnet defined in the router with the
418 * device ID given.
419 *
420 * @param deviceId device identification of the router
421 * @param hostIp host IP address to check
422 * @return true if the host is within the subnet of the router,
423 * false if no subnet is defined under the router or if the host is not
424 * within the subnet defined in the router
425 */
426 public boolean inSameSubnet(DeviceId deviceId, Ip4Address hostIp) {
427
Charles Chan9f676b62015-10-29 14:58:10 -0700428 Set<Ip4Prefix> subnets = getSubnets(deviceId);
sangho666cd6d2015-04-14 16:27:13 -0700429 if (subnets == null) {
430 return false;
431 }
432
433 for (Ip4Prefix subnet: subnets) {
434 if (subnet.contains(hostIp)) {
435 return true;
436 }
437 }
438
439 return false;
440 }
sangho1e575652015-05-14 00:39:53 -0700441
442 /**
443 * Returns the ports corresponding to the adjacency Sid given.
444 *
445 * @param deviceId device identification of the router
446 * @param sid adjacency Sid
447 * @return list of port numbers
448 */
449 public List<Integer> getPortsForAdjacencySid(DeviceId deviceId, int sid) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700450 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
451 if (srinfo != null) {
452 for (AdjacencySid asid : srinfo.adjacencySids) {
Charles Chan4636be02015-10-07 14:21:45 -0700453 if (asid.getAsid() == sid) {
sangho1e575652015-05-14 00:39:53 -0700454 return asid.getPorts();
455 }
456 }
457 }
458
459 return Lists.newArrayList();
460 }
461
462 /**
463 * Check if the Sid given is whether adjacency Sid of the router device or not.
464 *
465 * @param deviceId device identification of the router
466 * @param sid Sid to check
467 * @return true if the Sid given is the adjacency Sid of the device,
468 * otherwise false
469 */
470 public boolean isAdjacencySid(DeviceId deviceId, int sid) {
Saurav Das0e99e2b2015-10-28 12:39:42 -0700471 SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId);
472 if (srinfo != null) {
473 if (srinfo.adjacencySids.isEmpty()) {
sangho1e575652015-05-14 00:39:53 -0700474 return false;
475 } else {
Charles Chand6832882015-10-05 17:50:33 -0700476 for (AdjacencySid asid:
Saurav Das0e99e2b2015-10-28 12:39:42 -0700477 srinfo.adjacencySids) {
Charles Chan4636be02015-10-07 14:21:45 -0700478 if (asid.getAsid() == sid) {
sangho1e575652015-05-14 00:39:53 -0700479 return true;
480 }
481 }
482 return false;
483 }
484 }
485
486 return false;
487 }
Charles Chand6832882015-10-05 17:50:33 -0700488}