UT: ofoverlay-arp
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / arp / ArpFlowFactoryTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.arp;
10
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.controller.liblldp.EtherTypes;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
21
22 public class ArpFlowFactoryTest {
23
24     @Test
25     public void createEthernetMatchWithAddressTest() {
26         MacAddress mac = new MacAddress("00:00:00:00:00:01");
27         EthernetMatch match = ArpFlowFactory.createEthernetMatch(mac);
28         Assert.assertEquals(mac, match.getEthernetDestination().getAddress());
29         Assert.assertNull(match.getEthernetSource());
30         Assert.assertEquals(Long.valueOf(EtherTypes.ARP.intValue()), match.getEthernetType().getType().getValue());
31     }
32
33     @Test
34     public void createEthernetMatchWithoutAddressTest() {
35         EthernetMatch match = ArpFlowFactory.createEthernetMatch();
36         Assert.assertEquals(Long.valueOf(EtherTypes.ARP.intValue()), match.getEthernetType().getType().getValue());
37         Assert.assertNull(match.getEthernetDestination());
38     }
39
40     @Test
41     public void createArpMatchTest() {
42         Ipv4Address senderAddress = new Ipv4Address("192.168.0.1");
43         Ipv4Address targetAddress = new Ipv4Address("192.168.0.2");
44         MacAddress targetMac = new MacAddress("00:00:00:00:00:01");
45         ArpMessageAddress target = new ArpMessageAddress(targetMac, targetAddress);
46         ArpMatch match = ArpFlowFactory.createArpMatch(target, senderAddress);
47         Assert.assertTrue(match.getArpTargetTransportAddress().getValue().contains(targetAddress.getValue()));
48         Assert.assertTrue(match.getArpSourceTransportAddress().getValue().contains(senderAddress.getValue()));
49         Assert.assertEquals(ArpOperation.REPLY.intValue(), match.getArpOp().intValue());
50     }
51
52     @Test
53     public void createSendToControllerActionTest() {
54         int order = 25;
55         Action action = ArpFlowFactory.createSendToControllerAction(order);
56         Assert.assertEquals(order, action.getOrder().intValue());
57         Assert.assertEquals(order, action.getKey().getOrder().intValue());
58         Assert.assertTrue(action.getAction() instanceof OutputActionCase);
59         OutputActionCase output = ((OutputActionCase) action.getAction());
60         Assert.assertEquals(OutputPortValues.CONTROLLER.toString(),
61                 output.getOutputAction().getOutputNodeConnector().getValue());
62     }
63 }