2 * Copyright (c) 2017 Red Hat, Inc. 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
8 package org.opendaylight.openflowjava.nx.codec.match;
10 import static org.junit.Assert.assertEquals;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.ByteBufAllocator;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmOfIpDst;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.of.match.ip.dst.grouping.IpDstValuesBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.IpDstCaseValue;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.IpDstCaseValueBuilder;
25 public class Ipv6DstCodecTest {
27 Ipv6DstCodec ipv6DstCodec;
31 private static final int VALUE_LENGTH = 16;
32 private static final int NXM_FIELD_CODE = 20;
36 ipv6DstCodec = new Ipv6DstCodec();
37 buffer = ByteBufAllocator.DEFAULT.buffer();
41 public void serializeTest() {
42 input = createMatchEntry();
43 ipv6DstCodec.serialize(input, buffer);
45 assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
46 short fieldMask = buffer.readUnsignedByte();
47 assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
48 assertEquals(0, fieldMask & 1);
49 assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
50 assertEquals(1, buffer.readUnsignedInt());
54 public void deserializeTest() {
57 input = ipv6DstCodec.deserialize(buffer);
59 final IpDstCaseValue result = (IpDstCaseValue) input.getMatchEntryValue();
61 assertEquals(Nxm1Class.class, input.getOxmClass());
62 assertEquals(NxmOfIpDst.class, input.getOxmMatchField());
63 assertEquals(false, input.isHasMask());
64 assertEquals(2, result.getIpDstValues().getValue().intValue());
67 private static MatchEntry createMatchEntry() {
68 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
69 final IpDstCaseValueBuilder caseBuilder = new IpDstCaseValueBuilder();
70 final IpDstValuesBuilder valuesBuilder = new IpDstValuesBuilder();
72 matchEntryBuilder.setOxmClass(Nxm1Class.class);
73 matchEntryBuilder.setOxmMatchField(NxmOfIpDst.class);
74 matchEntryBuilder.setHasMask(false);
76 valuesBuilder.setValue((long)1);
78 caseBuilder.setIpDstValues(valuesBuilder.build());
79 matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
80 return matchEntryBuilder.build();
83 private static void createBuffer(ByteBuf message) {
84 message.writeShort(OxmMatchConstants.NXM_1_CLASS);
86 int fieldMask = NXM_FIELD_CODE << 1;
87 message.writeByte(fieldMask);
88 message.writeByte(VALUE_LENGTH);