Determines route IP by checking the interface config directly
Previously, SR checked the subnet data structure which contains
multiple subnets now in order to support generic routing.
A missing part of gerrit #11842.
Change-Id: Ia778c8ba5a42927d259c70bbb7538869270a7a1f
diff --git a/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java b/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
index 21f00df..220d3f2 100644
--- a/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
@@ -145,22 +145,22 @@
Ip4Address destIpAddress = Ip4Address.valueOf(icmpReplyIpv4.getDestinationAddress());
Ip4Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress);
- int sid = config.getSegmentId(destRouterAddress);
- if (sid < 0) {
+ int destSid = config.getSegmentId(destRouterAddress);
+ if (destSid < 0) {
log.warn("Cannot find the Segment ID for {}", destAddress);
return;
}
- sendPacketOut(outport, icmpReplyEth, sid);
+ sendPacketOut(outport, icmpReplyEth, destSid);
}
- private void sendPacketOut(ConnectPoint outport, Ethernet payload, int sid) {
+ private void sendPacketOut(ConnectPoint outport, Ethernet payload, int destSid) {
IPv4 ipPacket = (IPv4) payload.getPayload();
Ip4Address destIpAddress = Ip4Address.valueOf(ipPacket.getDestinationAddress());
- if (sid == -1 || config.getSegmentId(payload.getDestinationMAC()) == sid ||
+ if (destSid == -1 || config.getSegmentId(payload.getDestinationMAC()) == destSid ||
config.inSameSubnet(outport.deviceId(), destIpAddress)) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().
setOutput(outport.port()).build();
@@ -175,7 +175,7 @@
payload.setEtherType(Ethernet.MPLS_UNICAST);
MPLS mplsPkt = new MPLS();
- mplsPkt.setLabel(sid);
+ mplsPkt.setLabel(destSid);
mplsPkt.setTtl(((IPv4) payload.getPayload()).getTtl());
mplsPkt.setPayload(payload.getPayload());
payload.setPayload(mplsPkt);
diff --git a/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java b/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
index 15e9fa7..cb0a275 100644
--- a/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
+++ b/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java
@@ -386,17 +386,21 @@
* @return router ip address
*/
public Ip4Address getRouterIpAddressForASubnetHost(Ip4Address destIpAddress) {
- for (Map.Entry<DeviceId, SegmentRouterInfo> entry:
- deviceConfigMap.entrySet()) {
- for (Ip4Prefix prefix : entry.getValue().subnets.values()) {
- if (prefix.contains(destIpAddress)) {
- return entry.getValue().ip;
- }
- }
+ Interface matchIntf = srManager.interfaceService.getMatchingInterface(destIpAddress);
+
+ if (matchIntf == null) {
+ log.debug("No router was found for {}", destIpAddress);
+ return null;
}
- log.debug("No router was found for {}", destIpAddress);
- return null;
+ DeviceId routerDeviceId = matchIntf.connectPoint().deviceId();
+ SegmentRouterInfo srInfo = deviceConfigMap.get(routerDeviceId);
+ if (srInfo == null) {
+ log.debug("No device config was found for {}", routerDeviceId);
+ return null;
+ }
+
+ return srInfo.ip;
}
/**