blob: 29bb95a3198ccebbdc68956e4afe6b05ab16c42e [file] [log] [blame]
TeruU8b2d1672014-04-25 17:02:56 -07001package net.onrc.onos.apps.proxyarp;
2
Sho SHIMIZU107344e2014-08-13 16:11:53 -07003import static org.easymock.EasyMock.anyLong;
4import static org.easymock.EasyMock.anyObject;
5import static org.easymock.EasyMock.anyShort;
6import static org.easymock.EasyMock.createMock;
7import static org.easymock.EasyMock.eq;
8import static org.easymock.EasyMock.expect;
9import static org.easymock.EasyMock.expectLastCall;
10import static org.easymock.EasyMock.isA;
11import static org.easymock.EasyMock.replay;
TeruU8b2d1672014-04-25 17:02:56 -070012import static org.junit.Assert.assertEquals;
13import static org.junit.Assert.assertTrue;
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070014
TeruU8b2d1672014-04-25 17:02:56 -070015import java.net.InetAddress;
16import java.net.UnknownHostException;
17import java.nio.ByteBuffer;
18import java.util.ArrayList;
19import java.util.HashMap;
20import java.util.List;
21import java.util.Map;
22
TeruU8b2d1672014-04-25 17:02:56 -070023import net.floodlightcontroller.core.IFloodlightProviderService;
24import net.floodlightcontroller.core.module.FloodlightModuleContext;
25import net.floodlightcontroller.restserver.IRestApiService;
26import net.floodlightcontroller.util.MACAddress;
27import net.onrc.onos.api.packet.IPacketService;
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -070028import net.onrc.onos.apps.proxyarp.web.ArpWebRoutable;
TeruU8b2d1672014-04-25 17:02:56 -070029import net.onrc.onos.core.datagrid.IDatagridService;
30import net.onrc.onos.core.datagrid.IEventChannel;
31import net.onrc.onos.core.datagrid.IEventChannelListener;
TeruU8b2d1672014-04-25 17:02:56 -070032import net.onrc.onos.core.flowprogrammer.IFlowPusherService;
Jonathan Hart03102132014-07-01 23:22:04 -070033import net.onrc.onos.core.hostmanager.IHostService;
TeruU8b2d1672014-04-25 17:02:56 -070034import net.onrc.onos.core.main.config.IConfigInfoService;
35import net.onrc.onos.core.packet.ARP;
36import net.onrc.onos.core.packet.Ethernet;
37import net.onrc.onos.core.packet.IPv4;
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070038import net.onrc.onos.core.topology.Host;
Jonathan Harte37e4e22014-05-13 19:12:02 -070039import net.onrc.onos.core.topology.ITopologyService;
40import net.onrc.onos.core.topology.Topology;
TeruU8b2d1672014-04-25 17:02:56 -070041import net.onrc.onos.core.topology.Port;
42import net.onrc.onos.core.topology.Switch;
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070043import net.onrc.onos.core.util.Dpid;
44import net.onrc.onos.core.util.PortNumber;
TeruU8b2d1672014-04-25 17:02:56 -070045
46import org.easymock.EasyMock;
47import org.junit.After;
48import org.junit.Before;
49import org.junit.Test;
TeruU8b2d1672014-04-25 17:02:56 -070050
Yuta HIGUCHI33a04972014-06-03 13:00:15 -070051// XXX Commented out as workaround for PowerMock + Hazelcast issue.
52//@RunWith(PowerMockRunner.class)
53//@PowerMockIgnore({ "net.onrc.onos.core.datastore.*", "com.hazelcast.*" })
54//@PrepareOnlyThisForTest({ ProxyArpManager.class })
Ray Milkeyff735142014-05-22 19:06:02 -070055@SuppressWarnings({ "rawtypes", "unchecked" })
TeruU8b2d1672014-04-25 17:02:56 -070056public class ProxyArpManagerTest {
Yuta HIGUCHI1a1b44f2014-06-18 10:56:42 -070057
58 static {
59 // configuration to quickly fall back to instance mode for faster test run
60 System.setProperty("net.onrc.onos.core.datastore.hazelcast.client.attemptLimit", "0");
61 }
62
TeruU8b2d1672014-04-25 17:02:56 -070063 String defaultStrAgingMsec = "60000";
64 String defaultStrCleanupMsec = "60000";
65
66 ProxyArpManager arpManager;
67 FloodlightModuleContext context;
68 IFloodlightProviderService floodligthProviderService;
69 IConfigInfoService configInfoService;
70 IRestApiService restApiService;
71 IDatagridService datagridService;
72 IFlowPusherService flowPusherService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070073 ITopologyService topologyService;
Jonathan Hart03102132014-07-01 23:22:04 -070074 IHostService hostService;
TeruU8b2d1672014-04-25 17:02:56 -070075 IPacketService packetService;
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070076 Map<String, String> configMap;
TeruU8b2d1672014-04-25 17:02:56 -070077
78 String srcStrMac, dstStrMac, cachedStrMac1, cachedStrMac2, srcStrIp, dstStrIp, cachedStrIp1, cachedStrIp2;
79 byte[] srcByteMac, dstByteMac;
80 MACAddress dstMac, srcMac, cachedMac1, cachedMac2;
81 InetAddress srcIp, dstIp, cachedIp1, cachedIp2;
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070082 Dpid sw1Dpid;
83 PortNumber sw1Inport, sw1Outport;
TeruU8b2d1672014-04-25 17:02:56 -070084 Short vlanId;
85 ARP arpRequest, arpReply, rarpRequest;
86 Ethernet ethArpRequest, ethArpReply, ethRarpRequest, ethArpOtherOp;
87
Jonathan Harte37e4e22014-05-13 19:12:02 -070088 Topology topology;
TeruU8b2d1672014-04-25 17:02:56 -070089 IEventChannel eg;
90 IEventChannelListener el;
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070091 Host host1;
TeruU8b2d1672014-04-25 17:02:56 -070092 Port inPort1, outPort1;
93 Switch sw1;
94 ArpCache arpCache;
95 List<String> arpCacheComparisonList;
96
97 @Before
98 public void setUp() throws Exception {
99 makeTestedObject();
100 makeMock();
101 prepareExpectForInit();
102 prepareExpectForStartUp();
103 prepareExpectForGeneral();
104 }
105
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700106 private void makeTestedObject() throws UnknownHostException {
TeruU8b2d1672014-04-25 17:02:56 -0700107 //Made tested values
108 srcStrMac = "00:00:00:00:00:01";
109 dstStrMac = "00:00:00:00:00:02";
110 cachedStrMac1 = "00:00:00:00:00:03";
111 cachedStrMac2 = "00:00:00:00:00:04";
112 srcStrIp = "192.168.0.1";
113 dstStrIp = "192.168.0.2";
114 cachedStrIp1 = "192.168.0.3";
115 cachedStrIp2 = "192.168.0.4";
116 srcByteMac = Ethernet.toMACAddress(srcStrMac);
117 dstByteMac = Ethernet.toMACAddress(dstStrMac);
118 dstMac = new MACAddress(dstByteMac);
119 srcMac = new MACAddress(srcByteMac);
120 cachedMac1 = new MACAddress(Ethernet.toMACAddress(cachedStrMac1));
121 cachedMac2 = new MACAddress(Ethernet.toMACAddress(cachedStrMac2));
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700122
123 srcIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(srcStrIp));
124 dstIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(dstStrIp));
125 cachedIp1 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp1));
126 cachedIp2 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp2));
127
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -0700128 sw1Dpid = new Dpid(1L);
129 sw1Inport = new PortNumber((short) 1);
130 sw1Outport = new PortNumber((short) 2);
TeruU8b2d1672014-04-25 17:02:56 -0700131 vlanId = 1;
132
133 //Made tested packets
134 arpRequest = new ARP()
135 .setHardwareType(ARP.HW_TYPE_ETHERNET)
136 .setProtocolType(ARP.PROTO_TYPE_IP)
137 .setHardwareAddressLength((byte) 6)
138 .setProtocolAddressLength((byte) 4)
139 .setOpCode(ARP.OP_REQUEST)
140 .setSenderHardwareAddress(srcByteMac)
141 .setSenderProtocolAddress(srcIp.getAddress())
142 .setTargetProtocolAddress(dstIp.getAddress())
143 .setTargetHardwareAddress(dstByteMac);
144
145 ethArpRequest = (Ethernet) new Ethernet()
146 .setSourceMACAddress(srcStrMac)
147 .setDestinationMACAddress(dstStrMac)
148 .setEtherType(Ethernet.TYPE_ARP)
149 .setVlanID((short) 0)
150 .setPayload(arpRequest);
151
152 arpReply = new ARP()
153 .setHardwareType(ARP.HW_TYPE_ETHERNET)
154 .setProtocolType(ARP.PROTO_TYPE_IP)
155 .setHardwareAddressLength((byte) 6)
156 .setProtocolAddressLength((byte) 4)
157 .setOpCode(ARP.OP_RARP_REPLY)
158 .setSenderHardwareAddress(srcByteMac)
159 .setSenderProtocolAddress(srcIp.getAddress())
160 .setTargetProtocolAddress(dstIp.getAddress())
161 .setTargetHardwareAddress(dstByteMac);
162
163 ethArpReply = (Ethernet) new Ethernet()
164 .setSourceMACAddress(srcStrMac)
165 .setDestinationMACAddress(dstStrMac)
166 .setEtherType(Ethernet.TYPE_ARP)
167 .setVlanID((short) 0)
168 .setPayload(arpReply);
169
170 rarpRequest = new ARP()
171 .setHardwareType(ARP.HW_TYPE_ETHERNET)
172 .setProtocolType(ARP.PROTO_TYPE_IP)
173 .setHardwareAddressLength((byte) 6)
174 .setProtocolAddressLength((byte) 4)
175 .setOpCode(ARP.OP_RARP_REQUEST)
176 .setSenderHardwareAddress(srcByteMac)
177 .setSenderProtocolAddress(srcIp.getAddress())
178 .setTargetProtocolAddress(dstIp.getAddress())
179 .setTargetHardwareAddress(dstByteMac);
180
181 ethRarpRequest = (Ethernet) new Ethernet()
182 .setSourceMACAddress(srcStrMac)
183 .setDestinationMACAddress(dstStrMac)
184 .setEtherType(Ethernet.TYPE_RARP)
185 .setVlanID((short) 0)
186 .setPayload(rarpRequest);
187
188 ethArpOtherOp = (Ethernet) new Ethernet()
189 .setSourceMACAddress(srcStrMac)
190 .setDestinationMACAddress(dstStrMac)
191 .setEtherType(Ethernet.TYPE_ARP)
192 .setVlanID((short) 0)
193 .setPayload(rarpRequest);
194
195 //Made tested objects
196 arpCache = new ArpCache();
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -0700197 arpCache.setArpEntryTimeoutConfig(Long.parseLong(defaultStrCleanupMsec));
TeruU8b2d1672014-04-25 17:02:56 -0700198 arpCache.update(cachedIp1, cachedMac1);
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -0700199 arpCache.update(cachedIp2, cachedMac2);
200
201 arpCacheComparisonList = new ArrayList<String>();
TeruU8b2d1672014-04-25 17:02:56 -0700202 arpCacheComparisonList.add(cachedStrIp1
203 + " => "
204 + cachedStrMac1
205 + " : VALID");
TeruU8b2d1672014-04-25 17:02:56 -0700206 arpCacheComparisonList.add(cachedStrIp2
207 + " => "
208 + cachedStrMac2
209 + " : VALID");
210
211 arpManager = new ProxyArpManager();
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700212 configMap = new HashMap<String, String>();
TeruU8b2d1672014-04-25 17:02:56 -0700213 }
214
215 private void makeMock() {
216 //Mock floodlight modules
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700217 context = createMock(FloodlightModuleContext.class);
218 floodligthProviderService = createMock(IFloodlightProviderService.class);
219 configInfoService = createMock(IConfigInfoService.class);
220 restApiService = createMock(IRestApiService.class);
221 datagridService = createMock(IDatagridService.class);
222 flowPusherService = createMock(IFlowPusherService.class);
223 topologyService = createMock(ITopologyService.class);
224 hostService = createMock(IHostService.class);
225 packetService = createMock(IPacketService.class);
226 eg = createMock(IEventChannel.class);
227 el = createMock(IEventChannelListener.class);
TeruU8b2d1672014-04-25 17:02:56 -0700228
Jonathan Harte37e4e22014-05-13 19:12:02 -0700229 //Mock Topology related data
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700230 topology = createMock(Topology.class);
231 host1 = createMock(Host.class);
232 inPort1 = createMock(Port.class);
233 outPort1 = createMock(Port.class);
234 sw1 = createMock(Switch.class);
TeruU8b2d1672014-04-25 17:02:56 -0700235 }
236
237 private void prepareExpectForGeneral() {
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700238 expect(inPort1.getNumber()).andReturn(sw1Inport).anyTimes();
239 expect(outPort1.getNumber()).andReturn(sw1Outport).anyTimes();
240 expect(outPort1.getOutgoingLink()).andReturn(null).anyTimes();
241 expect(outPort1.getIncomingLink()).andReturn(null).anyTimes();
242 expect(outPort1.getSwitch()).andReturn(sw1).anyTimes();
243 expect(sw1.getDpid()).andReturn(sw1Dpid).anyTimes();
TeruU8b2d1672014-04-25 17:02:56 -0700244 }
245
246 private void prepareExpectForInit() {
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700247 expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodligthProviderService);
248 expect(context.getServiceImpl(IConfigInfoService.class)).andReturn(configInfoService);
249 expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApiService);
250 expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
251 expect(context.getServiceImpl(IFlowPusherService.class)).andReturn(flowPusherService);
252 expect(context.getServiceImpl(ITopologyService.class)).andReturn(topologyService);
253 expect(context.getServiceImpl(IHostService.class)).andReturn(hostService);
254 expect(context.getServiceImpl(IPacketService.class)).andReturn(packetService);
TeruU8b2d1672014-04-25 17:02:56 -0700255 }
256
257 private void prepareExpectForStartUp() {
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700258 // XXX Commented out as workaround for PowerMock + Hazelcast issue.
259// try {
260// PowerMock.expectNew(ArpCache.class).andReturn(arpCache);
261// } catch (Exception e) {
262// fail("Exception:" + e.getMessage());
263// }
264// PowerMock.replayAll();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700265 expect(configInfoService.getVlan()).andReturn(vlanId);
266 restApiService.addRestletRoutable(isA(ArpWebRoutable.class));
267 expectLastCall();
TeruU8b2d1672014-04-25 17:02:56 -0700268 packetService.registerPacketListener(arpManager);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700269 expectLastCall();
270 expect(topologyService.getTopology()).andReturn(topology);
271 expect(datagridService.addListener(EasyMock.<String>anyObject(),
272 isA(IEventChannelListener.class),
273 (Class) anyObject(), (Class) anyObject())).andReturn(eg).anyTimes();
TeruU8b2d1672014-04-25 17:02:56 -0700274 List<ArpCacheNotification> list = new ArrayList<ArpCacheNotification>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700275 expect(eg.getAllEntries()).andReturn(list);
TeruU8b2d1672014-04-25 17:02:56 -0700276 }
277
278 private void prepareExpectForLearnArp() {
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700279 eg.addEntry(eq(srcIp.toString()), isA(ArpCacheNotification.class));
280 expectLastCall();
TeruU8b2d1672014-04-25 17:02:56 -0700281 }
282
283 @After
284 public void tearDown() throws Exception {
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -0700285 arpCache = null;
TeruU8b2d1672014-04-25 17:02:56 -0700286 }
287
288 @Test
289 public void testConfigTimeWithNoConfig() {
290 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700291 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700292
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700293 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700294 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700295 topologyService, hostService, packetService, topology, eg,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700296 el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700297 arpManager.init(context);
298 arpManager.startUp(context);
299 assertEquals(defaultStrAgingMsec, String.valueOf(arpManager.getArpEntryTimeout()));
300 assertEquals(defaultStrCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod()));
301 }
302
303 @Test
304 public void testConfigTimeWithWrongParameter() {
305 Map<String, String> config = new HashMap<String, String>();
306 String strAgingMsec = "aaaaa";
307 String strCleanupMsec = "bbbbb";
308 config.put("agingmsec", strAgingMsec);
309 config.put("cleanupmsec", strCleanupMsec);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700310 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700311
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700312 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700313 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700314 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700315 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700316 arpManager.init(context);
317 arpManager.startUp(context);
318 assertEquals(defaultStrAgingMsec, String.valueOf(arpManager.getArpEntryTimeout()));
319 assertEquals(defaultStrCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod()));
320 }
321
322 @Test
323 public void testConfigTime() {
324 String strAgingMsec = "10000";
325 String strCleanupMsec = "10000";
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700326 configMap.put("agingmsec", strAgingMsec);
327 configMap.put("cleanupmsec", strCleanupMsec);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700328 expect(context.getConfigParams(arpManager)).andReturn(configMap);
TeruU8b2d1672014-04-25 17:02:56 -0700329
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700330 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700331 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700332 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700333 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700334 arpManager.init(context);
335 arpManager.startUp(context);
336 assertEquals(strAgingMsec, String.valueOf(arpManager.getArpEntryTimeout()));
337 assertEquals(strCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod()));
338 }
339
340 @Test
341 public void testGetMacAddress() {
342 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700343 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700344
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700345 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700346 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700347 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700348 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700349 arpManager.init(context);
350 arpManager.startUp(context);
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700351
352 // XXX workaround for PowerMock + Hazelcast issue.
353 this.arpManager.debugReplaceArpCache(arpCache);
354
TeruU8b2d1672014-04-25 17:02:56 -0700355 MACAddress mac = arpManager.getMacAddress(cachedIp1);
356 assertEquals(cachedMac1, mac);
357 }
358
359 @Test
360 public void testGetMappings() {
361 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700362 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700363
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700364 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700365 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700366 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700367 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700368 arpManager.init(context);
369 arpManager.startUp(context);
370 List<String> list = arpManager.getMappings();
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700371 for (String str : list) {
TeruU8b2d1672014-04-25 17:02:56 -0700372 assertTrue(arpCacheComparisonList.contains(str));
373 }
374 }
375
376 @Test
377 public void testReceivePacketWithNoArpPacket() {
378 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700379 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700380
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700381 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700382 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700383 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700384 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700385 arpManager.init(context);
386 arpManager.startUp(context);
387 arpManager.receive(sw1, inPort1, ethRarpRequest);
388 }
389
390 @Test
391 public void testReceivePacketWithOtherOpCode() {
392 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700393 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700394
395 prepareExpectForLearnArp();
396
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700397 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700398 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700399 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700400 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700401 arpManager.init(context);
402 arpManager.startUp(context);
403 arpManager.receive(sw1, inPort1, ethArpOtherOp);
404 }
405
406 @Test
407 public void testClassifyPacketToSendArpReplyNotification() {
408 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700409 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700410
411 prepareExpectForLearnArp();
412
413 ArpReplyNotification value =
414 new ArpReplyNotification(ByteBuffer.wrap(dstIp.getAddress()).getInt(), dstMac);
415 eg.addTransientEntry(srcMac.toLong(), value);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700416 expectLastCall();
417 expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
TeruU8b2d1672014-04-25 17:02:56 -0700418
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700419 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700420 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700421 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700422 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700423 arpManager.init(context);
424 arpManager.startUp(context);
425 arpManager.receive(sw1, inPort1, ethArpReply);
426 }
427
428 @Test
429 public void testClassifyPacketToHandleArpRequest() {
430 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700431 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700432
433 prepareExpectForLearnArp();
434
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700435 expect(configInfoService.fromExternalNetwork(anyLong(), anyShort())).andReturn(true);
436 expect(configInfoService.isInterfaceAddress(dstIp)).andReturn(false);
TeruU8b2d1672014-04-25 17:02:56 -0700437
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700438 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700439 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700440 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700441 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700442 arpManager.init(context);
443 arpManager.startUp(context);
444 arpManager.receive(sw1, inPort1, ethArpRequest);
445 }
446
447 @Test
448 public void testClassifyPacketToHandleArpRequest2() {
449 List<Port> portList = new ArrayList<Port>();
450 portList.add(outPort1);
451
452 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700453 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700454
455 prepareExpectForLearnArp();
456
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700457 expect(configInfoService.fromExternalNetwork(
458 anyLong(), anyShort())).andReturn(false);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700459 topology.acquireReadLock();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700460 expectLastCall();
461 expect(topology.getHostByMac(dstMac)).andReturn(host1);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700462 topology.releaseReadLock();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700463 expectLastCall();
464 expect(host1.getAttachmentPoints()).andReturn(portList);
465 eg.addTransientEntry(anyLong(), anyObject());
466 expectLastCall();
TeruU8b2d1672014-04-25 17:02:56 -0700467
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700468 replay(context, configInfoService, restApiService, floodligthProviderService,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700469 topologyService, datagridService, eg, topology, host1, inPort1, outPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700470 arpManager.init(context);
471 arpManager.startUp(context);
472 arpManager.receive(sw1, inPort1, ethArpRequest);
473 }
474}