[ONOS-5030] Fix to gateway ip address in host annotation refers appropriate ip address
- Fix to gateway ip address in host annotation refers right ip address, not host ip address
Change-Id: Ia07ed828d2f37e623dcca4ad204bfbaf4db2a45a
diff --git a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java
index b6bf09a..f46a94b 100644
--- a/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java
+++ b/apps/openstacknetworking/routing/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java
@@ -191,8 +191,10 @@
icmpReq.setChecksum((short) 0);
icmpReq.setIcmpType(ICMP.TYPE_ECHO_REPLY).resetChecksum();
+ int destinationAddress = ipPacket.getSourceAddress();
+
ipPacket.setSourceAddress(ipPacket.getDestinationAddress())
- .setDestinationAddress(ipPacket.getSourceAddress())
+ .setDestinationAddress(destinationAddress)
.resetChecksum();
ipPacket.setPayload(icmpReq);
@@ -200,7 +202,7 @@
icmpReply.setEtherType(Ethernet.TYPE_IPV4)
.setSourceMACAddress(Constants.DEFAULT_GATEWAY_MAC)
.setDestinationMACAddress(reqHost.mac())
- .setPayload(icmpReq);
+ .setPayload(ipPacket);
sendReply(icmpReply, reqHost);
}
diff --git a/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingHostManager.java b/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingHostManager.java
index 2d6621a..dd6d4bf 100644
--- a/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingHostManager.java
+++ b/apps/openstacknetworking/switching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingHostManager.java
@@ -161,7 +161,15 @@
return;
}
- registerDhcpInfo(osPort);
+ OpenstackSubnet openstackSubnet = openstackService.subnets().stream()
+ .filter(n -> n.networkId().equals(osPort.networkId()))
+ .findFirst().orElse(null);
+ if (openstackSubnet == null) {
+ log.warn("Failed to find subnet for {}", osPort);
+ return;
+ }
+
+ registerDhcpInfo(osPort, openstackSubnet);
ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
// TODO remove gateway IP from host annotation
Map.Entry<String, Ip4Address> fixedIp = osPort.fixedIps().entrySet().stream().findFirst().get();
@@ -175,7 +183,7 @@
.set(VXLAN_ID, osNet.segmentId())
.set(TENANT_ID, osNet.tenantId())
// TODO remove gateway IP from host annotation
- .set(GATEWAY_IP, fixedIp.getValue().toString())
+ .set(GATEWAY_IP, openstackSubnet.gatewayIp())
.set(CREATE_TIME, String.valueOf(System.currentTimeMillis()));
HostDescription hostDesc = new DefaultHostDescription(
@@ -202,18 +210,11 @@
});
}
- private void registerDhcpInfo(OpenstackPort openstackPort) {
+ private void registerDhcpInfo(OpenstackPort openstackPort, OpenstackSubnet openstackSubnet) {
checkNotNull(openstackPort);
+ checkNotNull(openstackSubnet);
checkArgument(!openstackPort.fixedIps().isEmpty());
- OpenstackSubnet openstackSubnet = openstackService.subnets().stream()
- .filter(n -> n.networkId().equals(openstackPort.networkId()))
- .findFirst().orElse(null);
- if (openstackSubnet == null) {
- log.warn("Failed to find subnet for {}", openstackPort);
- return;
- }
-
Ip4Address ipAddress = openstackPort.fixedIps().values().stream().findFirst().get();
IpPrefix subnetPrefix = IpPrefix.valueOf(openstackSubnet.cidr());
Ip4Address broadcast = Ip4Address.makeMaskedAddress(