List of usage examples for io.netty.buffer ByteBuf readLong
public abstract long readLong();
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testAggregateBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(2)); MultipartReplyAggregateCaseBuilder aggregateCase = new MultipartReplyAggregateCaseBuilder(); MultipartReplyAggregateBuilder aggregate = new MultipartReplyAggregateBuilder(); aggregate.setPacketCount(BigInteger.valueOf(1234L)); aggregate.setByteCount(BigInteger.valueOf(1234L)); aggregate.setFlowCount(1L);//from w w w . j a v a 2s . c o m aggregateCase.setMultipartReplyAggregate(aggregate.build()); builder.setMultipartReplyBody(aggregateCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 36); Assert.assertEquals("Wrong type", MultipartType.OFPMPAGGREGATE.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); Assert.assertEquals("Wrong Packet count", 1234L, serializedBuffer.readLong()); Assert.assertEquals("Wrong Byte count", 1234L, serializedBuffer.readLong()); Assert.assertEquals("Wrong flow count", 1L, serializedBuffer.readInt()); serializedBuffer.skipBytes(4); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testTableBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(3)); MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder(); MultipartReplyTableBuilder table = new MultipartReplyTableBuilder(); table.setTableStats(createTableStats()); tableCase.setMultipartReplyTable(table.build()); builder.setMultipartReplyBody(tableCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 60); Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); Assert.assertEquals("Wrong table id", 1, serializedBuffer.readUnsignedByte()); serializedBuffer.skipBytes(3);/*from w ww .j a va 2s. c om*/ Assert.assertEquals("Wrong name", "Table name", ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 16)); Assert.assertEquals("Wrong wildcards", 3145983, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong max entries", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong active count", 1L, serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong lookup count", 1234L, serializedBuffer.readLong()); Assert.assertEquals("Wrong matched count", 1234L, serializedBuffer.readLong()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testPortStatsBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(4)); MultipartReplyPortStatsCaseBuilder portStatsCase = new MultipartReplyPortStatsCaseBuilder(); MultipartReplyPortStatsBuilder portStats = new MultipartReplyPortStatsBuilder(); portStats.setPortStats(createPortStats()); portStatsCase.setMultipartReplyPortStats(portStats.build()); builder.setMultipartReplyBody(portStatsCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 118); Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTSTATS.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); MultipartReplyPortStatsCase body = (MultipartReplyPortStatsCase) message.getMultipartReplyBody(); MultipartReplyPortStats messageOutput = body.getMultipartReplyPortStats(); PortStats portStatsOutput = messageOutput.getPortStats().get(0); Assert.assertEquals("Wrong port no", portStatsOutput.getPortNo().intValue(), serializedBuffer.readInt()); serializedBuffer.skipBytes(6);//from w w w . jav a2 s .c om Assert.assertEquals("Wrong rx packets", portStatsOutput.getRxPackets().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx packets", portStatsOutput.getTxPackets().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx bytes", portStatsOutput.getRxBytes().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx bytes", portStatsOutput.getTxBytes().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx dropped", portStatsOutput.getRxDropped().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx dropped", portStatsOutput.getTxDropped().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx errors", portStatsOutput.getRxErrors().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx errors", portStatsOutput.getTxErrors().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx frame err", portStatsOutput.getRxFrameErr().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx over err", portStatsOutput.getRxOverErr().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong rx crc err", portStatsOutput.getRxCrcErr().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong collisions", portStatsOutput.getCollisions().longValue(), serializedBuffer.readLong()); }
From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java
License:Open Source License
@Test public void testQueueBodySerialize() throws Exception { MultipartReplyMessageBuilder builder; builder = new MultipartReplyMessageBuilder(); BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID); builder.setFlags(new MultipartRequestFlags(true)); builder.setType(MultipartType.forValue(5)); MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder(); MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder(); queue.setQueueStats(createQueueStats()); queueCase.setMultipartReplyQueue(queue.build()); builder.setMultipartReplyBody(queueCase.build()); MultipartReplyMessage message = builder.build(); ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer(); factory.serialize(message, serializedBuffer); BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 44); Assert.assertEquals("Wrong type", MultipartType.OFPMPQUEUE.getIntValue(), serializedBuffer.readShort()); Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort())); MultipartReplyQueueCase body = (MultipartReplyQueueCase) message.getMultipartReplyBody(); MultipartReplyQueue messageOutput = body.getMultipartReplyQueue(); QueueStats queueStats = messageOutput.getQueueStats().get(0); Assert.assertEquals("Wrong length", 32, serializedBuffer.readUnsignedShort()); serializedBuffer.skipBytes(2);/*from w ww .j a v a 2 s . c o m*/ Assert.assertEquals("Wrong queue id", queueStats.getQueueId().intValue(), serializedBuffer.readUnsignedInt()); Assert.assertEquals("Wrong tx bytes", queueStats.getTxBytes().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx packets", queueStats.getTxPackets().longValue(), serializedBuffer.readLong()); Assert.assertEquals("Wrong tx errors", queueStats.getTxErrors().longValue(), serializedBuffer.readLong()); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.MatchSerializerTest2.java
License:Open Source License
/** * Testing serialization of match//from ww w .ja v a 2 s.co m */ @Test public void test() { MatchBuilder builder = new MatchBuilder(); builder.setType(OxmMatchType.class); List<MatchEntries> entries = new ArrayList<>(); MatchEntriesBuilder entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(Nxm0Class.class); entryBuilder.setOxmMatchField(InPort.class); entryBuilder.setHasMask(false); PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder(); portNumberBuilder.setPortNumber(new PortNumber(42L)); entryBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(Nxm1Class.class); entryBuilder.setOxmMatchField(InPhyPort.class); entryBuilder.setHasMask(false); portNumberBuilder = new PortNumberMatchEntryBuilder(); portNumberBuilder.setPortNumber(new PortNumber(43L)); entryBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Metadata.class); entryBuilder.setHasMask(true); MetadataMatchEntryBuilder metadataBuilder = new MetadataMatchEntryBuilder(); metadataBuilder.setMetadata(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MetadataMatchEntry.class, metadataBuilder.build()); MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(ExperimenterClass.class); entryBuilder.setOxmMatchField(EthDst.class); entryBuilder.setHasMask(true); MacAddressMatchEntryBuilder macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("01:00:03:00:00:06")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 5 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthSrc.class); entryBuilder.setHasMask(true); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("04:00:02:00:00:08")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthType.class); entryBuilder.setHasMask(false); EthTypeMatchEntryBuilder ethBuilder = new EthTypeMatchEntryBuilder(); ethBuilder.setEthType(new EtherType(46)); entryBuilder.addAugmentation(EthTypeMatchEntry.class, ethBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(VlanVid.class); entryBuilder.setHasMask(true); VlanVidMatchEntryBuilder vidBuilder = new VlanVidMatchEntryBuilder(); vidBuilder.setCfiBit(true); vidBuilder.setVlanVid(45); entryBuilder.addAugmentation(VlanVidMatchEntry.class, vidBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 9 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(VlanPcp.class); entryBuilder.setHasMask(true); VlanPcpMatchEntryBuilder pcpBuilder = new VlanPcpMatchEntryBuilder(); pcpBuilder.setVlanPcp((short) 14); entryBuilder.addAugmentation(VlanPcpMatchEntry.class, pcpBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpDscp.class); entryBuilder.setHasMask(false); DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder(); dscpBuilder.setDscp(new Dscp((short) 48)); entryBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpEcn.class); entryBuilder.setHasMask(false); EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); ecnBuilder.setEcn((short) 49); entryBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpProto.class); entryBuilder.setHasMask(false); ProtocolNumberMatchEntryBuilder protoBuilder = new ProtocolNumberMatchEntryBuilder(); protoBuilder.setProtocolNumber((short) 50); entryBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv4Src.class); entryBuilder.setHasMask(true); Ipv4AddressMatchEntryBuilder ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.1")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 14 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv4Dst.class); entryBuilder.setHasMask(true); ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.2")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 15 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TcpSrc.class); entryBuilder.setHasMask(false); PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6653)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TcpDst.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6654)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(UdpSrc.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6655)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(UdpDst.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6656)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(SctpSrc.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6657)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(SctpDst.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6658)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv4Type.class); entryBuilder.setHasMask(false); Icmpv4TypeMatchEntryBuilder icmpv4typeBuilder = new Icmpv4TypeMatchEntryBuilder(); icmpv4typeBuilder.setIcmpv4Type((short) 51); entryBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4typeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv4Code.class); entryBuilder.setHasMask(false); Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder(); icmpv4CodeBuilder.setIcmpv4Code((short) 52); entryBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpOp.class); entryBuilder.setHasMask(false); OpCodeMatchEntryBuilder opBuilder = new OpCodeMatchEntryBuilder(); opBuilder.setOpCode(53); entryBuilder.addAugmentation(OpCodeMatchEntry.class, opBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpSpa.class); entryBuilder.setHasMask(true); ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.4")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 16 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpTpa.class); entryBuilder.setHasMask(true); ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.5")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 17 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpSha.class); entryBuilder.setHasMask(true); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("00:01:02:03:04:05")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 4, 0, 0, 6 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpTha.class); entryBuilder.setHasMask(true); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("00:00:00:00:00:03")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 6, 0, 0, 4 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Src.class); entryBuilder.setHasMask(true); Ipv6AddressMatchEntryBuilder ipv6Builder = new Ipv6AddressMatchEntryBuilder(); ipv6Builder.setIpv6Address(new Ipv6Address("0:0:0:0:0:0:0:1")); entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Dst.class); entryBuilder.setHasMask(true); ipv6Builder = new Ipv6AddressMatchEntryBuilder(); ipv6Builder.setIpv6Address(new Ipv6Address("0:0:1:0:1:0:0:1")); entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Flabel.class); entryBuilder.setHasMask(true); Ipv6FlabelMatchEntryBuilder flabelBuilder = new Ipv6FlabelMatchEntryBuilder(); flabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(58L)); entryBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, flabelBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 1, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv6Type.class); entryBuilder.setHasMask(false); Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder(); icmpv6TypeBuilder.setIcmpv6Type((short) 59); entryBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv6Code.class); entryBuilder.setHasMask(false); Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder(); icmpv6CodeBuilder.setIcmpv6Code((short) 60); entryBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdTarget.class); entryBuilder.setHasMask(false); ipv6Builder = new Ipv6AddressMatchEntryBuilder(); ipv6Builder.setIpv6Address(new Ipv6Address("F:0:0::0:0:0:1")); entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(ExperimenterClass.class); entryBuilder.setOxmMatchField(Ipv6NdSll.class); entryBuilder.setHasMask(false); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("01:00:03:00:00:06")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdTll.class); entryBuilder.setHasMask(false); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("04:00:02:00:00:08")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsLabel.class); entryBuilder.setHasMask(false); MplsLabelMatchEntryBuilder labelBuilder = new MplsLabelMatchEntryBuilder(); labelBuilder.setMplsLabel(61L); entryBuilder.addAugmentation(MplsLabelMatchEntry.class, labelBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsTc.class); entryBuilder.setHasMask(false); TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder(); tcBuilder.setTc((short) 62); entryBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsBos.class); entryBuilder.setHasMask(false); BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder(); bosBuilder.setBos(true); entryBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(PbbIsid.class); entryBuilder.setHasMask(true); IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder(); isidBuilder.setIsid(64L); entryBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 1, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TunnelId.class); entryBuilder.setHasMask(true); metadataBuilder = new MetadataMatchEntryBuilder(); metadataBuilder.setMetadata(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MetadataMatchEntry.class, metadataBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Exthdr.class); entryBuilder.setHasMask(true); PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder(); pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(true, false, true, false, true, false, true, false, true)); entryBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); builder.setMatchEntries(entries); Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); MatchSerializer.encodeMatch(match, out); Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong match length", 428, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 0, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 42, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 43, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 5, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1L, out.readLong()); Assert.assertEquals("Wrong match entry mask", 2L, out.readLong()); Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 7, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); byte[] array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 1, 0, 3, 0, 0, 6 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 5 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 9, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 4, 0, 2, 0, 0, 8 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 10, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 46, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 13, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 4141, out.readUnsignedShort()); array = new byte[2]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 9 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 14, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 14, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 48, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 18, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 49, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 20, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 50, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 23, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 1 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 14 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 25, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 2 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 15 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 26, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6653, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 28, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6654, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 30, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6655, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 32, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6656, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 34, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6657, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 36, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6658, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 38, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 51, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 40, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 52, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 42, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 53, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 45, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 4 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 16 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 47, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 5 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 17 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 49, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 1, 2, 3, 4, 5 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 4, 0, 0, 6 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 51, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 3 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 6, 0, 0, 4 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 53, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 32, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 55, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 32, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, array); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 57, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 58, out.readUnsignedInt()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 1, 0, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 58, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 59, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 60, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 60, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 62, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0xFFFF, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 64, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 1, 0, 3, 0, 0, 6 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 66, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 4, 0, 2, 0, 0, 8 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 68, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 61, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 70, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 62, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 72, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 75, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 64, out.readUnsignedMedium()); array = new byte[3]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 1, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 77, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1L, out.readLong()); Assert.assertEquals("Wrong match entry mask", 2L, out.readLong()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 79, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 358, out.readUnsignedShort()); array = new byte[2]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 2 }, array); Assert.assertTrue("Wrong padding", out.readableBytes() == 4); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.OF13MatchSerializer02Test.java
License:Open Source License
/** * Testing serialization of match/* www . j a v a 2 s. com*/ */ @Test public void test() { MatchBuilder builder = new MatchBuilder(); builder.setType(OxmMatchType.class); List<MatchEntry> entries = new ArrayList<>(); MatchEntryBuilder entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(InPort.class); entryBuilder.setHasMask(false); InPortCaseBuilder inPortCaseBuilder = new InPortCaseBuilder(); InPortBuilder inPortBuilder = new InPortBuilder(); inPortBuilder.setPortNumber(new PortNumber(42L)); inPortCaseBuilder.setInPort(inPortBuilder.build()); entryBuilder.setMatchEntryValue(inPortCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(InPhyPort.class); entryBuilder.setHasMask(false); InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder(); InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder(); inPhyPortBuilder.setPortNumber(new PortNumber(43L)); inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build()); entryBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Metadata.class); entryBuilder.setHasMask(true); MetadataCaseBuilder metaCaseBuilder = new MetadataCaseBuilder(); MetadataBuilder metadataBuilder = new MetadataBuilder(); metadataBuilder.setMetadata(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); metadataBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }); metaCaseBuilder.setMetadata(metadataBuilder.build()); entryBuilder.setMatchEntryValue(metaCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthDst.class); entryBuilder.setHasMask(true); EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder(); EthDstBuilder ethDstBuilder = new EthDstBuilder(); ethDstBuilder.setMacAddress(new MacAddress("01:00:03:00:00:06")); ethDstBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 5 }); ethDstCaseBuilder.setEthDst(ethDstBuilder.build()); entryBuilder.setMatchEntryValue(ethDstCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthSrc.class); entryBuilder.setHasMask(true); EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder(); EthSrcBuilder ethSrcBuilder = new EthSrcBuilder(); ethSrcBuilder.setMacAddress(new MacAddress("04:00:02:00:00:08")); ethSrcBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 2 }); ethSrcCaseBuilder.setEthSrc(ethSrcBuilder.build()); entryBuilder.setMatchEntryValue(ethSrcCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthType.class); entryBuilder.setHasMask(false); EthTypeCaseBuilder ethTypeCaseBuilder = new EthTypeCaseBuilder(); EthTypeBuilder ethTypeBuilder = new EthTypeBuilder(); ethTypeBuilder.setEthType(new EtherType(46)); ethTypeCaseBuilder.setEthType(ethTypeBuilder.build()); entryBuilder.setMatchEntryValue(ethTypeCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(VlanVid.class); entryBuilder.setHasMask(true); VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder(); VlanVidBuilder vlanVidBuilder = new VlanVidBuilder(); vlanVidBuilder.setVlanVid(45); vlanVidBuilder.setCfiBit(true); vlanVidBuilder.setMask(new byte[] { 0, 9 }); vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build()); entryBuilder.setMatchEntryValue(vlanVidCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(VlanPcp.class); entryBuilder.setHasMask(false); VlanPcpCaseBuilder vlanPcpCaseBuilder = new VlanPcpCaseBuilder(); VlanPcpBuilder vlanPcpBuilder = new VlanPcpBuilder(); vlanPcpBuilder.setVlanPcp((short) 14); vlanPcpCaseBuilder.setVlanPcp(vlanPcpBuilder.build()); entryBuilder.setMatchEntryValue(vlanPcpCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpDscp.class); entryBuilder.setHasMask(false); IpDscpCaseBuilder ipDscpCaseBuilder = new IpDscpCaseBuilder(); IpDscpBuilder ipDscpBuilder = new IpDscpBuilder(); ipDscpBuilder.setDscp(new Dscp((short) 48)); ipDscpCaseBuilder.setIpDscp(ipDscpBuilder.build()); entryBuilder.setMatchEntryValue(ipDscpCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpEcn.class); entryBuilder.setHasMask(false); IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder(); IpEcnBuilder ipEcnBuilder = new IpEcnBuilder(); ipEcnBuilder.setEcn((short) 49); ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build()); entryBuilder.setMatchEntryValue(ipEcnCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpProto.class); entryBuilder.setHasMask(false); IpProtoCaseBuilder ipProtoCaseBuilder = new IpProtoCaseBuilder(); IpProtoBuilder ipProtoBuilder = new IpProtoBuilder(); ipProtoBuilder.setProtocolNumber((short) 50); ipProtoCaseBuilder.setIpProto(ipProtoBuilder.build()); entryBuilder.setMatchEntryValue(ipProtoCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv4Src.class); entryBuilder.setHasMask(true); Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder(); Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder(); ipv4SrcBuilder.setIpv4Address(new Ipv4Address("10.0.0.1")); ipv4SrcBuilder.setMask(new byte[] { 0, 0, 0, 14 }); ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build()); entryBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv4Dst.class); entryBuilder.setHasMask(true); Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder(); Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder(); ipv4DstBuilder.setIpv4Address(new Ipv4Address("10.0.0.2")); ipv4DstBuilder.setMask(new byte[] { 0, 0, 0, 15 }); ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build()); entryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TcpSrc.class); entryBuilder.setHasMask(false); TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder(); TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder(); tcpSrcBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber( 6653)); tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build()); entryBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TcpDst.class); entryBuilder.setHasMask(false); TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder(); TcpDstBuilder tcpDstBuilder = new TcpDstBuilder(); tcpDstBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber( 6654)); tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build()); entryBuilder.setMatchEntryValue(tcpDstCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(UdpSrc.class); entryBuilder.setHasMask(false); UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder(); UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder(); udpSrcBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber( 6655)); udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build()); entryBuilder.setMatchEntryValue(udpSrcCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(UdpDst.class); entryBuilder.setHasMask(false); UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder(); UdpDstBuilder udpDstBuilder = new UdpDstBuilder(); udpDstBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber( 6656)); udpDstCaseBuilder.setUdpDst(udpDstBuilder.build()); entryBuilder.setMatchEntryValue(udpDstCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(SctpSrc.class); entryBuilder.setHasMask(false); SctpSrcCaseBuilder sctpSrcCaseBuilder = new SctpSrcCaseBuilder(); SctpSrcBuilder sctpSrcBuilder = new SctpSrcBuilder(); sctpSrcBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber( 6657)); sctpSrcCaseBuilder.setSctpSrc(sctpSrcBuilder.build()); entryBuilder.setMatchEntryValue(sctpSrcCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(SctpDst.class); entryBuilder.setHasMask(false); SctpDstCaseBuilder sctpDstCaseBuilder = new SctpDstCaseBuilder(); SctpDstBuilder sctpDstBuilder = new SctpDstBuilder(); sctpDstBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber( 6658)); sctpDstCaseBuilder.setSctpDst(sctpDstBuilder.build()); entryBuilder.setMatchEntryValue(sctpDstCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv4Type.class); entryBuilder.setHasMask(false); Icmpv4TypeCaseBuilder icmpv4TypeCaseBuilder = new Icmpv4TypeCaseBuilder(); Icmpv4TypeBuilder icmpv4TypeBuilder = new Icmpv4TypeBuilder(); icmpv4TypeBuilder.setIcmpv4Type((short) 51); icmpv4TypeCaseBuilder.setIcmpv4Type(icmpv4TypeBuilder.build()); entryBuilder.setMatchEntryValue(icmpv4TypeCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv4Code.class); entryBuilder.setHasMask(false); Icmpv4CodeCaseBuilder icmpv4CodeCaseBuilder = new Icmpv4CodeCaseBuilder(); Icmpv4CodeBuilder icmpv4CodeBuilder = new Icmpv4CodeBuilder(); icmpv4CodeBuilder.setIcmpv4Code((short) 52); icmpv4CodeCaseBuilder.setIcmpv4Code(icmpv4CodeBuilder.build()); entryBuilder.setMatchEntryValue(icmpv4CodeCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpOp.class); entryBuilder.setHasMask(false); ArpOpCaseBuilder arpOpCaseBuilder = new ArpOpCaseBuilder(); ArpOpBuilder arpOpBuilder = new ArpOpBuilder(); arpOpBuilder.setOpCode(53); arpOpCaseBuilder.setArpOp(arpOpBuilder.build()); entryBuilder.setMatchEntryValue(arpOpCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpSpa.class); entryBuilder.setHasMask(true); ArpSpaCaseBuilder arpSpaCaseBuilder = new ArpSpaCaseBuilder(); ArpSpaBuilder arpSpaBuilder = new ArpSpaBuilder(); arpSpaBuilder.setIpv4Address(new Ipv4Address("10.0.0.4")); arpSpaBuilder.setMask(new byte[] { 0, 0, 0, 16 }); arpSpaCaseBuilder.setArpSpa(arpSpaBuilder.build()); entryBuilder.setMatchEntryValue(arpSpaCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpTpa.class); entryBuilder.setHasMask(true); ArpTpaCaseBuilder arpTpaCaseBuilder = new ArpTpaCaseBuilder(); ArpTpaBuilder arpTpaBuilder = new ArpTpaBuilder(); arpTpaBuilder.setIpv4Address(new Ipv4Address("10.0.0.5")); arpTpaBuilder.setMask(new byte[] { 0, 0, 0, 17 }); arpTpaCaseBuilder.setArpTpa(arpTpaBuilder.build()); entryBuilder.setMatchEntryValue(arpTpaCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpSha.class); entryBuilder.setHasMask(true); ArpShaCaseBuilder arpShaCaseBuilder = new ArpShaCaseBuilder(); ArpShaBuilder arpShaBuilder = new ArpShaBuilder(); arpShaBuilder.setMacAddress(new MacAddress("00:01:02:03:04:05")); arpShaBuilder.setMask(new byte[] { 0, 0, 4, 0, 0, 6 }); arpShaCaseBuilder.setArpSha(arpShaBuilder.build()); entryBuilder.setMatchEntryValue(arpShaCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpTha.class); entryBuilder.setHasMask(true); ArpThaCaseBuilder arpThaCaseBuilder = new ArpThaCaseBuilder(); ArpThaBuilder arpThaBuilder = new ArpThaBuilder(); arpThaBuilder.setMacAddress(new MacAddress("00:00:00:00:00:03")); arpThaBuilder.setMask(new byte[] { 0, 0, 6, 0, 0, 4 }); arpThaCaseBuilder.setArpTha(arpThaBuilder.build()); entryBuilder.setMatchEntryValue(arpThaCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Src.class); entryBuilder.setHasMask(true); Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder(); Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder(); ipv6SrcBuilder.setIpv6Address(new Ipv6Address("0:0:0:0:0:0:0:1")); ipv6SrcBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }); ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build()); entryBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Dst.class); entryBuilder.setHasMask(true); Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder(); Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder(); ipv6DstBuilder.setIpv6Address(new Ipv6Address("0:0:1:0:1:0:0:1")); ipv6DstBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1 }); ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build()); entryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Flabel.class); entryBuilder.setHasMask(false); Ipv6FlabelCaseBuilder ipv6FlabelCaseBuilder = new Ipv6FlabelCaseBuilder(); Ipv6FlabelBuilder ipv6FlabelBuilder = new Ipv6FlabelBuilder(); ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(58L)); ipv6FlabelCaseBuilder.setIpv6Flabel(ipv6FlabelBuilder.build()); entryBuilder.setMatchEntryValue(ipv6FlabelCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv6Type.class); entryBuilder.setHasMask(false); Icmpv6TypeCaseBuilder icmpv6TypeCaseBuilder = new Icmpv6TypeCaseBuilder(); Icmpv6TypeBuilder icmpv6TypeBuilder = new Icmpv6TypeBuilder(); icmpv6TypeBuilder.setIcmpv6Type((short) 59); icmpv6TypeCaseBuilder.setIcmpv6Type(icmpv6TypeBuilder.build()); entryBuilder.setMatchEntryValue(icmpv6TypeCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv6Code.class); entryBuilder.setHasMask(false); Icmpv6CodeCaseBuilder Icmpv6CodeCaseBuilder = new Icmpv6CodeCaseBuilder(); Icmpv6CodeBuilder Icmpv6CodeBuilder = new Icmpv6CodeBuilder(); Icmpv6CodeBuilder.setIcmpv6Code((short) 60); Icmpv6CodeCaseBuilder.setIcmpv6Code(Icmpv6CodeBuilder.build()); entryBuilder.setMatchEntryValue(Icmpv6CodeCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdTarget.class); entryBuilder.setHasMask(false); Ipv6NdTargetCaseBuilder ipv6NdTargetCaseBuilder = new Ipv6NdTargetCaseBuilder(); Ipv6NdTargetBuilder ipv6NdTargetBuilder = new Ipv6NdTargetBuilder(); ipv6NdTargetBuilder.setIpv6Address(new Ipv6Address("F:0:0::0:0:0:1")); ipv6NdTargetCaseBuilder.setIpv6NdTarget(ipv6NdTargetBuilder.build()); entryBuilder.setMatchEntryValue(ipv6NdTargetCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdSll.class); entryBuilder.setHasMask(false); Ipv6NdSllCaseBuilder ipv6NdSllCaseBuilder = new Ipv6NdSllCaseBuilder(); Ipv6NdSllBuilder ipv6NdSllBuilder = new Ipv6NdSllBuilder(); ipv6NdSllBuilder.setMacAddress(new MacAddress("01:00:03:00:00:06")); ipv6NdSllCaseBuilder.setIpv6NdSll(ipv6NdSllBuilder.build()); entryBuilder.setMatchEntryValue(ipv6NdSllCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdTll.class); entryBuilder.setHasMask(false); Ipv6NdTllCaseBuilder ipv6NdTllCaseBuilder = new Ipv6NdTllCaseBuilder(); Ipv6NdTllBuilder ipv6NdTllBuilder = new Ipv6NdTllBuilder(); ipv6NdTllBuilder.setMacAddress(new MacAddress("04:00:02:00:00:08")); ipv6NdTllCaseBuilder.setIpv6NdTll(ipv6NdTllBuilder.build()); entryBuilder.setMatchEntryValue(ipv6NdTllCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsLabel.class); entryBuilder.setHasMask(false); MplsLabelCaseBuilder mplsLabelCaseBuilder = new MplsLabelCaseBuilder(); MplsLabelBuilder mplsLabelBuilder = new MplsLabelBuilder(); mplsLabelBuilder.setMplsLabel(61L); mplsLabelCaseBuilder.setMplsLabel(mplsLabelBuilder.build()); entryBuilder.setMatchEntryValue(mplsLabelCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsTc.class); entryBuilder.setHasMask(false); MplsTcCaseBuilder MplsTcCaseBuilder = new MplsTcCaseBuilder(); MplsTcBuilder MplsTcBuilder = new MplsTcBuilder(); MplsTcBuilder.setTc((short) 62); MplsTcCaseBuilder.setMplsTc(MplsTcBuilder.build()); entryBuilder.setMatchEntryValue(MplsTcCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsBos.class); entryBuilder.setHasMask(false); MplsBosCaseBuilder MplsBosCaseBuilder = new MplsBosCaseBuilder(); MplsBosBuilder MplsBosBuilder = new MplsBosBuilder(); MplsBosBuilder.setBos(true); MplsBosCaseBuilder.setMplsBos(MplsBosBuilder.build()); entryBuilder.setMatchEntryValue(MplsBosCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(PbbIsid.class); entryBuilder.setHasMask(true); PbbIsidCaseBuilder pbbIsidCaseBuilder = new PbbIsidCaseBuilder(); PbbIsidBuilder pbbIsidBuilder = new PbbIsidBuilder(); pbbIsidBuilder.setIsid(64L); pbbIsidBuilder.setMask(new byte[] { 0, 1, 2 }); pbbIsidCaseBuilder.setPbbIsid(pbbIsidBuilder.build()); entryBuilder.setMatchEntryValue(pbbIsidCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TunnelId.class); entryBuilder.setHasMask(true); TunnelIdCaseBuilder tunnelIdCaseBuilder = new TunnelIdCaseBuilder(); TunnelIdBuilder tunnelIdBuilder = new TunnelIdBuilder(); tunnelIdBuilder.setTunnelId(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); tunnelIdBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }); tunnelIdCaseBuilder.setTunnelId(tunnelIdBuilder.build()); entryBuilder.setMatchEntryValue(tunnelIdCaseBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntryBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Exthdr.class); entryBuilder.setHasMask(true); Ipv6ExthdrCaseBuilder ipv6ExthdrCaseBuilder = new Ipv6ExthdrCaseBuilder(); Ipv6ExthdrBuilder ipv6ExthdrBuilder = new Ipv6ExthdrBuilder(); ipv6ExthdrBuilder .setPseudoField(new Ipv6ExthdrFlags(true, false, true, false, true, false, true, false, true)); ipv6ExthdrBuilder.setMask(new byte[] { 0, 2 }); ipv6ExthdrCaseBuilder.setIpv6Exthdr(ipv6ExthdrBuilder.build()); entryBuilder.setMatchEntryValue(ipv6ExthdrCaseBuilder.build()); entries.add(entryBuilder.build()); builder.setMatchEntry(entries); Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); matchSerializer.serialize(match, out); Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong match length", 424, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 0, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 42, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 43, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 5, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1L, out.readLong()); Assert.assertEquals("Wrong match entry mask", 2L, out.readLong()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 7, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); byte[] array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 1, 0, 3, 0, 0, 6 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 5 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 9, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 4, 0, 2, 0, 0, 8 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 10, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 46, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 13, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 4141, out.readUnsignedShort()); array = new byte[2]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 9 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 14, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 14, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 48, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 18, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 49, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 20, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 50, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 23, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 1 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 14 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 25, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 2 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 15 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 26, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6653, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 28, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6654, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 30, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6655, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 32, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6656, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 34, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6657, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 36, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6658, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 38, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 51, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 40, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 52, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 42, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 53, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 45, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 4 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 16 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 47, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 5 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 17 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 49, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 1, 2, 3, 4, 5 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 4, 0, 0, 6 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 51, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 3 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 6, 0, 0, 4 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 53, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 32, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 55, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 32, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, array); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 56, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); //8, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 58, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 58, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 59, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 60, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 60, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 62, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 64, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 1, 0, 3, 0, 0, 6 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 66, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 4, 0, 2, 0, 0, 8 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 68, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 61, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 70, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 62, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 72, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 75, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 64, out.readUnsignedMedium()); array = new byte[3]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 1, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 77, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1L, out.readLong()); Assert.assertEquals("Wrong match entry mask", 2L, out.readLong()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 79, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 358, out.readUnsignedShort()); array = new byte[2]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 2 }, array); Assert.assertTrue("Wrong padding", out.readableBytes() == 0); }
From source file:org.opendaylight.openflowjava.protocol.impl.util.OF13MatchSerializerTest2.java
License:Open Source License
/** * Testing serialization of match//from w w w . j ava 2s. c om */ @Test public void test() { MatchBuilder builder = new MatchBuilder(); builder.setType(OxmMatchType.class); List<MatchEntries> entries = new ArrayList<>(); MatchEntriesBuilder entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(InPort.class); entryBuilder.setHasMask(false); PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder(); portNumberBuilder.setPortNumber(new PortNumber(42L)); entryBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(InPhyPort.class); entryBuilder.setHasMask(false); portNumberBuilder = new PortNumberMatchEntryBuilder(); portNumberBuilder.setPortNumber(new PortNumber(43L)); entryBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Metadata.class); entryBuilder.setHasMask(true); MetadataMatchEntryBuilder metadataBuilder = new MetadataMatchEntryBuilder(); metadataBuilder.setMetadata(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MetadataMatchEntry.class, metadataBuilder.build()); MaskMatchEntryBuilder maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthDst.class); entryBuilder.setHasMask(true); MacAddressMatchEntryBuilder macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("01:00:03:00:00:06")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 5 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthSrc.class); entryBuilder.setHasMask(true); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("04:00:02:00:00:08")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(EthType.class); entryBuilder.setHasMask(false); EthTypeMatchEntryBuilder ethBuilder = new EthTypeMatchEntryBuilder(); ethBuilder.setEthType(new EtherType(46)); entryBuilder.addAugmentation(EthTypeMatchEntry.class, ethBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(VlanVid.class); entryBuilder.setHasMask(true); VlanVidMatchEntryBuilder vidBuilder = new VlanVidMatchEntryBuilder(); vidBuilder.setCfiBit(true); vidBuilder.setVlanVid(45); entryBuilder.addAugmentation(VlanVidMatchEntry.class, vidBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 9 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(VlanPcp.class); entryBuilder.setHasMask(false); VlanPcpMatchEntryBuilder pcpBuilder = new VlanPcpMatchEntryBuilder(); pcpBuilder.setVlanPcp((short) 14); entryBuilder.addAugmentation(VlanPcpMatchEntry.class, pcpBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpDscp.class); entryBuilder.setHasMask(false); DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder(); dscpBuilder.setDscp(new Dscp((short) 48)); entryBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpEcn.class); entryBuilder.setHasMask(false); EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder(); ecnBuilder.setEcn((short) 49); entryBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(IpProto.class); entryBuilder.setHasMask(false); ProtocolNumberMatchEntryBuilder protoBuilder = new ProtocolNumberMatchEntryBuilder(); protoBuilder.setProtocolNumber((short) 50); entryBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv4Src.class); entryBuilder.setHasMask(true); Ipv4AddressMatchEntryBuilder ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.1")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 14 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv4Dst.class); entryBuilder.setHasMask(true); ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.2")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 15 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TcpSrc.class); entryBuilder.setHasMask(false); PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6653)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TcpDst.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6654)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(UdpSrc.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6655)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(UdpDst.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6656)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(SctpSrc.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6657)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(SctpDst.class); entryBuilder.setHasMask(false); portBuilder = new PortMatchEntryBuilder(); portBuilder.setPort( new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber( 6658)); entryBuilder.addAugmentation(PortMatchEntry.class, portBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv4Type.class); entryBuilder.setHasMask(false); Icmpv4TypeMatchEntryBuilder icmpv4typeBuilder = new Icmpv4TypeMatchEntryBuilder(); icmpv4typeBuilder.setIcmpv4Type((short) 51); entryBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4typeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv4Code.class); entryBuilder.setHasMask(false); Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder(); icmpv4CodeBuilder.setIcmpv4Code((short) 52); entryBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpOp.class); entryBuilder.setHasMask(false); OpCodeMatchEntryBuilder opBuilder = new OpCodeMatchEntryBuilder(); opBuilder.setOpCode(53); entryBuilder.addAugmentation(OpCodeMatchEntry.class, opBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpSpa.class); entryBuilder.setHasMask(true); ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.4")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 16 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpTpa.class); entryBuilder.setHasMask(true); ipv4Builder = new Ipv4AddressMatchEntryBuilder(); ipv4Builder.setIpv4Address(new Ipv4Address("10.0.0.5")); entryBuilder.addAugmentation(Ipv4AddressMatchEntry.class, ipv4Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 17 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpSha.class); entryBuilder.setHasMask(true); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("00:01:02:03:04:05")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 4, 0, 0, 6 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(ArpTha.class); entryBuilder.setHasMask(true); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("00:00:00:00:00:03")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 6, 0, 0, 4 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Src.class); entryBuilder.setHasMask(true); Ipv6AddressMatchEntryBuilder ipv6Builder = new Ipv6AddressMatchEntryBuilder(); ipv6Builder.setIpv6Address(new Ipv6Address("0:0:0:0:0:0:0:1")); entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Dst.class); entryBuilder.setHasMask(true); ipv6Builder = new Ipv6AddressMatchEntryBuilder(); ipv6Builder.setIpv6Address(new Ipv6Address("0:0:1:0:1:0:0:1")); entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Flabel.class); entryBuilder.setHasMask(true); Ipv6FlabelMatchEntryBuilder flabelBuilder = new Ipv6FlabelMatchEntryBuilder(); flabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(58L)); entryBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, flabelBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 1, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv6Type.class); entryBuilder.setHasMask(false); Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder(); icmpv6TypeBuilder.setIcmpv6Type((short) 59); entryBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Icmpv6Code.class); entryBuilder.setHasMask(false); Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder(); icmpv6CodeBuilder.setIcmpv6Code((short) 60); entryBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build()); entries.add(entryBuilder.build()); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdTarget.class); entryBuilder.setHasMask(false); ipv6Builder = new Ipv6AddressMatchEntryBuilder(); ipv6Builder.setIpv6Address(new Ipv6Address("F:0:0::0:0:0:1")); entryBuilder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6Builder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdSll.class); entryBuilder.setHasMask(false); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("01:00:03:00:00:06")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6NdTll.class); entryBuilder.setHasMask(false); macBuilder = new MacAddressMatchEntryBuilder(); macBuilder.setMacAddress(new MacAddress("04:00:02:00:00:08")); entryBuilder.addAugmentation(MacAddressMatchEntry.class, macBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsLabel.class); entryBuilder.setHasMask(false); MplsLabelMatchEntryBuilder labelBuilder = new MplsLabelMatchEntryBuilder(); labelBuilder.setMplsLabel(61L); entryBuilder.addAugmentation(MplsLabelMatchEntry.class, labelBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsTc.class); entryBuilder.setHasMask(false); TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder(); tcBuilder.setTc((short) 62); entryBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(MplsBos.class); entryBuilder.setHasMask(false); BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder(); bosBuilder.setBos(true); entryBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(PbbIsid.class); entryBuilder.setHasMask(true); IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder(); isidBuilder.setIsid(64L); entryBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 1, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(TunnelId.class); entryBuilder.setHasMask(true); metadataBuilder = new MetadataMatchEntryBuilder(); metadataBuilder.setMetadata(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }); entryBuilder.addAugmentation(MetadataMatchEntry.class, metadataBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); entryBuilder = new MatchEntriesBuilder(); entryBuilder.setOxmClass(OpenflowBasicClass.class); entryBuilder.setOxmMatchField(Ipv6Exthdr.class); entryBuilder.setHasMask(true); PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder(); pseudoBuilder.setPseudoField(new Ipv6ExthdrFlags(true, false, true, false, true, false, true, false, true)); entryBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build()); maskBuilder = new MaskMatchEntryBuilder(); maskBuilder.setMask(new byte[] { 0, 2 }); entryBuilder.addAugmentation(MaskMatchEntry.class, maskBuilder.build()); entries.add(entryBuilder.build()); builder.setMatchEntries(entries); Match match = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); matchSerializer.serialize(match, out); Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort()); Assert.assertEquals("Wrong match length", 428, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 0, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 42, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 43, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 5, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1L, out.readLong()); Assert.assertEquals("Wrong match entry mask", 2L, out.readLong()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 7, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); byte[] array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 1, 0, 3, 0, 0, 6 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 5 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 9, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 4, 0, 2, 0, 0, 8 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 10, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 46, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 13, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 4141, out.readUnsignedShort()); array = new byte[2]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 9 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 14, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 14, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 48, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 18, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 49, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 20, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 50, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 23, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 1 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 14 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 25, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 2 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 15 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 26, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6653, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 28, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6654, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 30, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6655, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 32, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6656, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 34, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6657, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 36, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 6658, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 38, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 51, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 40, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 52, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 42, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 2, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 53, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 45, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 4 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 16 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 47, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 10, 0, 0, 5 }, array); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 17 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 49, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 1, 2, 3, 4, 5 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 4, 0, 0, 6 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 51, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 12, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 3 }, array); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 6, 0, 0, 4 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 53, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 32, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 55, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 32, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }, array); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 57, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 8, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 58, out.readUnsignedInt()); array = new byte[4]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 1, 0, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 58, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 59, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 60, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 60, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 62, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); array = new byte[16]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 64, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 1, 0, 3, 0, 0, 6 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 66, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); array = new byte[6]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 4, 0, 2, 0, 0, 8 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 68, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 61, out.readUnsignedInt()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 70, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 62, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 72, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 75, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 6, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 64, out.readUnsignedMedium()); array = new byte[3]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry mask", new byte[] { 0, 1, 2 }, array); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 77, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 16, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 1L, out.readLong()); Assert.assertEquals("Wrong match entry mask", 2L, out.readLong()); Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort()); Assert.assertEquals("Wrong match entry field & hasMask", 79, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte()); Assert.assertEquals("Wrong match entry value", 358, out.readUnsignedShort()); array = new byte[2]; out.readBytes(array); Assert.assertArrayEquals("Wrong match entry value", new byte[] { 0, 2 }, array); Assert.assertTrue("Wrong padding", out.readableBytes() == 4); }
From source file:org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser.java
License:Open Source License
/** * Parses common parts for Link State Nodes, Links and Prefixes, that includes protocol ID and identifier tlv. * * @param nlri as byte array/*from w w w . ja va2 s . co m*/ * @param isVpn flag which determines that destination has route distinguisher * @return {@link CLinkstateDestination} * @throws BGPParsingException if parsing was unsuccessful */ public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException { final List<CLinkstateDestination> dests = new ArrayList<>(); while (nlri.isReadable()) { final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder(); final NlriType type = NlriType.forValue(nlri.readUnsignedShort()); // length means total length of the tlvs including route distinguisher not including the type field final int length = nlri.readUnsignedShort(); RouteDistinguisher distinguisher = null; if (isVpn) { // this parses route distinguisher distinguisher = new RouteDistinguisher(BigInteger.valueOf(nlri.readLong())); builder.setDistinguisher(distinguisher); } // parse source protocol final ProtocolId sp = ProtocolId.forValue(nlri.readByte()); builder.setProtocolId(sp); // parse identifier final Identifier identifier = new Identifier(BigInteger.valueOf(nlri.readLong())); builder.setIdentifier(identifier); // if we are dealing with linkstate nodes/links, parse local node descriptor org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.NodeIdentifier localDescriptor = null; ByteBuf rest = null; if (!type.equals(NlriType.Ipv4TeLsp) && !type.equals(NlriType.Ipv6TeLsp)) { final int localtype = nlri.readUnsignedShort(); final int locallength = nlri.readUnsignedShort(); if (localtype == LOCAL_NODE_DESCRIPTORS_TYPE) { localDescriptor = NodeNlriParser.parseNodeDescriptors(nlri.readSlice(locallength), type, true); } final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH - TYPE_LENGTH - LENGTH_SIZE - locallength; LOG.trace("Restlength {}", restLength); rest = nlri.readSlice(restLength); } setObjectType(nlri, builder, type, localDescriptor, rest); dests.add(builder.build()); } return dests; }
From source file:org.opendaylight.protocol.bgp.linkstate.spi.AbstractNlriTypeCodec.java
License:Open Source License
@Override public final CLinkstateDestination parseTypeNlri(final ByteBuf nlri) { final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder(); builder.setProtocolId(ProtocolId.forValue(nlri.readUnsignedByte())); builder.setIdentifier(new Identifier(BigInteger.valueOf(nlri.readLong()))); builder.setObjectType(parseObjectType(nlri)); return builder.build(); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.AigpAttributeParser.java
License:Open Source License
/** * Reads data from buffer until reaches TLV of type AIGP TLV. * * @param buffer TLVs in ByteBuf format/*from www.java2 s .com*/ * @return instance of AigpTlv class or null if buffer contains unknown TLV type */ private static AigpTlv parseAigpTLV(final ByteBuf buffer) { final int tlvType = buffer.readByte(); buffer.skipBytes(TLV_SIZE_IN_BYTES); if (tlvType != AIGP_TLV_TYPE) { LOG.warn("AIGP attribute contains unknown TLV type {}.", tlvType); return null; } return new AigpTlvBuilder().setMetric(new AccumulatedIgpMetric(BigInteger.valueOf(buffer.readLong()))) .build(); }