Merge "Remove CSS artifact remnants"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / VlanVidEntrySerializerTest.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.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
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.match.VlanMatchBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
22
23 public class VlanVidEntrySerializerTest extends AbstractMatchEntrySerializerTest {
24
25     @Test
26     public void testSerialize() throws Exception {
27         final int vlan = (short) 1;
28
29         final Match vlanMatch = new MatchBuilder()
30                 .setVlanMatch(new VlanMatchBuilder()
31                         .setVlanId(new VlanIdBuilder()
32                                 .setVlanId(new VlanId(vlan))
33                                 .setVlanIdPresent(true)
34                                 .build())
35                         .build())
36                 .build();
37
38         assertMatch(vlanMatch, false, (out) -> assertEquals(out.readShort(), vlan | (1 << 12)));
39
40         final Match vlanMatchMaskOnly = new MatchBuilder()
41                 .setVlanMatch(new VlanMatchBuilder()
42                         .setVlanId(new VlanIdBuilder()
43                                 .setVlanIdPresent(true)
44                                 .build())
45                         .build())
46                 .build();
47
48         assertMatch(vlanMatchMaskOnly, true, out -> {
49             assertEquals(out.readShort(), (1 << 12));
50
51             byte[] mask = new byte[2];
52             out.readBytes(mask);
53             assertArrayEquals(mask, new byte[] { 16, 0 });
54         });
55     }
56
57     @Override
58     protected short getLength() {
59         return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
60     }
61
62     @Override
63     protected int getOxmFieldCode() {
64         return OxmMatchConstants.VLAN_VID;
65     }
66
67     @Override
68     protected int getOxmClassCode() {
69         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
70     }
71
72 }