import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.ethernet.rev140528.ethernet.packet.received.packet.chain.packet.EthernetPacket;
/**
- * This class listens to certain type of packets and writes
- * a mac to mac flows.
+ * This class listens to certain type of packets and writes a mac to mac flows.
*/
public class ReactiveFlowWriter implements ArpPacketListener {
- private InventoryReader inventoryReader;
- private FlowWriterService flowWriterService;
+ private InventoryReader inventoryReader;
+ private FlowWriterService flowWriterService;
- public ReactiveFlowWriter(InventoryReader inventoryReader, FlowWriterService flowWriterService) {
- this.inventoryReader = inventoryReader;
- this.flowWriterService = flowWriterService;
- }
-
- /**
- * Checks if a MAC should be considered for flow creation
- *
- * @param macToCheck MacAddress to consider
- * @return true if a MacAddess is broadcast or multicast, false if
- * the MacAddress is unicast (and thus legible for flow creation).
- */
-
- private boolean ignoreThisMac(MacAddress macToCheck) {
- if (macToCheck == null) return true;
- String [] octets = macToCheck.getValue().split(":");
- short first_byte = Short.parseShort(octets[0], 16);
+ public ReactiveFlowWriter(InventoryReader inventoryReader, FlowWriterService flowWriterService) {
+ this.inventoryReader = inventoryReader;
+ this.flowWriterService = flowWriterService;
+ }
- /* First bit in first byte for unicast and multicast is 1
- * Unicast and multicast are handled by flooding, they are
- * not legible for flow creation
+ /**
+ * Checks if a MAC should be considered for flow creation
+ *
+ * @param macToCheck
+ * MacAddress to consider
+ * @return true if a MacAddess is broadcast or multicast, false if the
+ * MacAddress is unicast (and thus legible for flow creation).
*/
- return ((first_byte & 1) == 1);
- }
+ private boolean ignoreThisMac(MacAddress macToCheck) {
+ if (macToCheck == null)
+ return true;
+ String[] octets = macToCheck.getValue().split(":");
+ short first_byte = Short.parseShort(octets[0], 16);
- @Override
- public void onArpPacketReceived(ArpPacketReceived packetReceived) {
- if(packetReceived == null || packetReceived.getPacketChain() == null) {
- return;
- }
+ /*
+ * First bit in first byte for unicast and multicast is 1 Unicast and
+ * multicast are handled by flooding, they are not legible for flow
+ * creation
+ */
- RawPacket rawPacket = null;
- EthernetPacket ethernetPacket = null;
- ArpPacket arpPacket = null;
- for(PacketChain packetChain : packetReceived.getPacketChain()) {
- if(packetChain.getPacket() instanceof RawPacket) {
- rawPacket = (RawPacket) packetChain.getPacket();
- } else if(packetChain.getPacket() instanceof EthernetPacket) {
- ethernetPacket = (EthernetPacket) packetChain.getPacket();
- } else if(packetChain.getPacket() instanceof ArpPacket) {
- arpPacket = (ArpPacket) packetChain.getPacket();
- }
+ return ((first_byte & 1) == 1);
}
- if(rawPacket == null || ethernetPacket == null || arpPacket == null) {
- return;
- }
- MacAddress destMac = ethernetPacket.getDestinationMac();
- if(!ignoreThisMac(destMac)) {
- writeFlows(rawPacket.getIngress(),
- ethernetPacket.getSourceMac(),
- ethernetPacket.getDestinationMac());
+
+ @Override
+ public void onArpPacketReceived(ArpPacketReceived packetReceived) {
+ if (packetReceived == null || packetReceived.getPacketChain() == null) {
+ return;
+ }
+
+ RawPacket rawPacket = null;
+ EthernetPacket ethernetPacket = null;
+ ArpPacket arpPacket = null;
+ for (PacketChain packetChain : packetReceived.getPacketChain()) {
+ if (packetChain.getPacket() instanceof RawPacket) {
+ rawPacket = (RawPacket) packetChain.getPacket();
+ } else if (packetChain.getPacket() instanceof EthernetPacket) {
+ ethernetPacket = (EthernetPacket) packetChain.getPacket();
+ } else if (packetChain.getPacket() instanceof ArpPacket) {
+ arpPacket = (ArpPacket) packetChain.getPacket();
+ }
+ }
+ if (rawPacket == null || ethernetPacket == null || arpPacket == null) {
+ return;
+ }
+ MacAddress destMac = ethernetPacket.getDestinationMac();
+ if (!ignoreThisMac(destMac)) {
+ writeFlows(rawPacket.getIngress(), ethernetPacket.getSourceMac(), ethernetPacket.getDestinationMac());
+ }
}
- }
- /**
- * Invokes flow writer service to write bidirectional mac-mac flows on a switch.
- *
- * @param ingress The NodeConnector where the payload came from.
- * @param srcMac The source MacAddress of the packet.
- * @param destMac The destination MacAddress of the packet.
- */
- public void writeFlows(NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) {
- NodeConnectorRef destNodeConnector = inventoryReader.getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac);
- if(destNodeConnector != null) {
- flowWriterService.addBidirectionalMacToMacFlows(srcMac, ingress, destMac, destNodeConnector);
+ /**
+ * Invokes flow writer service to write bidirectional mac-mac flows on a
+ * switch.
+ *
+ * @param ingress
+ * The NodeConnector where the payload came from.
+ * @param srcMac
+ * The source MacAddress of the packet.
+ * @param destMac
+ * The destination MacAddress of the packet.
+ */
+ public void writeFlows(NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) {
+ NodeConnectorRef destNodeConnector = inventoryReader
+ .getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac);
+ if (destNodeConnector != null) {
+ flowWriterService.addBidirectionalMacToMacFlows(srcMac, ingress, destMac, destNodeConnector);
+ }
}
- }
}