2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.l2switch.arphandler.core;
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Mockito.times;
12 import static org.mockito.Mockito.verify;
14 import java.util.ArrayList;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.MockitoAnnotations;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.arp.rev140528.ArpPacketReceived;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.arp.rev140528.ArpPacketReceivedBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.arp.rev140528.arp.packet.received.packet.chain.packet.ArpPacketBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.basepacket.rev140528.packet.chain.grp.PacketChain;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.basepacket.rev140528.packet.chain.grp.PacketChainBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.basepacket.rev140528.packet.chain.grp.packet.chain.packet.RawPacketBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.ethernet.rev140528.ethernet.packet.received.packet.chain.packet.EthernetPacketBuilder;
28 public class ArpPacketHandlerTest {
30 @MockitoAnnotations.Mock
31 private PacketDispatcher packetDispatcher;
32 private ArpPacketHandler arpPacketHandler;
35 public void initMocks() {
36 MockitoAnnotations.initMocks(this);
37 arpPacketHandler = new ArpPacketHandler(packetDispatcher);
41 public void onArpPacketReceivedTest() throws Exception {
42 ArrayList<PacketChain> packetChainList = new ArrayList<PacketChain>();
43 packetChainList.add(new PacketChainBuilder().setPacket(new RawPacketBuilder().build()).build());
44 packetChainList.add(new PacketChainBuilder().setPacket(new EthernetPacketBuilder().build()).build());
45 packetChainList.add(new PacketChainBuilder().setPacket(new ArpPacketBuilder().build()).build());
46 ArpPacketReceived arpReceived = new ArpPacketReceivedBuilder().setPacketChain(packetChainList).build();
47 arpPacketHandler.onArpPacketReceived(arpReceived);
49 verify(packetDispatcher, times(1)).dispatchPacket(any(byte[].class), any(NodeConnectorRef.class),
50 any(MacAddress.class), any(MacAddress.class));
54 public void onArpPacketReceivedTest_NullInput() throws Exception {
55 arpPacketHandler.onArpPacketReceived(null);
56 verify(packetDispatcher, times(0)).dispatchPacket(any(byte[].class), any(NodeConnectorRef.class),
57 any(MacAddress.class), any(MacAddress.class));
61 public void onArpPacketReceivedTest_NullPacketChain() throws Exception {
62 ArpPacketReceived arpReceived = new ArpPacketReceivedBuilder().build();
63 arpPacketHandler.onArpPacketReceived(arpReceived);
64 verify(packetDispatcher, times(0)).dispatchPacket(any(byte[].class), any(NodeConnectorRef.class),
65 any(MacAddress.class), any(MacAddress.class));
69 public void onArpPacketReceivedTest_EmptyPacketChain() throws Exception {
70 ArrayList<PacketChain> packetChainList = new ArrayList<PacketChain>();
71 ArpPacketReceived arpReceived = new ArpPacketReceivedBuilder().setPacketChain(packetChainList).build();
72 arpPacketHandler.onArpPacketReceived(arpReceived);
73 verify(packetDispatcher, times(0)).dispatchPacket(any(byte[].class), any(NodeConnectorRef.class),
74 any(MacAddress.class), any(MacAddress.class));
78 public void onArpPacketReceivedTest_NoRawPacket() throws Exception {
79 ArrayList<PacketChain> packetChainList = new ArrayList<PacketChain>();
80 packetChainList.add(new PacketChainBuilder().setPacket(new EthernetPacketBuilder().build()).build());
81 packetChainList.add(new PacketChainBuilder().setPacket(new ArpPacketBuilder().build()).build());
82 ArpPacketReceived arpReceived = new ArpPacketReceivedBuilder().setPacketChain(packetChainList).build();
83 arpPacketHandler.onArpPacketReceived(arpReceived);
85 verify(packetDispatcher, times(0)).dispatchPacket(any(byte[].class), any(NodeConnectorRef.class),
86 any(MacAddress.class), any(MacAddress.class));
90 public void onArpPacketReceivedTest_NoEthernetPacket() throws Exception {
91 ArrayList<PacketChain> packetChainList = new ArrayList<PacketChain>();
92 packetChainList.add(new PacketChainBuilder().setPacket(new RawPacketBuilder().build()).build());
93 packetChainList.add(new PacketChainBuilder().setPacket(new ArpPacketBuilder().build()).build());
94 ArpPacketReceived arpReceived = new ArpPacketReceivedBuilder().setPacketChain(packetChainList).build();
95 arpPacketHandler.onArpPacketReceived(arpReceived);
97 verify(packetDispatcher, times(0)).dispatchPacket(any(byte[].class), any(NodeConnectorRef.class),
98 any(MacAddress.class), any(MacAddress.class));
102 public void onArpPacketReceivedTest_NoArpPacket() throws Exception {
103 ArrayList<PacketChain> packetChainList = new ArrayList<PacketChain>();
104 packetChainList.add(new PacketChainBuilder().setPacket(new RawPacketBuilder().build()).build());
105 packetChainList.add(new PacketChainBuilder().setPacket(new EthernetPacketBuilder().build()).build());
106 ArpPacketReceived arpReceived = new ArpPacketReceivedBuilder().setPacketChain(packetChainList).build();
107 arpPacketHandler.onArpPacketReceived(arpReceived);
109 verify(packetDispatcher, times(0)).dispatchPacket(any(byte[].class), any(NodeConnectorRef.class),
110 any(MacAddress.class), any(MacAddress.class));