Daniel Park
Committed by Gerrit Code Review

[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
...@@ -191,8 +191,10 @@ public class OpenstackIcmpHandler { ...@@ -191,8 +191,10 @@ public class OpenstackIcmpHandler {
191 icmpReq.setChecksum((short) 0); 191 icmpReq.setChecksum((short) 0);
192 icmpReq.setIcmpType(ICMP.TYPE_ECHO_REPLY).resetChecksum(); 192 icmpReq.setIcmpType(ICMP.TYPE_ECHO_REPLY).resetChecksum();
193 193
194 + int destinationAddress = ipPacket.getSourceAddress();
195 +
194 ipPacket.setSourceAddress(ipPacket.getDestinationAddress()) 196 ipPacket.setSourceAddress(ipPacket.getDestinationAddress())
195 - .setDestinationAddress(ipPacket.getSourceAddress()) 197 + .setDestinationAddress(destinationAddress)
196 .resetChecksum(); 198 .resetChecksum();
197 199
198 ipPacket.setPayload(icmpReq); 200 ipPacket.setPayload(icmpReq);
...@@ -200,7 +202,7 @@ public class OpenstackIcmpHandler { ...@@ -200,7 +202,7 @@ public class OpenstackIcmpHandler {
200 icmpReply.setEtherType(Ethernet.TYPE_IPV4) 202 icmpReply.setEtherType(Ethernet.TYPE_IPV4)
201 .setSourceMACAddress(Constants.DEFAULT_GATEWAY_MAC) 203 .setSourceMACAddress(Constants.DEFAULT_GATEWAY_MAC)
202 .setDestinationMACAddress(reqHost.mac()) 204 .setDestinationMACAddress(reqHost.mac())
203 - .setPayload(icmpReq); 205 + .setPayload(ipPacket);
204 206
205 sendReply(icmpReply, reqHost); 207 sendReply(icmpReply, reqHost);
206 } 208 }
......
...@@ -161,7 +161,15 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider ...@@ -161,7 +161,15 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider
161 return; 161 return;
162 } 162 }
163 163
164 - registerDhcpInfo(osPort); 164 + OpenstackSubnet openstackSubnet = openstackService.subnets().stream()
165 + .filter(n -> n.networkId().equals(osPort.networkId()))
166 + .findFirst().orElse(null);
167 + if (openstackSubnet == null) {
168 + log.warn("Failed to find subnet for {}", osPort);
169 + return;
170 + }
171 +
172 + registerDhcpInfo(osPort, openstackSubnet);
165 ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number()); 173 ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
166 // TODO remove gateway IP from host annotation 174 // TODO remove gateway IP from host annotation
167 Map.Entry<String, Ip4Address> fixedIp = osPort.fixedIps().entrySet().stream().findFirst().get(); 175 Map.Entry<String, Ip4Address> fixedIp = osPort.fixedIps().entrySet().stream().findFirst().get();
...@@ -175,7 +183,7 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider ...@@ -175,7 +183,7 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider
175 .set(VXLAN_ID, osNet.segmentId()) 183 .set(VXLAN_ID, osNet.segmentId())
176 .set(TENANT_ID, osNet.tenantId()) 184 .set(TENANT_ID, osNet.tenantId())
177 // TODO remove gateway IP from host annotation 185 // TODO remove gateway IP from host annotation
178 - .set(GATEWAY_IP, fixedIp.getValue().toString()) 186 + .set(GATEWAY_IP, openstackSubnet.gatewayIp())
179 .set(CREATE_TIME, String.valueOf(System.currentTimeMillis())); 187 .set(CREATE_TIME, String.valueOf(System.currentTimeMillis()));
180 188
181 HostDescription hostDesc = new DefaultHostDescription( 189 HostDescription hostDesc = new DefaultHostDescription(
...@@ -202,18 +210,11 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider ...@@ -202,18 +210,11 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider
202 }); 210 });
203 } 211 }
204 212
205 - private void registerDhcpInfo(OpenstackPort openstackPort) { 213 + private void registerDhcpInfo(OpenstackPort openstackPort, OpenstackSubnet openstackSubnet) {
206 checkNotNull(openstackPort); 214 checkNotNull(openstackPort);
215 + checkNotNull(openstackSubnet);
207 checkArgument(!openstackPort.fixedIps().isEmpty()); 216 checkArgument(!openstackPort.fixedIps().isEmpty());
208 217
209 - OpenstackSubnet openstackSubnet = openstackService.subnets().stream()
210 - .filter(n -> n.networkId().equals(openstackPort.networkId()))
211 - .findFirst().orElse(null);
212 - if (openstackSubnet == null) {
213 - log.warn("Failed to find subnet for {}", openstackPort);
214 - return;
215 - }
216 -
217 Ip4Address ipAddress = openstackPort.fixedIps().values().stream().findFirst().get(); 218 Ip4Address ipAddress = openstackPort.fixedIps().values().stream().findFirst().get();
218 IpPrefix subnetPrefix = IpPrefix.valueOf(openstackSubnet.cidr()); 219 IpPrefix subnetPrefix = IpPrefix.valueOf(openstackSubnet.cidr());
219 Ip4Address broadcast = Ip4Address.makeMaskedAddress( 220 Ip4Address broadcast = Ip4Address.makeMaskedAddress(
......