use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.
the class PacketReceivedTranslator method translate.
@Override
public PacketReceived translate(final PacketInMessage input, final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
PacketReceivedBuilder packetReceivedBuilder = new PacketReceivedBuilder();
BigInteger datapathId = deviceInfo.getDatapathId();
// TODO: connection cookie from connection distinguisher
packetReceivedBuilder.setPayload(input.getData());
// get the Cookie if it exists
if (input.getCookie() != null) {
packetReceivedBuilder.setFlowCookie(new FlowCookie(input.getCookie()));
}
// Try to create the NodeConnectorRef
BigInteger dataPathId = deviceInfo.getDatapathId();
NodeConnectorRef nodeConnectorRef = NodeConnectorRefToPortTranslator.toNodeConnectorRef(input, dataPathId);
// If we was able to create NodeConnectorRef, use it
if (nodeConnectorRef != null) {
packetReceivedBuilder.setIngress(nodeConnectorRef);
}
packetReceivedBuilder.setPacketInReason(PacketInUtil.getMdSalPacketInReason(input.getReason()));
if (input.getTableId() != null) {
packetReceivedBuilder.setTableId(new TableId(input.getTableId().getValue().shortValue()));
}
if (input.getMatch() != null) {
org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.Match packetInMatch = getPacketInMatch(input, datapathId);
packetReceivedBuilder.setMatch(packetInMatch);
}
return packetReceivedBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.
the class PacketInDispatcherImpl method onPacketReceived.
@Override
public void onPacketReceived(PacketReceived notification) {
// find corresponding handler
/*
* Notification contains reference to ingress port
* in a form of path in inventory: /nodes/node/node-connector
*
* In order to get path we shorten path to the first node reference
* by using firstIdentifierOf helper method provided by InstanceIdentifier,
* this will effectively shorten the path to /nodes/node.
*/
InstanceIdentifier<?> ingressPort = notification.getIngress().getValue();
InstanceIdentifier<Node> nodeOfPacket = ingressPort.firstIdentifierOf(Node.class);
/**
* We lookup up the the packet-in listener for this node.
*/
PacketProcessingListener nodeHandler = handlerMapping.get(nodeOfPacket);
/**
* If we have packet-processing listener, we delegate notification.
*/
if (nodeHandler != null) {
nodeHandler.onPacketReceived(notification);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.
the class AbstractDropTest method processPacket.
@SuppressWarnings("checkstyle:IllegalCatch")
private void processPacket(final PacketReceived notification) {
try {
final byte[] rawPacket = notification.getPayload();
final byte[] srcMac = Arrays.copyOfRange(rawPacket, 6, 12);
final MatchBuilder match = new MatchBuilder();
final EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder();
final EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder();
// TODO: use HEX, use binary form
// Hex.decodeHex("000000000001".toCharArray());
ethSourceBuilder.setAddress(new MacAddress(macAddressToString(srcMac)));
ethernetMatch.setEthernetSource(ethSourceBuilder.build());
match.setEthernetMatch(ethernetMatch.build());
// Get the Ingress nodeConnectorRef
final NodeConnectorRef ncr = notification.getIngress();
// Get the instance identifier for the nodeConnectorRef
final InstanceIdentifier<?> ncri = ncr.getValue();
processPacket(ncri.firstIdentifierOf(Node.class), match.build(), DROP_INSTRUCTIONS);
SENT_UPDATER.incrementAndGet(this);
} catch (RuntimeException e) {
LOG.warn("Failed to process packet: {}", e.getMessage());
LOG.debug("Failed to process packet.. ", e);
EXCS_UPDATER.incrementAndGet(this);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project openflowplugin by opendaylight.
the class LearningSwitchHandlerSimpleImpl method onPacketReceived.
@Override
public void onPacketReceived(PacketReceived notification) {
if (!isLearning) {
// ignoring packets - this should not happen
return;
}
LOG.debug("Received packet via match: {}", notification.getMatch());
// detect and compare node - we support one switch
if (!nodePath.contains(notification.getIngress().getValue())) {
return;
}
// read src MAC and dst MAC
byte[] dstMacRaw = PacketUtils.extractDstMac(notification.getPayload());
byte[] srcMacRaw = PacketUtils.extractSrcMac(notification.getPayload());
byte[] etherType = PacketUtils.extractEtherType(notification.getPayload());
MacAddress dstMac = PacketUtils.rawMacToMac(dstMacRaw);
MacAddress srcMac = PacketUtils.rawMacToMac(srcMacRaw);
NodeConnectorKey ingressKey = InstanceIdentifierUtils.getNodeConnectorKey(notification.getIngress().getValue());
LOG.debug("Received packet from MAC match: {}, ingress: {}", srcMac, ingressKey.getId());
LOG.debug("Received packet to MAC match: {}", dstMac);
LOG.debug("Ethertype: {}", Integer.toHexString(0x0000ffff & ByteBuffer.wrap(etherType).getShort()));
// learn by IPv4 traffic only
if (Arrays.equals(ETH_TYPE_IPV4, etherType)) {
NodeConnectorRef previousPort = mac2portMapping.put(srcMac, notification.getIngress());
if (previousPort != null && !notification.getIngress().equals(previousPort)) {
NodeConnectorKey previousPortKey = InstanceIdentifierUtils.getNodeConnectorKey(previousPort.getValue());
LOG.debug("mac2port mapping changed by mac {}: {} -> {}", srcMac, previousPortKey, ingressKey.getId());
}
// if dst MAC mapped:
NodeConnectorRef destNodeConnector = mac2portMapping.get(dstMac);
if (destNodeConnector != null) {
synchronized (coveredMacPaths) {
if (!destNodeConnector.equals(notification.getIngress())) {
// add flow
addBridgeFlow(srcMac, dstMac, destNodeConnector);
addBridgeFlow(dstMac, srcMac, notification.getIngress());
} else {
LOG.debug("useless rule ignoring - both MACs are behind the same port");
}
}
LOG.debug("packetIn-directing.. to {}", InstanceIdentifierUtils.getNodeConnectorKey(destNodeConnector.getValue()).getId());
sendPacketOut(notification.getPayload(), notification.getIngress(), destNodeConnector);
} else {
// flood
LOG.debug("packetIn-still flooding.. ");
flood(notification.getPayload(), notification.getIngress());
}
} else {
// non IPv4 package
flood(notification.getPayload(), notification.getIngress());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project genius by opendaylight.
the class ArpUtilTestUtil method createPayload.
public static PacketReceived createPayload(int oc) {
final short ID = 2;
byte[] payload = bytePayload(// Destination MAC
"1F 1F 1F 1F 1F 1F", // Source MAC
"00 01 02 03 04 05", // Ethernet type
"08 06", // Hardware type
"0 1", // Protocol type
"8 0", // Hardware size
"6", // Protocol size
"4", // Opcode
OP_CODE[oc], // Sender MAC Address
"00 01 02 03 04 05", // Sender IP Address
"C0 A8 0 2", // Target MAC Address
"00 01 02 03 04 05", // Target IP Address
"C0 A8 0 2");
return new PacketReceivedBuilder().setPacketInReason(SendToController.class).setTableId(new TableId(ID)).setPayload(payload).setIngress(new NodeConnectorRef(InstanceIdentifier.create(Node.class))).setMatch(new MatchBuilder().setMetadata(new MetadataBuilder().setMetadata(META_DATA).build()).build()).build();
}
Aggregations