Search in sources :

Example 11 with MatchEntryDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey in project openflowplugin by opendaylight.

the class MatchDeserializerTest method testIpv4Address.

/**
 * Testing Ipv4 address deserialization.
 */
@Test
public void testIpv4Address() {
    ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03");
    MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, 0x8000, 12);
    key.setExperimenterId(null);
    OFDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
    MatchEntry entry = entryDeserializer.deserialize(buffer);
    Assert.assertEquals("Wrong Ipv4 address format", new Ipv4Address("0.1.2.3"), ((Ipv4DstCase) entry.getMatchEntryValue()).getIpv4Dst().getIpv4Address());
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) MatchEntryDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey) Ipv4DstCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCase) ByteBuf(io.netty.buffer.ByteBuf) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 12 with MatchEntryDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey in project openflowplugin by opendaylight.

the class MatchDeserializerTest method testHeaders.

/**
 * Testing header deserialization.
 */
@Test
public void testHeaders() {
    ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03");
    MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, 0x8000, 12);
    key.setExperimenterId(null);
    HeaderDeserializer<MatchEntry> entryDeserializer = registry.getDeserializer(key);
    MatchEntry entry = entryDeserializer.deserializeHeader(buffer);
    Assert.assertEquals("Wrong entry class", OpenflowBasicClass.class, entry.getOxmClass());
    Assert.assertEquals("Wrong entry field", Ipv4Dst.class, entry.getOxmMatchField());
    Assert.assertEquals("Wrong entry hasMask", false, entry.isHasMask());
    Assert.assertNull("Wrong Ipv4 address", entry.getMatchEntryValue());
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) MatchEntryDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 13 with MatchEntryDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey in project openflowplugin by opendaylight.

the class MatchDeserializer method deserializeEntry.

@Override
public void deserializeEntry(ByteBuf inBuffer, MatchBuilder builder) {
    if (inBuffer.readableBytes() <= 0) {
        return;
    }
    int oxmClass = inBuffer.getUnsignedShort(inBuffer.readerIndex());
    int oxmField = inBuffer.getUnsignedByte(inBuffer.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES) >>> 1;
    final MatchEntryDeserializerKey key = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, oxmClass, oxmField);
    if (oxmClass == EncodeConstants.EXPERIMENTER_VALUE) {
        long expId = inBuffer.getUnsignedInt(inBuffer.readerIndex() + EncodeConstants.SIZE_OF_SHORT_IN_BYTES + 2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        key.setExperimenterId(expId);
    }
    final MatchEntryDeserializer entryDeserializer = entryRegistry.get(key);
    if (Objects.nonNull(entryDeserializer)) {
        entryDeserializer.deserializeEntry(inBuffer, builder);
    } else {
        final OFDeserializer<MatchEntry> deserializer = registry.getDeserializer(key);
        MatchExtensionHelper.injectExtension(EncodeConstants.OF13_VERSION_ID, deserializer.deserialize(inBuffer), builder, matchPath);
    }
}
Also used : MatchEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry) MatchEntryDeserializer(org.opendaylight.openflowplugin.api.openflow.protocol.deserialization.MatchEntryDeserializer) MatchEntryDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey)

Example 14 with MatchEntryDeserializerKey

use of org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey in project openflowplugin by opendaylight.

the class CodeKeyMakerFactoryTest method testMatchEntriesKeyMaker.

/**
 * Tests {@link CodeKeyMakerFactory#createMatchEntriesKeyMaker(short)}.
 */
@Test
public void testMatchEntriesKeyMaker() {
    CodeKeyMaker keyMaker = CodeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
    Assert.assertNotNull("Null key maker", keyMaker);
    ByteBuf buffer = BufferHelper.buildBuffer("80 00 00 04 00 00 00 01");
    // skip XID
    buffer.skipBytes(4);
    MessageCodeKey codeKey = keyMaker.make(buffer);
    Assert.assertNotNull("Null key", codeKey);
    Assert.assertEquals("Wrong key", new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, 32768, 0), codeKey);
    Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}
Also used : MessageCodeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey) MatchEntryDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

MatchEntryDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey)14 Test (org.junit.Test)7 ByteBuf (io.netty.buffer.ByteBuf)6 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)5 MessageCodeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey)3 NiciraActionDeserializerKey (org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey)2 NiciraActionSerializerKey (org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey)2 MatchEntrySerializerKey (org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey)2 Nxm0Class (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Nxm0Class)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 ExperimenterActionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey)1 ExperimenterActionSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey)1 ExperimenterIdDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey)1 ExperimenterIdMeterSubTypeSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdMeterSubTypeSerializerKey)1 ExperimenterIdSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey)1 ExperimenterInstructionDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionDeserializerKey)1 ExperimenterInstructionSerializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterInstructionSerializerKey)1 MessageTypeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)1