Merge "Bug 7481 - Flows with nicira actions get corrupted after cluster failure"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / EthernetDestinationEntrySerializerTest.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.Match;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
22
23 public class EthernetDestinationEntrySerializerTest extends AbstractMatchEntrySerializerTest {
24     @Test
25     public void testSerialize() throws Exception {
26         final MacAddress address = new MacAddress("00:01:02:03:04:05");
27         final MacAddress mask = new MacAddress("00:00:00:00:00:00");
28
29         final Match match = new MatchBuilder()
30                 .setEthernetMatch(new EthernetMatchBuilder()
31                         .setEthernetDestination(new EthernetDestinationBuilder()
32                                 .setAddress(address)
33                                 .setMask(mask)
34                                 .build())
35                         .build())
36                 .build();
37
38         assertMatch(match, true, (out) -> {
39             final byte[] addressBytes = new byte[6];
40             out.readBytes(addressBytes);
41             assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
42
43             final byte[] maskBytes = new byte[6];
44             out.readBytes(maskBytes);
45             assertEquals(new MacAddress(ByteBufUtils.macAddressToString(maskBytes)).getValue(), mask.getValue());
46         });
47
48         final Match matchNoMask = new MatchBuilder()
49                 .setEthernetMatch(new EthernetMatchBuilder()
50                         .setEthernetDestination(new EthernetDestinationBuilder()
51                                 .setAddress(address)
52                                 .build())
53                         .build())
54                 .build();
55
56         assertMatch(matchNoMask, false, (out) -> {
57             final byte[] addressBytes = new byte[6];
58             out.readBytes(addressBytes);
59             assertEquals(new MacAddress(ByteBufUtils.macAddressToString(addressBytes)).getValue(), address.getValue());
60         });
61     }
62
63     @Override
64     protected short getLength() {
65         return EncodeConstants.MAC_ADDRESS_LENGTH;
66     }
67
68     @Override
69     protected int getOxmFieldCode() {
70         return OxmMatchConstants.ETH_DST;
71     }
72
73     @Override
74     protected int getOxmClassCode() {
75         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
76     }
77
78 }