2 * Copyright (c) 2016 Cisco Systems, 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
9 package org.opendaylight.openflowjava.nx.codec.match;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.ByteBufAllocator;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm1Class;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxNshc1;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._1.grouping.Nshc1ValuesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc1CaseValue;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc1CaseValueBuilder;
26 public class Nshc1CodecTest {
28 Nshc1Codec nshc1Codec;
32 private static final int VALUE_LENGTH = 4;
33 private static final int NXM_FIELD_CODE = 115;
37 nshc1Codec = new Nshc1Codec();
38 buffer = ByteBufAllocator.DEFAULT.buffer();
42 public void serializeTest() {
43 input = createMatchEntry();
44 nshc1Codec.serialize(input, buffer);
46 assertEquals(OxmMatchConstants.NXM_1_CLASS, buffer.readUnsignedShort());
47 short fieldMask = buffer.readUnsignedByte();
48 assertEquals(NXM_FIELD_CODE, fieldMask >> 1);
49 assertEquals(0, fieldMask & 1);
50 assertEquals(VALUE_LENGTH, buffer.readUnsignedByte());
51 assertEquals(1, buffer.readUnsignedInt());
55 public void deserializeTest() {
58 input = nshc1Codec.deserialize(buffer);
60 Nshc1CaseValue result = ((Nshc1CaseValue) input.getMatchEntryValue());
62 assertEquals(Nxm1Class.class, input.getOxmClass());
63 assertEquals(NxmNxNshc1.class, input.getOxmMatchField());
64 assertEquals(false, input.isHasMask());
65 assertEquals(2, result.getNshc1Values().getNshc().intValue());
69 private MatchEntry createMatchEntry() {
70 MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
71 Nshc1CaseValueBuilder caseBuilder = new Nshc1CaseValueBuilder();
72 Nshc1ValuesBuilder valuesBuilder = new Nshc1ValuesBuilder();
74 matchEntryBuilder.setOxmClass(Nxm1Class.class);
75 matchEntryBuilder.setOxmMatchField(NxmNxNshc1.class);
76 matchEntryBuilder.setHasMask(false);
78 valuesBuilder.setNshc((long)1);
80 caseBuilder.setNshc1Values(valuesBuilder.build());
81 matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
82 return matchEntryBuilder.build();
85 private void createBuffer(ByteBuf message) {
86 message.writeShort(OxmMatchConstants.NXM_1_CLASS);
88 int fieldMask = (NXM_FIELD_CODE << 1);
89 message.writeByte(fieldMask);
90 message.writeByte(VALUE_LENGTH);