Merge "Add NodeConfiguratorImpl enqueue trace"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / ArpSourceHardwareAddressEntrySerializerTest.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.openflowplugin.impl.protocol.serialization.match;
10
11 import static org.junit.Assert.assertEquals;
12
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
22
23 public class ArpSourceHardwareAddressEntrySerializerTest extends AbstractMatchEntrySerializerTest {
24
25     @Test
26     public void testSerialize() {
27         final MacAddress address = new MacAddress("00:01:02:03:04:05");
28         final MacAddress mask = new MacAddress("00:00:00:00:00:00");
29
30         final Match arpShaMatch = new MatchBuilder()
31                 .setLayer3Match(new ArpMatchBuilder()
32                         .setArpSourceHardwareAddress(new ArpSourceHardwareAddressBuilder()
33                                 .setAddress(address)
34                                 .setMask(mask)
35                                 .build())
36                         .build())
37                 .build();
38
39         assertMatch(arpShaMatch, true, (out) -> {
40             byte[] addressBytes = new byte[6];
41             out.readBytes(addressBytes);
42             assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
43
44             byte[] maskBytes = new byte[6];
45             out.readBytes(maskBytes);
46             assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
47         });
48
49         final Match arpShaMatchNoMask = new MatchBuilder()
50                 .setLayer3Match(new ArpMatchBuilder()
51                         .setArpSourceHardwareAddress(new ArpSourceHardwareAddressBuilder()
52                                 .setAddress(address)
53                                 .build())
54                         .build())
55                 .build();
56
57         assertMatch(arpShaMatchNoMask, false, (out) -> {
58             byte[] addressBytes = new byte[6];
59             out.readBytes(addressBytes);
60             assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
61         });
62     }
63
64     @Override
65     protected short getLength() {
66         return EncodeConstants.MAC_ADDRESS_LENGTH;
67     }
68
69     @Override
70     protected int getOxmFieldCode() {
71         return OxmMatchConstants.ARP_SHA;
72     }
73
74     @Override
75     protected int getOxmClassCode() {
76         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
77     }
78
79 }