blob: cb394f8972f504ea095d14e263530b06d3ee76ea [file] [log] [blame]
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -07001/*******************************************************************************
2 * Copyright (c) 2014 Open Networking Laboratory.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Apache License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 ******************************************************************************/
8
9package net.onrc.onos.apps.segmentrouting;
10
11import java.util.ArrayList;
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -070012import java.util.HashSet;
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070013import java.util.Iterator;
14import java.util.List;
15
16import net.floodlightcontroller.core.IFloodlightProviderService;
17import net.floodlightcontroller.core.IOFSwitch;
18import net.floodlightcontroller.core.module.FloodlightModuleContext;
19import net.floodlightcontroller.util.MACAddress;
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070020import net.onrc.onos.core.flowprogrammer.IFlowPusherService;
21import net.onrc.onos.core.packet.ARP;
22import net.onrc.onos.core.packet.Ethernet;
23import net.onrc.onos.core.packet.IPv4;
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -070024import net.onrc.onos.core.topology.Host;
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070025import net.onrc.onos.core.topology.ITopologyService;
26import net.onrc.onos.core.topology.MutableTopology;
27import net.onrc.onos.core.topology.Port;
28import net.onrc.onos.core.topology.Switch;
29
30import org.json.JSONArray;
31import org.json.JSONException;
32import org.projectfloodlight.openflow.protocol.OFFactory;
33import org.projectfloodlight.openflow.protocol.OFPacketOut;
34import org.projectfloodlight.openflow.protocol.action.OFAction;
35import org.projectfloodlight.openflow.types.IPv4Address;
36import org.projectfloodlight.openflow.types.MacAddress;
37import org.projectfloodlight.openflow.types.OFPort;
38import org.projectfloodlight.openflow.types.U32;
39import org.slf4j.Logger;
40import org.slf4j.LoggerFactory;
41
42import com.esotericsoftware.minlog.Log;
43
44/**
45 * Handling ARP requests to switches for Segment Routing.
46 * <p/>
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -070047 * The module is for handling ARP requests to switches. It sends ARP response
48 * for any known hosts to the controllers. TODO: need to check the network
49 * config file for all hosts and packets
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070050 */
Srikanth Vavilapallib1fce732014-09-24 14:09:50 -070051public class ArpHandler {
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070052
53 private static final Logger log = LoggerFactory
54 .getLogger(ArpHandler.class);
55
56 private IFloodlightProviderService floodlightProvider;
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070057 private IFlowPusherService flowPusher;
58 private ITopologyService topologyService;
59 private MutableTopology mutableTopology;
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -070060 // private List<ArpEntry> arpEntries;
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070061 private SegmentRoutingManager srManager;
62
63 private static final short IDLE_TIMEOUT = 0;
64 private static final short HARD_TIMEOUT = 0;
65
66 private static final int TABLE_VLAN = 0;
67 private static final int TABLE_TMAC = 1;
68 private static final int TABLE_IPv4_UNICAST = 2;
69 private static final int TABLE_MPLS = 3;
70 private static final int TABLE_META = 4;
71 private static final int TABLE_ACL = 5;
72
73 private static final short MAX_PRIORITY = (short) 0xffff;
74 private static final short SLASH_24_PRIORITY = (short) 0xfff0;
75 private static final short SLASH_16_PRIORITY = (short) 0xff00;
76 private static final short SLASH_8_PRIORITY = (short) 0xf000;
77 private static final short MIN_PRIORITY = 0x0;
78
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070079 /*
80 * Default Constructor
81 */
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -070082 public ArpHandler(FloodlightModuleContext context,
83 SegmentRoutingManager segmentRoutingManager) {
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070084
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -070085 this.floodlightProvider = context
86 .getServiceImpl(IFloodlightProviderService.class);
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070087 this.flowPusher = context.getServiceImpl(IFlowPusherService.class);
88 this.topologyService = context.getServiceImpl(ITopologyService.class);
89 this.srManager = segmentRoutingManager;
90 this.mutableTopology = topologyService.getTopology();
91
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -070092 Log.debug("Arp Handler is initialized");
93
94 }
95
Sangho Shin463bee52014-09-29 15:14:43 -070096 /**
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -070097 * process ARP packets from switches It add a IP routing rule to the host If
98 * it is an ARP response, then flush out all pending packets to the host
99 *
Sangho Shin463bee52014-09-29 15:14:43 -0700100 * @param sw
101 * @param inPort
102 * @param payload
103 */
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700104 public void processPacketIn(Switch sw, Port inPort, Ethernet payload) {
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700105
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700106 log.debug("ArpHandler: Received a ARP packet from sw {} ", sw.getDpid());
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700107
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700108 ARP arp = (ARP) payload.getPayload();
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700109
Sangho Shin463bee52014-09-29 15:14:43 -0700110 byte[] senderMacAddressByte = arp.getSenderHardwareAddress();
111 IPv4Address hostIpAddress = IPv4Address.of(arp.getSenderProtocolAddress());
112 log.debug("ArpHandler: Add IP route to Host {} ", hostIpAddress);
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700113 srManager.addRouteToHost(sw, hostIpAddress.getInt(), senderMacAddressByte);
Sangho Shin463bee52014-09-29 15:14:43 -0700114
Srikanth Vavilapallib1fce732014-09-24 14:09:50 -0700115 if (arp.getOpCode() == ARP.OP_REQUEST) {
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700116 log.debug("ArpHandler: Received a ARP Requestfrom sw {} ", sw.getDpid());
Srikanth Vavilapallib1fce732014-09-24 14:09:50 -0700117 handleArpRequest(sw, inPort, payload);
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700118 }
Sangho Shin463bee52014-09-29 15:14:43 -0700119 else {
120 byte[] destIp = arp.getSenderProtocolAddress();
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700121 for (IPv4 ipPacket : srManager.getIpPacketFromQueue(destIp)) {
Sangho Shin463bee52014-09-29 15:14:43 -0700122 if (ipPacket != null && !inSameSubnet(sw, ipPacket)) {
123 Ethernet eth = new Ethernet();
124 eth.setDestinationMACAddress(payload.getSourceMACAddress());
125 eth.setSourceMACAddress(sw.getStringAttribute("routerMac"));
126 eth.setEtherType(Ethernet.TYPE_IPV4);
127 eth.setPayload(ipPacket);
128 sendPacketOut(sw, eth, inPort.getNumber().shortValue());
129 }
130 }
131 }
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700132 }
133
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700134 /**
135 * Send an ARP response for the ARP request to the known switches
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700136 *
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700137 * @param sw Switch
138 * @param inPort port to send ARP response to
139 * @param arpRequest ARP request packet to handle
140 */
Srikanth Vavilapallib1fce732014-09-24 14:09:50 -0700141 private void handleArpRequest(Switch sw, Port inPort, Ethernet payload) {
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700142
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700143 ARP arpRequest = (ARP) payload.getPayload();
144 MACAddress targetMac = null;
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700145
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700146 if (isArpReqForSwitch(sw, arpRequest)) {
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700147 String switchMacAddressStr = sw.getStringAttribute("routerMac");
148 targetMac = MACAddress.valueOf(switchMacAddressStr);
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700149 log.debug("ArpHandler: Received a ARP query for a sw {} ", sw.getDpid());
150 }
151 else {
152 Host knownHost = isArpReqForKnownHost(sw, arpRequest);
153 if (knownHost != null) {
Sangho Shin3a5fcad2014-10-01 14:14:49 -0700154 targetMac = knownHost.getMacAddress();
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700155 log.debug("ArpHandler: Received a ARP query for a known host {} ",
156 IPv4Address.of(knownHost.getIpAddress()));
157 }
158 }
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700159
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700160 if (targetMac != null) {
161 /* ARP Destination is known. Packet out ARP Reply */
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700162 ARP arpReply = new ARP();
163 arpReply.setHardwareType(ARP.HW_TYPE_ETHERNET)
164 .setProtocolType(ARP.PROTO_TYPE_IP)
165 .setHardwareAddressLength(
166 (byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
167 .setProtocolAddressLength((byte) IPv4.ADDRESS_LENGTH)
168 .setOpCode(ARP.OP_REPLY)
169 .setSenderHardwareAddress(targetMac.toBytes())
170 .setSenderProtocolAddress(arpRequest.getTargetProtocolAddress())
171 .setTargetHardwareAddress(arpRequest.getSenderHardwareAddress())
172 .setTargetProtocolAddress(arpRequest.getSenderProtocolAddress());
173
174 Ethernet eth = new Ethernet();
175 eth.setDestinationMACAddress(arpRequest.getSenderHardwareAddress())
176 .setSourceMACAddress(targetMac.toBytes())
177 .setEtherType(Ethernet.TYPE_ARP).setPayload(arpReply);
178
179 sendPacketOut(sw, eth, inPort.getPortNumber().shortValue());
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700180 }
181 else
182 {
183 /* Broadcast the received ARP request to all switch ports
184 * that subnets are connected to except the port from which
185 * ARP request is received
186 */
187 IPv4Address targetAddress =
188 IPv4Address.of(arpRequest.getTargetProtocolAddress());
189 log.debug("ArpHandler: Received a ARP query for unknown host {} ",
190 IPv4Address.of(arpRequest.getTargetProtocolAddress()));
191 for (Integer portNo : getSwitchSubnetPorts(sw, targetAddress)) {
192 if (portNo.shortValue() == inPort.getPortNumber().shortValue())
193 continue;
194 log.debug("ArpHandler: Sending ARP request on switch {} port {}",
195 sw.getDpid(), portNo.shortValue());
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700196 sendPacketOut(sw, payload, portNo.shortValue());
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700197 }
198 }
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700199 }
200
Sangho Shin463bee52014-09-29 15:14:43 -0700201 /**
202 * Check if the ARP request is to known hosts
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700203 *
204 * @param sw Switch
205 * @param arpRequest ARP request to check
Sangho Shin463bee52014-09-29 15:14:43 -0700206 */
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700207 private Host isArpReqForKnownHost(Switch sw, ARP arpRequest) {
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700208 Host knownHost = null;
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700209
210 IPv4Address targetIPAddress = IPv4Address.of(
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700211 arpRequest.getTargetProtocolAddress());
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700212
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700213 for (Host host : sw.getHosts()) {
214 if (host.getIpAddress() == targetIPAddress.getInt()) {
215 knownHost = host;
216 break;
217 }
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700218 }
219 return knownHost;
220
221 }
Sangho Shin463bee52014-09-29 15:14:43 -0700222
223 /**
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700224 *
Sangho Shin463bee52014-09-29 15:14:43 -0700225 * Check if the ARP is for the switch
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700226 *
Sangho Shin463bee52014-09-29 15:14:43 -0700227 * @param sw Switch
228 * @param arpRequest ARP request to check
229 * @return true if the ARP is for the switch
230 */
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700231 private boolean isArpReqForSwitch(Switch sw, ARP arpRequest) {
232 List<String> subnetGatewayIPs = getSubnetGatewayIps(sw);
233 boolean isArpForSwitch = false;
234 if (!subnetGatewayIPs.isEmpty()) {
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700235 IPv4Address targetProtocolAddress = IPv4Address.of(arpRequest
236 .getTargetProtocolAddress());
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700237 if (subnetGatewayIPs.contains(targetProtocolAddress.toString())) {
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700238 isArpForSwitch = true;
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700239 }
240 }
241 return isArpForSwitch;
242 }
Sangho Shin463bee52014-09-29 15:14:43 -0700243
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700244 /**
245 * Retrieve Gateway IP address of all subnets defined in net config file
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700246 *
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700247 * @param sw Switch to retrieve subnet GW IPs for
248 * @return list of GW IP addresses for all subnets
249 */
250 private List<String> getSubnetGatewayIps(Switch sw) {
251
252 List<String> gatewayIps = new ArrayList<String>();
253
254 String subnets = sw.getStringAttribute("subnets");
255 try {
256 JSONArray arry = new JSONArray(subnets);
257 for (int i = 0; i < arry.length(); i++) {
258 String subnetIpSlash = (String) arry.getJSONObject(i).get("subnetIp");
259 if (subnetIpSlash != null) {
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700260 String subnetIp = subnetIpSlash.substring(0,
261 subnetIpSlash.indexOf('/'));
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700262 gatewayIps.add(subnetIp);
263 }
264 }
265 } catch (JSONException e) {
266 // TODO Auto-generated catch block
267 e.printStackTrace();
268 }
269
270 return gatewayIps;
271 }
272
Sangho Shin3a5fcad2014-10-01 14:14:49 -0700273 private HashSet<Integer> getSwitchSubnetPorts(Switch sw, IPv4Address targetAddress) {
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700274 HashSet<Integer> switchSubnetPorts = new HashSet<Integer>();
275
276 String subnets = sw.getStringAttribute("subnets");
277 try {
278 JSONArray arry = new JSONArray(subnets);
279 for (int i = 0; i < arry.length(); i++) {
Sangho Shin3a5fcad2014-10-01 14:14:49 -0700280 String subnetIpSlash = (String) arry.getJSONObject(i).get("subnetIp");
281 if (srManager.netMatch(subnetIpSlash, targetAddress.toString())) {
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700282 Integer subnetPort = (Integer) arry.getJSONObject(i).get("portNo");
Sangho Shin3a5fcad2014-10-01 14:14:49 -0700283 switchSubnetPorts.add(subnetPort);
284 }
Srikanth Vavilapalli27f2a122014-09-24 15:56:02 -0700285 }
286 } catch (JSONException e) {
287 // TODO Auto-generated catch block
288 e.printStackTrace();
289 }
290
291 return switchSubnetPorts;
292 }
293
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700294 /**
295 * Send an ARP request
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700296 *
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700297 * @param sw Switch
298 * @param targetAddress Target IP address
299 * @param inPort Port to send the ARP request
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700300 *
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700301 */
302 public void sendArpRequest(Switch sw, int targetAddressInt, Port inPort) {
303
304 IPv4Address targetAddress = IPv4Address.of(targetAddressInt);
305 String senderMacAddressStr = sw.getStringAttribute("routerMac");
306 String senderIpAddressSlash = sw.getStringAttribute("routerIp");
307 if (senderMacAddressStr == null || senderIpAddressSlash == null)
308 return;
309 String senderIpAddressStr =
310 senderIpAddressSlash.substring(0, senderIpAddressSlash.indexOf('/'));
311 byte[] senderMacAddress = MacAddress.of(senderMacAddressStr).getBytes();
312 byte[] senderIpAddress = IPv4Address.of(senderIpAddressStr).getBytes();
313
314 ARP arpRequest = new ARP();
315 arpRequest.setHardwareType(ARP.HW_TYPE_ETHERNET)
316 .setProtocolType(ARP.PROTO_TYPE_IP)
317 .setHardwareAddressLength(
318 (byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
319 .setProtocolAddressLength((byte) IPv4.ADDRESS_LENGTH)
320 .setOpCode(ARP.OP_REQUEST)
321 .setSenderHardwareAddress(senderMacAddress)
322 .setTargetHardwareAddress(MacAddress.NONE.getBytes())
323 .setSenderProtocolAddress(senderIpAddress)
324 .setTargetProtocolAddress(targetAddress.getBytes());
325
326 Ethernet eth = new Ethernet();
327 eth.setDestinationMACAddress(MacAddress.BROADCAST.getBytes())
328 .setSourceMACAddress(senderMacAddress)
329 .setEtherType(Ethernet.TYPE_ARP).setPayload(arpRequest);
330
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700331 /* Broadcast the ARP request to all switch ports
332 * that subnets are connected to except the port from which
333 * ARP request is received
334 */
335 for (Integer portNo : getSwitchSubnetPorts(sw, targetAddress)) {
336 if (portNo.shortValue() == inPort.getPortNumber().shortValue())
337 continue;
338 log.debug("ArpHandler: Sending ARP request on switch {} port {}",
339 sw.getDpid(), portNo.shortValue());
Srikanth Vavilapallia95d5832014-09-24 16:38:52 -0700340 sendPacketOut(sw, eth, portNo.shortValue());
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700341 }
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700342 }
343
344 /**
345 * Send PACKET_OUT packet to switch
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700346 *
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700347 * @param sw Switch to send the packet to
348 * @param packet Packet to send
349 * @param switchPort port to send (if -1, broadcast)
350 */
351 private void sendPacketOut(Switch sw, Ethernet packet, short port) {
352
353 IOFSwitch ofSwitch = floodlightProvider.getMasterSwitch(sw.getDpid().value());
354 OFFactory factory = ofSwitch.getFactory();
355
356 List<OFAction> actions = new ArrayList<>();
357
358 if (port > 0) {
359 OFAction outport = factory.actions().output(OFPort.of(port), Short.MAX_VALUE);
360 actions.add(outport);
361 }
362 else {
363 Iterator<Port> iter = sw.getPorts().iterator();
364 while (iter.hasNext()) {
365 Port p = iter.next();
366 int pnum = p.getPortNumber().shortValue();
367 if (U32.of(pnum).compareTo(U32.of(OFPort.MAX.getPortNumber())) < 1) {
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700368 OFAction outport = factory.actions().output(
369 OFPort.of(p.getNumber().shortValue()),
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700370 Short.MAX_VALUE);
371 actions.add(outport);
372 }
373 }
374 }
375
376 OFPacketOut po = factory.buildPacketOut()
377 .setData(packet.serialize())
378 .setActions(actions)
379 .build();
380
381 flowPusher.add(sw.getDpid(), po);
382 }
383
Sangho Shin463bee52014-09-29 15:14:43 -0700384 /**
385 * Check if the source IP and destination IP are in the same subnet
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700386 *
Sangho Shin463bee52014-09-29 15:14:43 -0700387 * @param sw Switch
388 * @param ipv4 IP address to check
389 * @return return true if the IP packet is within the same subnet
390 */
391 private boolean inSameSubnet(Switch sw, IPv4 ipv4) {
392
393 String gwIpSrc = getGwIpForSubnet(ipv4.getSourceAddress());
394 String gwIpDest = getGwIpForSubnet(ipv4.getDestinationAddress());
395
396 if (gwIpSrc.equals(gwIpDest)) {
397 return true;
398 }
399 else
400 return false;
401 }
402
403 /**
404 * Get router IP address for the given IP address
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700405 *
Sangho Shin463bee52014-09-29 15:14:43 -0700406 * @param sourceAddress
407 * @return
408 */
409 private String getGwIpForSubnet(int sourceAddress) {
410
411 String gwIp = null;
412 IPv4Address srcIp = IPv4Address.of(sourceAddress);
413
Srikanth Vavilapallif25c7b02014-10-01 14:30:43 -0700414 for (Switch sw : mutableTopology.getSwitches()) {
Sangho Shin463bee52014-09-29 15:14:43 -0700415
416 String subnets = sw.getStringAttribute("subnets");
417 try {
418 JSONArray arry = new JSONArray(subnets);
419 for (int i = 0; i < arry.length(); i++) {
420 String subnetIpSlash = (String) arry.getJSONObject(i).get("subnetIp");
421 if (srManager.netMatch(subnetIpSlash, srcIp.toString())) {
422 gwIp = subnetIpSlash;
423 }
424 }
425 } catch (JSONException e) {
426 // TODO Auto-generated catch block
427 e.printStackTrace();
428 }
429 }
430
431 return gwIp;
432 }
433
Srikanth Vavilapalli7f479d92014-09-24 13:36:46 -0700434}