Fix codestyle
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / match / Ipv6ExtHeaderEntrySerializerTest.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.ipv6.match.fields.Ipv6ExtHeaderBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
22
23 public class Ipv6ExtHeaderEntrySerializerTest extends AbstractMatchEntrySerializerTest {
24
25     @Test
26     public void testSerialize() throws Exception {
27         final int ipv6extHdr = 358;
28         final int ipv6extHdrMask = 100;
29
30         final Match ipv6extHdrMatch = new MatchBuilder()
31                 .setLayer3Match(new Ipv6MatchBuilder()
32                         .setIpv6ExtHeader(new Ipv6ExtHeaderBuilder()
33                                 .setIpv6Exthdr(ipv6extHdr)
34                                 .setIpv6ExthdrMask(ipv6extHdrMask)
35                                 .build())
36                         .build())
37                 .build();
38
39         assertMatch(ipv6extHdrMatch, true, (out) -> {
40             assertEquals(out.readUnsignedShort(), ipv6extHdr);
41
42             byte[] mask = new byte[2];
43             out.readBytes(mask);
44             assertArrayEquals(mask, ByteUtil.unsignedShortToBytes(ipv6extHdrMask));
45         });
46
47         final Match ipv6exyHdrMatchNoMask = new MatchBuilder()
48                 .setLayer3Match(new Ipv6MatchBuilder()
49                         .setIpv6ExtHeader(new Ipv6ExtHeaderBuilder()
50                                 .setIpv6Exthdr(ipv6extHdr)
51                                 .build())
52                         .build())
53                 .build();
54
55         assertMatch(ipv6exyHdrMatchNoMask, false, (out) -> assertEquals(out.readUnsignedShort(), ipv6extHdr));
56     }
57
58     @Override
59     protected short getLength() {
60         return EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
61     }
62
63     @Override
64     protected int getOxmFieldCode() {
65         return OxmMatchConstants.IPV6_EXTHDR;
66     }
67
68     @Override
69     protected int getOxmClassCode() {
70         return OxmMatchConstants.OPENFLOW_BASIC_CLASS;
71     }
72
73 }