blob: c6a62d5e24afa888cf22d9fa8091203966171d2c [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;
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070040import net.onrc.onos.core.topology.MutableTopology;
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
TeruU8b2d1672014-04-25 17:02:56 -070058 String defaultStrAgingMsec = "60000";
59 String defaultStrCleanupMsec = "60000";
60
61 ProxyArpManager arpManager;
62 FloodlightModuleContext context;
63 IFloodlightProviderService floodligthProviderService;
64 IConfigInfoService configInfoService;
65 IRestApiService restApiService;
66 IDatagridService datagridService;
67 IFlowPusherService flowPusherService;
Jonathan Harte37e4e22014-05-13 19:12:02 -070068 ITopologyService topologyService;
Jonathan Hart03102132014-07-01 23:22:04 -070069 IHostService hostService;
TeruU8b2d1672014-04-25 17:02:56 -070070 IPacketService packetService;
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070071 Map<String, String> configMap;
TeruU8b2d1672014-04-25 17:02:56 -070072
73 String srcStrMac, dstStrMac, cachedStrMac1, cachedStrMac2, srcStrIp, dstStrIp, cachedStrIp1, cachedStrIp2;
74 byte[] srcByteMac, dstByteMac;
75 MACAddress dstMac, srcMac, cachedMac1, cachedMac2;
76 InetAddress srcIp, dstIp, cachedIp1, cachedIp2;
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070077 Dpid sw1Dpid;
78 PortNumber sw1Inport, sw1Outport;
TeruU8b2d1672014-04-25 17:02:56 -070079 Short vlanId;
80 ARP arpRequest, arpReply, rarpRequest;
81 Ethernet ethArpRequest, ethArpReply, ethRarpRequest, ethArpOtherOp;
82
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -070083 MutableTopology mutableTopology;
TeruU8b2d1672014-04-25 17:02:56 -070084 IEventChannel eg;
85 IEventChannelListener el;
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070086 Host host1;
TeruU8b2d1672014-04-25 17:02:56 -070087 Port inPort1, outPort1;
88 Switch sw1;
89 ArpCache arpCache;
90 List<String> arpCacheComparisonList;
91
92 @Before
93 public void setUp() throws Exception {
94 makeTestedObject();
95 makeMock();
96 prepareExpectForInit();
97 prepareExpectForStartUp();
98 prepareExpectForGeneral();
99 }
100
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700101 private void makeTestedObject() throws UnknownHostException {
TeruU8b2d1672014-04-25 17:02:56 -0700102 //Made tested values
103 srcStrMac = "00:00:00:00:00:01";
104 dstStrMac = "00:00:00:00:00:02";
105 cachedStrMac1 = "00:00:00:00:00:03";
106 cachedStrMac2 = "00:00:00:00:00:04";
107 srcStrIp = "192.168.0.1";
108 dstStrIp = "192.168.0.2";
109 cachedStrIp1 = "192.168.0.3";
110 cachedStrIp2 = "192.168.0.4";
111 srcByteMac = Ethernet.toMACAddress(srcStrMac);
112 dstByteMac = Ethernet.toMACAddress(dstStrMac);
113 dstMac = new MACAddress(dstByteMac);
114 srcMac = new MACAddress(srcByteMac);
115 cachedMac1 = new MACAddress(Ethernet.toMACAddress(cachedStrMac1));
116 cachedMac2 = new MACAddress(Ethernet.toMACAddress(cachedStrMac2));
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700117
118 srcIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(srcStrIp));
119 dstIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(dstStrIp));
120 cachedIp1 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp1));
121 cachedIp2 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp2));
122
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -0700123 sw1Dpid = new Dpid(1L);
Yuta HIGUCHIa507baf2014-08-22 13:42:40 -0700124 sw1Inport = PortNumber.uint16((short) 1);
125 sw1Outport = PortNumber.uint16((short) 2);
TeruU8b2d1672014-04-25 17:02:56 -0700126 vlanId = 1;
127
128 //Made tested packets
129 arpRequest = new ARP()
130 .setHardwareType(ARP.HW_TYPE_ETHERNET)
131 .setProtocolType(ARP.PROTO_TYPE_IP)
132 .setHardwareAddressLength((byte) 6)
133 .setProtocolAddressLength((byte) 4)
134 .setOpCode(ARP.OP_REQUEST)
135 .setSenderHardwareAddress(srcByteMac)
136 .setSenderProtocolAddress(srcIp.getAddress())
137 .setTargetProtocolAddress(dstIp.getAddress())
138 .setTargetHardwareAddress(dstByteMac);
139
140 ethArpRequest = (Ethernet) new Ethernet()
141 .setSourceMACAddress(srcStrMac)
142 .setDestinationMACAddress(dstStrMac)
143 .setEtherType(Ethernet.TYPE_ARP)
144 .setVlanID((short) 0)
145 .setPayload(arpRequest);
146
147 arpReply = new ARP()
148 .setHardwareType(ARP.HW_TYPE_ETHERNET)
149 .setProtocolType(ARP.PROTO_TYPE_IP)
150 .setHardwareAddressLength((byte) 6)
151 .setProtocolAddressLength((byte) 4)
152 .setOpCode(ARP.OP_RARP_REPLY)
153 .setSenderHardwareAddress(srcByteMac)
154 .setSenderProtocolAddress(srcIp.getAddress())
155 .setTargetProtocolAddress(dstIp.getAddress())
156 .setTargetHardwareAddress(dstByteMac);
157
158 ethArpReply = (Ethernet) new Ethernet()
159 .setSourceMACAddress(srcStrMac)
160 .setDestinationMACAddress(dstStrMac)
161 .setEtherType(Ethernet.TYPE_ARP)
162 .setVlanID((short) 0)
163 .setPayload(arpReply);
164
165 rarpRequest = new ARP()
166 .setHardwareType(ARP.HW_TYPE_ETHERNET)
167 .setProtocolType(ARP.PROTO_TYPE_IP)
168 .setHardwareAddressLength((byte) 6)
169 .setProtocolAddressLength((byte) 4)
170 .setOpCode(ARP.OP_RARP_REQUEST)
171 .setSenderHardwareAddress(srcByteMac)
172 .setSenderProtocolAddress(srcIp.getAddress())
173 .setTargetProtocolAddress(dstIp.getAddress())
174 .setTargetHardwareAddress(dstByteMac);
175
176 ethRarpRequest = (Ethernet) new Ethernet()
177 .setSourceMACAddress(srcStrMac)
178 .setDestinationMACAddress(dstStrMac)
179 .setEtherType(Ethernet.TYPE_RARP)
180 .setVlanID((short) 0)
181 .setPayload(rarpRequest);
182
183 ethArpOtherOp = (Ethernet) new Ethernet()
184 .setSourceMACAddress(srcStrMac)
185 .setDestinationMACAddress(dstStrMac)
186 .setEtherType(Ethernet.TYPE_ARP)
187 .setVlanID((short) 0)
188 .setPayload(rarpRequest);
189
190 //Made tested objects
191 arpCache = new ArpCache();
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -0700192 arpCache.setArpEntryTimeoutConfig(Long.parseLong(defaultStrCleanupMsec));
TeruU8b2d1672014-04-25 17:02:56 -0700193 arpCache.update(cachedIp1, cachedMac1);
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -0700194 arpCache.update(cachedIp2, cachedMac2);
195
196 arpCacheComparisonList = new ArrayList<String>();
TeruU8b2d1672014-04-25 17:02:56 -0700197 arpCacheComparisonList.add(cachedStrIp1
198 + " => "
199 + cachedStrMac1
200 + " : VALID");
TeruU8b2d1672014-04-25 17:02:56 -0700201 arpCacheComparisonList.add(cachedStrIp2
202 + " => "
203 + cachedStrMac2
204 + " : VALID");
205
206 arpManager = new ProxyArpManager();
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700207 configMap = new HashMap<String, String>();
TeruU8b2d1672014-04-25 17:02:56 -0700208 }
209
210 private void makeMock() {
211 //Mock floodlight modules
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700212 context = createMock(FloodlightModuleContext.class);
213 floodligthProviderService = createMock(IFloodlightProviderService.class);
214 configInfoService = createMock(IConfigInfoService.class);
215 restApiService = createMock(IRestApiService.class);
216 datagridService = createMock(IDatagridService.class);
217 flowPusherService = createMock(IFlowPusherService.class);
218 topologyService = createMock(ITopologyService.class);
219 hostService = createMock(IHostService.class);
220 packetService = createMock(IPacketService.class);
221 eg = createMock(IEventChannel.class);
222 el = createMock(IEventChannelListener.class);
TeruU8b2d1672014-04-25 17:02:56 -0700223
Jonathan Harte37e4e22014-05-13 19:12:02 -0700224 //Mock Topology related data
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700225 mutableTopology = createMock(MutableTopology.class);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700226 host1 = createMock(Host.class);
227 inPort1 = createMock(Port.class);
228 outPort1 = createMock(Port.class);
229 sw1 = createMock(Switch.class);
TeruU8b2d1672014-04-25 17:02:56 -0700230 }
231
232 private void prepareExpectForGeneral() {
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700233 expect(inPort1.getNumber()).andReturn(sw1Inport).anyTimes();
234 expect(outPort1.getNumber()).andReturn(sw1Outport).anyTimes();
235 expect(outPort1.getOutgoingLink()).andReturn(null).anyTimes();
236 expect(outPort1.getIncomingLink()).andReturn(null).anyTimes();
237 expect(outPort1.getSwitch()).andReturn(sw1).anyTimes();
238 expect(sw1.getDpid()).andReturn(sw1Dpid).anyTimes();
TeruU8b2d1672014-04-25 17:02:56 -0700239 }
240
241 private void prepareExpectForInit() {
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700242 expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodligthProviderService);
243 expect(context.getServiceImpl(IConfigInfoService.class)).andReturn(configInfoService);
244 expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApiService);
245 expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
246 expect(context.getServiceImpl(IFlowPusherService.class)).andReturn(flowPusherService);
247 expect(context.getServiceImpl(ITopologyService.class)).andReturn(topologyService);
248 expect(context.getServiceImpl(IHostService.class)).andReturn(hostService);
249 expect(context.getServiceImpl(IPacketService.class)).andReturn(packetService);
TeruU8b2d1672014-04-25 17:02:56 -0700250 }
251
252 private void prepareExpectForStartUp() {
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700253 // XXX Commented out as workaround for PowerMock + Hazelcast issue.
254// try {
255// PowerMock.expectNew(ArpCache.class).andReturn(arpCache);
256// } catch (Exception e) {
257// fail("Exception:" + e.getMessage());
258// }
259// PowerMock.replayAll();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700260 expect(configInfoService.getVlan()).andReturn(vlanId);
261 restApiService.addRestletRoutable(isA(ArpWebRoutable.class));
262 expectLastCall();
TeruU8b2d1672014-04-25 17:02:56 -0700263 packetService.registerPacketListener(arpManager);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700264 expectLastCall();
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700265 expect(topologyService.getTopology()).andReturn(mutableTopology);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700266 expect(datagridService.addListener(EasyMock.<String>anyObject(),
267 isA(IEventChannelListener.class),
268 (Class) anyObject(), (Class) anyObject())).andReturn(eg).anyTimes();
TeruU8b2d1672014-04-25 17:02:56 -0700269 List<ArpCacheNotification> list = new ArrayList<ArpCacheNotification>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700270 expect(eg.getAllEntries()).andReturn(list);
TeruU8b2d1672014-04-25 17:02:56 -0700271 }
272
273 private void prepareExpectForLearnArp() {
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700274 eg.addEntry(eq(srcIp.toString()), isA(ArpCacheNotification.class));
275 expectLastCall();
TeruU8b2d1672014-04-25 17:02:56 -0700276 }
277
278 @After
279 public void tearDown() throws Exception {
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -0700280 arpCache = null;
TeruU8b2d1672014-04-25 17:02:56 -0700281 }
282
283 @Test
284 public void testConfigTimeWithNoConfig() {
285 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700286 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700287
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700288 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700289 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700290 topologyService, hostService, packetService, mutableTopology, eg,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700291 el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700292 arpManager.init(context);
293 arpManager.startUp(context);
294 assertEquals(defaultStrAgingMsec, String.valueOf(arpManager.getArpEntryTimeout()));
295 assertEquals(defaultStrCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod()));
296 }
297
298 @Test
299 public void testConfigTimeWithWrongParameter() {
300 Map<String, String> config = new HashMap<String, String>();
301 String strAgingMsec = "aaaaa";
302 String strCleanupMsec = "bbbbb";
303 config.put("agingmsec", strAgingMsec);
304 config.put("cleanupmsec", strCleanupMsec);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700305 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700306
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700307 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700308 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700309 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700310 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700311 arpManager.init(context);
312 arpManager.startUp(context);
313 assertEquals(defaultStrAgingMsec, String.valueOf(arpManager.getArpEntryTimeout()));
314 assertEquals(defaultStrCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod()));
315 }
316
317 @Test
318 public void testConfigTime() {
319 String strAgingMsec = "10000";
320 String strCleanupMsec = "10000";
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700321 configMap.put("agingmsec", strAgingMsec);
322 configMap.put("cleanupmsec", strCleanupMsec);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700323 expect(context.getConfigParams(arpManager)).andReturn(configMap);
TeruU8b2d1672014-04-25 17:02:56 -0700324
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700325 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700326 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700327 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700328 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700329 arpManager.init(context);
330 arpManager.startUp(context);
331 assertEquals(strAgingMsec, String.valueOf(arpManager.getArpEntryTimeout()));
332 assertEquals(strCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod()));
333 }
334
335 @Test
336 public void testGetMacAddress() {
337 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700338 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700339
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700340 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700341 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700342 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700343 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700344 arpManager.init(context);
345 arpManager.startUp(context);
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700346
347 // XXX workaround for PowerMock + Hazelcast issue.
348 this.arpManager.debugReplaceArpCache(arpCache);
349
TeruU8b2d1672014-04-25 17:02:56 -0700350 MACAddress mac = arpManager.getMacAddress(cachedIp1);
351 assertEquals(cachedMac1, mac);
352 }
353
354 @Test
355 public void testGetMappings() {
356 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700357 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700358
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700359 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700360 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700361 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700362 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700363 arpManager.init(context);
364 arpManager.startUp(context);
365 List<String> list = arpManager.getMappings();
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700366 for (String str : list) {
TeruU8b2d1672014-04-25 17:02:56 -0700367 assertTrue(arpCacheComparisonList.contains(str));
368 }
369 }
370
371 @Test
372 public void testReceivePacketWithNoArpPacket() {
373 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700374 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700375
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700376 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700377 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700378 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700379 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700380 arpManager.init(context);
381 arpManager.startUp(context);
382 arpManager.receive(sw1, inPort1, ethRarpRequest);
383 }
384
385 @Test
386 public void testReceivePacketWithOtherOpCode() {
387 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700388 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700389
390 prepareExpectForLearnArp();
391
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700392 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700393 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700394 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700395 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700396 arpManager.init(context);
397 arpManager.startUp(context);
398 arpManager.receive(sw1, inPort1, ethArpOtherOp);
399 }
400
401 @Test
402 public void testClassifyPacketToSendArpReplyNotification() {
403 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700404 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700405
406 prepareExpectForLearnArp();
407
408 ArpReplyNotification value =
409 new ArpReplyNotification(ByteBuffer.wrap(dstIp.getAddress()).getInt(), dstMac);
410 eg.addTransientEntry(srcMac.toLong(), value);
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700411 expectLastCall();
412 expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
TeruU8b2d1672014-04-25 17:02:56 -0700413
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700414 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700415 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700416 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700417 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700418 arpManager.init(context);
419 arpManager.startUp(context);
420 arpManager.receive(sw1, inPort1, ethArpReply);
421 }
422
423 @Test
424 public void testClassifyPacketToHandleArpRequest() {
425 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700426 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700427
428 prepareExpectForLearnArp();
429
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700430 expect(configInfoService.fromExternalNetwork(anyLong(), anyShort())).andReturn(true);
431 expect(configInfoService.isInterfaceAddress(dstIp)).andReturn(false);
TeruU8b2d1672014-04-25 17:02:56 -0700432
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700433 replay(context, floodligthProviderService, configInfoService,
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700434 restApiService, datagridService, flowPusherService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700435 topologyService, hostService, packetService, mutableTopology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700436 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700437 arpManager.init(context);
438 arpManager.startUp(context);
439 arpManager.receive(sw1, inPort1, ethArpRequest);
440 }
441
442 @Test
443 public void testClassifyPacketToHandleArpRequest2() {
444 List<Port> portList = new ArrayList<Port>();
445 portList.add(outPort1);
446
447 Map<String, String> config = new HashMap<String, String>();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700448 expect(context.getConfigParams(arpManager)).andReturn(config);
TeruU8b2d1672014-04-25 17:02:56 -0700449
450 prepareExpectForLearnArp();
451
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700452 expect(configInfoService.fromExternalNetwork(
453 anyLong(), anyShort())).andReturn(false);
pingping-lin0426dee2014-08-27 15:03:17 -0700454
455 expect(configInfoService.inConnectedNetwork(
456 dstIp)).andReturn(false);
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700457 mutableTopology.acquireReadLock();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700458 expectLastCall();
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700459 expect(mutableTopology.getHostByMac(dstMac)).andReturn(host1);
460 mutableTopology.releaseReadLock();
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700461 expectLastCall();
462 expect(host1.getAttachmentPoints()).andReturn(portList);
463 eg.addTransientEntry(anyLong(), anyObject());
464 expectLastCall();
TeruU8b2d1672014-04-25 17:02:56 -0700465
Sho SHIMIZU107344e2014-08-13 16:11:53 -0700466 replay(context, configInfoService, restApiService, floodligthProviderService,
Yuta HIGUCHId92b10c2014-08-25 09:30:28 -0700467 topologyService, datagridService, eg, mutableTopology, host1, inPort1, outPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700468 arpManager.init(context);
469 arpManager.startUp(context);
pingping-lin0426dee2014-08-27 15:03:17 -0700470
TeruU8b2d1672014-04-25 17:02:56 -0700471 arpManager.receive(sw1, inPort1, ethArpRequest);
472 }
473}