Search in sources :

Example 6 with PacketInMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder in project openflowplugin by opendaylight.

the class PacketInMessageDeserializer method deserialize.

@Override
public PacketInMessage deserialize(final ByteBuf message) {
    final PacketInMessageBuilder packetInMessageBuilder = new PacketInMessageBuilder().setVersion((short) EncodeConstants.OF13_VERSION_ID).setXid(message.readUnsignedInt());
    // We are ignoring buffer id and total len as it is not specified in OpenFlowPlugin models
    message.readUnsignedInt();
    message.readUnsignedShort();
    packetInMessageBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(PacketInReason.forValue(message.readUnsignedByte()))).setTableId(new TableId(message.readUnsignedByte()));
    final byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    message.readBytes(cookie);
    packetInMessageBuilder.setFlowCookie(new FlowCookie(new BigInteger(1, cookie)));
    final OFDeserializer<Match> matchDeserializer = Preconditions.checkNotNull(registry).getDeserializer(MATCH_KEY);
    packetInMessageBuilder.setMatch(MatchUtil.transformMatch(matchDeserializer.deserialize(message), org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.in.message.Match.class));
    message.skipBytes(PADDING_IN_PACKET_IN_HEADER);
    final byte[] data = new byte[message.readableBytes()];
    message.readBytes(data);
    return packetInMessageBuilder.setPayload(data).build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessageBuilder) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) BigInteger(java.math.BigInteger)

Example 7 with PacketInMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder in project openflowplugin by opendaylight.

the class PacketReceivedTranslatorTest method createPacketInMessage.

private static PacketInMessage createPacketInMessage(final byte[] data, final long port) {
    final PacketInReason reason = PacketInReason.OFPRACTION;
    MatchEntryBuilder matchEntryBuilder = assembleMatchEntryBld(port);
    MatchBuilder packetInMatchBld = new MatchBuilder().setMatchEntry(Lists.newArrayList(matchEntryBuilder.build()));
    return new PacketInMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_0).setData(data).setReason(reason).setMatch(packetInMatchBld.build()).setVersion(OFConstants.OFP_VERSION_1_3).setCookie(BigInteger.ZERO).setTableId(new TableId(42L)).build();
}
Also used : TableId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) PacketInReason(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder)

Example 8 with PacketInMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder in project openflowplugin by opendaylight.

the class PacketReceivedTranslatorTest method testGetPacketInMatch.

@Test
public void testGetPacketInMatch() throws Exception {
    MatchEntryBuilder matchEntryBuilder = assembleMatchEntryBld(PORT_NUM_VALUE);
    MatchBuilder packetInMatchBld = new MatchBuilder().setMatchEntry(Lists.newArrayList(matchEntryBuilder.build()));
    PacketInMessageBuilder inputBld = new PacketInMessageBuilder().setMatch(packetInMatchBld.build()).setVersion(OFConstants.OFP_VERSION_1_3);
    BigInteger dpid = BigInteger.TEN;
    final PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator(convertorManager);
    final Match packetInMatch = packetReceivedTranslator.getPacketInMatch(inputBld.build(), dpid);
    Assert.assertNotNull(packetInMatch.getInPort());
    Assert.assertEquals("openflow:10:" + PORT_NUM_VALUE, packetInMatch.getInPort().getValue());
}
Also used : PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) MatchEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder) BigInteger(java.math.BigInteger) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match) Test(org.junit.Test)

Example 9 with PacketInMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder in project openflowplugin by opendaylight.

the class OF10PacketInMessageFactory method deserialize.

@Override
public PacketInMessage deserialize(final ByteBuf rawMessage) {
    PacketInMessageBuilder builder = new PacketInMessageBuilder();
    builder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setBufferId(rawMessage.readUnsignedInt());
    builder.setTotalLen(rawMessage.readUnsignedShort());
    builder.setInPort(rawMessage.readUnsignedShort());
    builder.setReason(PacketInReason.forValue(rawMessage.readUnsignedByte()));
    rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);
    int remainingBytes = rawMessage.readableBytes();
    if (remainingBytes > 0) {
        final byte[] buf = new byte[remainingBytes];
        rawMessage.readBytes(buf);
        builder.setData(buf);
    }
    return builder.build();
}
Also used : PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder)

Example 10 with PacketInMessageBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder in project openflowplugin by opendaylight.

the class ConnectionAdapterImplStatisticsTest method testMessagePassCounter.

/**
 * Test counter for pass messages to consumer (counter US_MESSAGE_PASS has to be enabled).
 */
@Test
public void testMessagePassCounter() {
    if (!statCounters.isCounterEnabled(CounterEventTypes.US_MESSAGE_PASS)) {
        Assert.fail("Counter " + CounterEventTypes.US_MESSAGE_PASS + " is not enabled");
    }
    when(channel.pipeline()).thenReturn(pipeline);
    adapter = new ConnectionAdapterImpl(channel, InetSocketAddress.createUnresolved("10.0.0.1", 6653), true, CHANNEL_OUTBOUND_QUEUE_SIZE);
    adapter.setMessageListener(messageListener);
    adapter.setSystemListener(systemListener);
    adapter.setConnectionReadyListener(readyListener);
    cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
    adapter.setResponseCache(cache);
    when(channel.disconnect()).thenReturn(channelFuture);
    DataObject message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    message = new ErrorMessageBuilder().build();
    adapter.consume(message);
    message = new ExperimenterMessageBuilder().build();
    adapter.consume(message);
    message = new FlowRemovedMessageBuilder().build();
    adapter.consume(message);
    message = new HelloMessageBuilder().build();
    adapter.consume(message);
    message = new MultipartReplyMessageBuilder().build();
    adapter.consume(message);
    message = new PacketInMessageBuilder().build();
    adapter.consume(message);
    message = new PortStatusMessageBuilder().build();
    adapter.consume(message);
    message = new EchoRequestMessageBuilder().build();
    adapter.consume(message);
    Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl consume method", 9, statCounters.getCounter(CounterEventTypes.US_MESSAGE_PASS).getCounterValue());
    adapter.disconnect();
}
Also used : ErrorMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder) ExperimenterMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder) PacketInMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) PortStatusMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder) HelloMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) FlowRemovedMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder) EchoRequestMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder) Test(org.junit.Test)

Aggregations

PacketInMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder)10 Test (org.junit.Test)6 BigInteger (java.math.BigInteger)4 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId)4 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)4 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder)4 PacketInMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)3 ByteBuf (io.netty.buffer.ByteBuf)2 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)2 EchoRequestMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder)2 ErrorMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder)2 ExperimenterMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessageBuilder)2 FlowRemovedMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder)2 HelloMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder)2 MultipartReplyMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder)2 PortStatusMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ArrayList (java.util.ArrayList)1 FlowCookie (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie)1