2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.serialization.match;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.PooledByteBufAllocator;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6NdSll;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6NdSllCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.nd.sll._case.Ipv6NdSllBuilder;
28 * @author michal.polkorab
31 public class OxmIpv6NdSllSerializerTest {
33 OxmIpv6NdSllSerializer serializer = new OxmIpv6NdSllSerializer();
36 * Test correct serialization
39 public void testSerialize() {
40 MatchEntryBuilder builder = prepareMatchEntry("00:01:02:03:04:05");
42 ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
43 serializer.serialize(builder.build(), buffer);
45 checkHeader(buffer, false);
46 byte[] address = new byte[6];
47 buffer.readBytes(address);
48 Assert.assertArrayEquals("Wrong address", new byte[]{0, 1, 2, 3, 4, 5}, address);
49 assertTrue("Unexpected data", buffer.readableBytes() == 0);
53 * Test correct header serialization
56 public void testSerializeHeader() {
57 MatchEntryBuilder builder = prepareHeader(false);
59 ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
60 serializer.serializeHeader(builder.build(), buffer);
62 checkHeader(buffer, false);
63 assertTrue("Unexpected data", buffer.readableBytes() == 0);
67 * Test correct oxm-class return value
70 public void testGetOxmClassCode() {
71 assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, serializer.getOxmClassCode());
75 * Test correct oxm-field return value
78 public void getOxmFieldCode() {
79 assertEquals("Wrong oxm-class", OxmMatchConstants.IPV6_ND_SLL, serializer.getOxmFieldCode());
83 * Test correct value length return value
86 public void testGetValueLength() {
87 assertEquals("Wrong value length", EncodeConstants.MAC_ADDRESS_LENGTH, serializer.getValueLength());
90 private static MatchEntryBuilder prepareMatchEntry(String value) {
91 MatchEntryBuilder builder = prepareHeader(false);
92 Ipv6NdSllCaseBuilder casebuilder = new Ipv6NdSllCaseBuilder();
93 Ipv6NdSllBuilder valueBuilder = new Ipv6NdSllBuilder();
94 valueBuilder.setMacAddress(new MacAddress(value));
95 casebuilder.setIpv6NdSll(valueBuilder.build());
96 builder.setMatchEntryValue(casebuilder.build());
100 private static MatchEntryBuilder prepareHeader(boolean hasMask) {
101 MatchEntryBuilder builder = new MatchEntryBuilder();
102 builder.setOxmClass(OpenflowBasicClass.class);
103 builder.setOxmMatchField(Ipv6NdSll.class);
104 builder.setHasMask(hasMask);
108 private static void checkHeader(ByteBuf buffer, boolean hasMask) {
109 assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
110 short fieldAndMask = buffer.readUnsignedByte();
111 assertEquals("Wrong oxm-field", OxmMatchConstants.IPV6_ND_SLL, fieldAndMask >>> 1);
112 assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
113 assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());