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