use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.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();
}
Aggregations