use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn in project openflowplugin by opendaylight.
the class DeviceContextImpl method handlePacketInMessage.
private void handlePacketInMessage(final PacketIn packetIn, final Class<?> implementedInterface, final Match match) {
messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH);
final ConnectionAdapter connectionAdapter = getPrimaryConnectionContext().getConnectionAdapter();
if (packetIn == null) {
LOG.debug("Received a null packet from switch {}", connectionAdapter.getRemoteAddress());
messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_SRC_FAILURE);
return;
}
final OpenflowVersion openflowVersion = OpenflowVersion.get(deviceInfo.getVersion());
// Try to get ingress from match
final NodeConnectorRef nodeConnectorRef = Objects.nonNull(packetIn.getIngress()) ? packetIn.getIngress() : Optional.ofNullable(match).map(Match::getInPort).map(nodeConnectorId -> InventoryDataServiceUtil.portNumberfromNodeConnectorId(openflowVersion, nodeConnectorId)).map(portNumber -> InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(deviceInfo.getDatapathId(), portNumber, openflowVersion)).orElse(null);
messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
if (!packetInLimiter.acquirePermit()) {
LOG.debug("Packet limited");
// TODO: save packet into emergency slot if possible
messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PACKET_IN_LIMIT_REACHED_AND_DROPPED);
return;
}
final ListenableFuture<?> offerNotification = notificationPublishService.offerNotification(new PacketReceivedBuilder(packetIn).setIngress(nodeConnectorRef).setMatch(MatchUtil.transformMatch(match, org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match.class)).build());
if (NotificationPublishService.REJECTED.equals(offerNotification)) {
LOG.debug("notification offer rejected");
messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
packetInLimiter.drainLowWaterMark();
packetInLimiter.releasePermit();
return;
}
Futures.addCallback(offerNotification, new FutureCallback<Object>() {
@Override
public void onSuccess(final Object result) {
messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS);
packetInLimiter.releasePermit();
}
@Override
public void onFailure(final Throwable throwable) {
messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
LOG.debug("notification offer failed: {}", throwable.getMessage());
LOG.trace("notification offer failed..", throwable);
packetInLimiter.releasePermit();
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn in project openflowplugin by opendaylight.
the class NodeConnectorRefToPortTranslator method toNodeConnectorRef.
/**
* Converts {@link PacketIn} to {@link NodeConnectorRef}.
* @param packetIn Packet input
* @param dataPathId Data path id
* @return packet input converted to node connector reference
*/
@Nullable
public static NodeConnectorRef toNodeConnectorRef(@Nonnull PacketIn packetIn, BigInteger dataPathId) {
Preconditions.checkNotNull(packetIn);
NodeConnectorRef ref = null;
Long port = getPortNoFromPacketIn(packetIn);
if (port != null) {
OpenflowVersion version = OpenflowVersion.get(packetIn.getVersion());
ref = InventoryDataServiceUtil.nodeConnectorRefFromDatapathIdPortno(dataPathId, port, version);
}
return ref;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn in project openflowplugin by opendaylight.
the class NodeConnectorRefToPortTranslatorTest method testGetPortNoFromPacketIn.
@Test
public void testGetPortNoFromPacketIn() throws Exception {
PacketIn packetIn = createPacketIn(PORT_NO);
Long portNo = NodeConnectorRefToPortTranslator.getPortNoFromPacketIn(packetIn);
assertEquals(portNo, PORT_NO);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn in project openflowplugin by opendaylight.
the class NodeConnectorRefToPortTranslatorTest method testNodeConnectorConversion.
@Test
public void testNodeConnectorConversion() throws Exception {
// Mock the packet in message
PacketIn packetIn = createPacketIn(PORT_NO);
// Convert PacketIn to NodeConnectorRef
NodeConnectorRef ref = NodeConnectorRefToPortTranslator.toNodeConnectorRef(packetIn, DATA_PATH_ID);
// Get port number from created NodeConnectorRef
Long refPort = NodeConnectorRefToPortTranslator.fromNodeConnectorRef(ref, OF_VERSION);
// Check if we got the correct port number
assertEquals(PORT_NO, refPort);
// Check if 2 NodeConnectorRef created from same PacketIn have same value
assertEquals(ref, NodeConnectorRefToPortTranslator.toNodeConnectorRef(packetIn, DATA_PATH_ID));
// Check if 2 NodeConnectorRef created from same PacketIn but different datapaths do not have same value
assertNotSame(ref, NodeConnectorRefToPortTranslator.toNodeConnectorRef(packetIn, BigInteger.ONE));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn in project openflowplugin by opendaylight.
the class NodeConnectorRefToPortTranslatorTest method createPacketIn.
private static PacketIn createPacketIn(long portNo) {
InPortBuilder inPortBuilder = new InPortBuilder().setPortNumber(new PortNumber(portNo));
InPortCaseBuilder caseBuilder = new InPortCaseBuilder().setInPort(inPortBuilder.build());
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder().setOxmClass(OpenflowBasicClass.class).setOxmMatchField(InPort.class).setHasMask(false).setMatchEntryValue(caseBuilder.build());
MatchBuilder matchBuilder = new MatchBuilder().setMatchEntry(Lists.newArrayList(matchEntryBuilder.build()));
return new PacketInMessageBuilder().setVersion(OFConstants.OFP_VERSION_1_0).setData(PACKET_DATA.getBytes()).setReason(PacketInReason.OFPRACTION).setMatch(matchBuilder.build()).setVersion(OFConstants.OFP_VERSION_1_3).setCookie(BigInteger.ZERO).setTableId(new TableId(TABLE_ID)).build();
}
Aggregations