Merge remote-tracking branch 'liblldp/master'
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / PbbEntrySerializerTest.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.openflowplugin.openflow.md.util.ByteUtil;
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.match.ProtocolMatchFieldsBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.protocol.match.fields.PbbBuilder;
22
23 public class PbbEntrySerializerTest extends AbstractMatchEntrySerializerTest {
24
25     @Test
26     public void testSerialize() throws Exception {
27         final long pbbId = 6789;
28         final byte[] pbbIdMask = new byte[] { 0, 15, 10 };
29
30         final Match pbbMatch = new MatchBuilder()
31                 .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
32                         .setPbb(new PbbBuilder()
33                                 .setPbbIsid(pbbId)
34                                 .setPbbMask(ByteUtil.bytesToUnsignedMedium(pbbIdMask))
35                                 .build())
36                         .build())
37                 .build();
38
39         assertMatch(pbbMatch, true, (out) -> {
40             assertEquals(out.readUnsignedMedium(), pbbId);
41
42             final byte[] mask = new byte[3];
43             out.readBytes(mask);
44             assertArrayEquals(mask, pbbIdMask);
45         });
46
47         final Match pbbMatchNoMask = new MatchBuilder()
48                 .setProtocolMatchFields(new ProtocolMatchFieldsBuilder()
49                         .setPbb(new PbbBuilder()
50                                 .setPbbIsid(pbbId)
51                                 .build())
52                         .build())
53                 .build();
54
55         assertMatch(pbbMatchNoMask, false, (out) -> assertEquals(out.readUnsignedMedium(), pbbId));
56     }
57
58     @Override
59     protected short getLength() {
60         return EncodeConstants.SIZE_OF_3_BYTES;
61     }
62
63     @Override
64     protected int getOxmFieldCode() {
65         return OxmMatchConstants.PBB_ISID;
66     }
67
68     @Override
69     protected int getOxmClassCode() {
70         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
71     }
72
73 }