From f9348fbdc543a48ac7575b6f9498bdeb23691561 Mon Sep 17 00:00:00 2001 From: Madhavan Kasthurirangan Date: Mon, 6 May 2013 11:38:07 -0700 Subject: [PATCH] Logging enhancement related to Packet Signed-off-by: Madhavan Kasthurirangan --- .../openflow/internal/DataPacketMuxDemux.java | 68 ++++++++------ .../controller/sal/packet/LLDP.java | 5 ++ .../controller/sal/packet/Packet.java | 9 +- .../controller/sal/packet/RawPacket.java | 90 ++++++++++--------- 4 files changed, 102 insertions(+), 70 deletions(-) diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java index cc8bcfa6b9..a8ebcb068b 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DataPacketMuxDemux.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -44,6 +43,7 @@ import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService; import org.opendaylight.controller.sal.packet.PacketResult; import org.opendaylight.controller.sal.packet.RawPacket; import org.opendaylight.controller.sal.utils.GlobalConstants; +import org.opendaylight.controller.sal.utils.HexEncode; public class DataPacketMuxDemux implements IContainerListener, IMessageListener, IDataPacketMux, IInventoryShimExternalListener { @@ -53,7 +53,8 @@ public class DataPacketMuxDemux implements IContainerListener, private ConcurrentMap swID2ISwitch = new ConcurrentHashMap(); // Gives a map between a Container and all the DataPacket listeners on SAL private ConcurrentMap pluginOutDataPacketServices = new ConcurrentHashMap(); - // Gives a map between a NodeConnector and the containers to which it belongs + // Gives a map between a NodeConnector and the containers to which it + // belongs private ConcurrentMap> nc2Container = new ConcurrentHashMap>(); // Gives a map between a Container and the FlowSpecs on it private ConcurrentMap> container2FlowSpecs = new ConcurrentHashMap>(); @@ -130,17 +131,17 @@ public class DataPacketMuxDemux implements IContainerListener, /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ void init() { this.controller.addMessageListener(OFType.PACKET_IN, this); } /** - * Function called by the dependency manager when at least one - * dependency become unsatisfied or when the component is shutting - * down because for example bundle is being stopped. - * + * Function called by the dependency manager when at least one dependency + * become unsatisfied or when the component is shutting down because for + * example bundle is being stopped. + * */ void destroy() { this.controller.removeMessageListener(OFType.PACKET_IN, this); @@ -158,8 +159,9 @@ public class DataPacketMuxDemux implements IContainerListener, if (sw == null || msg == null || this.pluginOutDataPacketServices == null) { // Something fishy, we cannot do anything - logger.debug("sw: {} and/or msg: {} and/or pluginOutDataPacketServices: {} is null!", - new Object[]{sw, msg, this.pluginOutDataPacketServices}); + logger.debug( + "sw: {} and/or msg: {} and/or pluginOutDataPacketServices: {} is null!", + new Object[] { sw, msg, this.pluginOutDataPacketServices }); return; } if (msg instanceof OFPacketIn) { @@ -193,11 +195,16 @@ public class DataPacketMuxDemux implements IContainerListener, .get(GlobalConstants.DEFAULT.toString()); if (defaultOutService != null) { defaultOutService.receiveDataPacket(dataPacket); - logger.trace("Dispatched to apps a frame of size: {} on container: {}", - ofPacket.getPacketData().length, GlobalConstants.DEFAULT.toString()); + logger.trace( + "Dispatched to apps a frame of size: {} on container: {}: {}", + new Object[] { + ofPacket.getPacketData().length, + GlobalConstants.DEFAULT.toString(), + HexEncode.bytesToHexString(dataPacket + .getPacketData()) }); } // Now check the mapping between nodeConnector and - // Container and later on optinally filter based on + // Container and later on optimally filter based on // flowSpec List containersRX = this.nc2Container.get(p); if (containersRX != null) { @@ -208,8 +215,14 @@ public class DataPacketMuxDemux implements IContainerListener, if (s != null) { // TODO add filtering on a per-flowSpec base s.receiveDataPacket(dataPacket); - logger.trace("Dispatched to apps a frame of size: {} on container: {}", - ofPacket.getPacketData().length, GlobalConstants.DEFAULT.toString()); + logger.trace( + "Dispatched to apps a frame of size: {} on container: {}: {}", + new Object[] { + ofPacket.getPacketData().length, + GlobalConstants.DEFAULT.toString(), + HexEncode + .bytesToHexString(dataPacket + .getPacketData()) }); } } @@ -233,20 +246,20 @@ public class DataPacketMuxDemux implements IContainerListener, public void transmitDataPacket(RawPacket outPkt) { // Sanity check area if (outPkt == null) { - logger.debug("outPkt is null!"); + logger.debug("outPkt is null!"); return; } NodeConnector outPort = outPkt.getOutgoingNodeConnector(); if (outPort == null) { - logger.debug("outPort is null! outPkt: {}", outPkt); + logger.debug("outPort is null! outPkt: {}", outPkt); return; } if (!outPort.getType().equals( NodeConnector.NodeConnectorIDType.OPENFLOW)) { // The output Port is not of type OpenFlow - logger.debug("outPort is not OF Type! outPort: {}", outPort); + logger.debug("outPort is not OF Type! outPort: {}", outPort); return; } @@ -257,7 +270,7 @@ public class DataPacketMuxDemux implements IContainerListener, if (sw == null) { // If we cannot get the controller descriptor we cannot even // send out the frame - logger.debug("swID: {} - sw is null!", swID); + logger.debug("swID: {} - sw is null!", swID); return; } @@ -265,8 +278,9 @@ public class DataPacketMuxDemux implements IContainerListener, // build action OFActionOutput action = new OFActionOutput().setPort(port); // build packet out - OFPacketOut po = new OFPacketOut().setBufferId( - OFPacketOut.BUFFER_ID_NONE).setInPort(OFPort.OFPP_NONE) + OFPacketOut po = new OFPacketOut() + .setBufferId(OFPacketOut.BUFFER_ID_NONE) + .setInPort(OFPort.OFPP_NONE) .setActions(Collections.singletonList((OFAction) action)) .setActionsLength((short) OFActionOutput.MINIMUM_LENGTH); @@ -280,30 +294,30 @@ public class DataPacketMuxDemux implements IContainerListener, public void addNode(Node node, Set props) { if (node == null) { - logger.debug("node is null!"); + logger.debug("node is null!"); return; - } + } long sid = (Long) node.getID(); ISwitch sw = controller.getSwitches().get(sid); if (sw == null) { - logger.debug("sid: {} - sw is null!", sid); - return; + logger.debug("sid: {} - sw is null!", sid); + return; } this.swID2ISwitch.put(sw.getId(), sw); } public void removeNode(Node node) { if (node == null) { - logger.debug("node is null!"); + logger.debug("node is null!"); return; } long sid = (Long) node.getID(); ISwitch sw = controller.getSwitches().get(sid); if (sw == null) { - logger.debug("sid: {} - sw is null!", sid); - return; + logger.debug("sid: {} - sw is null!", sid); + return; } this.swID2ISwitch.remove(sw.getId()); } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java index 1a0033ee96..5e7a214f0e 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.opendaylight.controller.sal.utils.HexEncode; import org.opendaylight.controller.sal.utils.NetUtils; /** @@ -170,6 +171,8 @@ public class LLDP extends Packet { int lldpOffset = bitOffset; // LLDP start int lldpSize = size; // LLDP size + logger.trace("LLDP: {} (offset {} bitsize {})", new Object[] { + HexEncode.bytesToHexString(data), lldpOffset, lldpSize }); /* * Deserialize the TLVs until we reach the end of the packet */ @@ -209,6 +212,8 @@ public class LLDP extends Packet { throw new PacketException(e.getMessage()); } + logger.trace("LLDP: serialized: {}", + HexEncode.bytesToHexString(serializedBytes)); return serializedBytes; } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/Packet.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/Packet.java index cdf15322e3..95f0ca8617 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/Packet.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/Packet.java @@ -109,6 +109,11 @@ public abstract class Packet { * Store the raw read value, checks the payload type and set the * payloadClass accordingly */ + logger.trace("{}: {}: {} (offset {} bitsize {})", + new Object[] { this.getClass().getSimpleName(), hdrField, + HexEncode.bytesToHexString(hdrFieldBytes), + startOffset, numBits }); + this.setHeaderField(hdrField, hdrFieldBytes); } @@ -138,7 +143,7 @@ public abstract class Packet { * packet class, into a single stream of bytes to be sent on the wire * * @return byte[] - serialized bytes - * @throws PacketException + * @throws PacketException */ public byte[] serialize() throws PacketException { @@ -184,6 +189,8 @@ public abstract class Packet { } postSerializeCustomOperation(headerBytes); + logger.trace("{}: {}", this.getClass().getSimpleName(), + HexEncode.bytesToHexString(headerBytes)); return headerBytes; } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/RawPacket.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/RawPacket.java index 00befde7f1..d518902183 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/RawPacket.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/RawPacket.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -25,11 +24,10 @@ import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.TimeStamp; /** - * - * Describe a raw Data Packet, this is how a packet is - * received from the network and how it will be transmitted. It - * essentially wraps the raw bytestream - * + * + * Describe a raw Data Packet, this is how a packet is received from the network + * and how it will be transmitted. It essentially wraps the raw bytestream + * */ public class RawPacket { private byte[] packetData; @@ -41,10 +39,10 @@ public class RawPacket { private NodeConnector outgoingNodeConnector; /** - * If the packet is being sent this parameter tells where the - * packet is sent toward - * - * + * If the packet is being sent this parameter tells where the packet is sent + * toward + * + * * @return the NodeConnector toward where the packet is being sent */ public NodeConnector getOutgoingNodeConnector() { @@ -53,9 +51,9 @@ public class RawPacket { /** * Setter method for OutGoing NodeConnector - * - * @param outgoingNodeConnector NodeConnector toward where the - * packet is travelling + * + * @param outgoingNodeConnector + * NodeConnector toward where the packet is travelling */ public void setOutgoingNodeConnector(NodeConnector outgoingNodeConnector) { this.outgoingNodeConnector = outgoingNodeConnector; @@ -63,7 +61,7 @@ public class RawPacket { /** * Return the incoming NodeConnector if the packet was received - * + * * @return NodeConnector where the packet was received from */ public NodeConnector getIncomingNodeConnector() { @@ -72,8 +70,9 @@ public class RawPacket { /** * Setter for Incoming NodeConnector - * - * @param incomingNodeConnector NodeConnector to be used and incoming one + * + * @param incomingNodeConnector + * NodeConnector to be used and incoming one */ public void setIncomingNodeConnector(NodeConnector incomingNodeConnector) { this.incomingNodeConnector = incomingNodeConnector; @@ -81,9 +80,10 @@ public class RawPacket { /** * Retrieve a given property attached to the packet, if exits of course - * - * @param key Key to retrieve the wanted property attached to the packet - * + * + * @param key + * Key to retrieve the wanted property attached to the packet + * * @return The property attached to the packet */ public Object getProps(Object key) { @@ -95,9 +95,11 @@ public class RawPacket { /** * Generic data associated to the data packet - * - * @param key key for the association - * @param value value associated to the key + * + * @param key + * key for the association + * @param value + * value associated to the key */ public void setProps(Object key, Object value) { if (this.props == null) { @@ -109,10 +111,12 @@ public class RawPacket { /** * Constructor for RawPacket - * - * @param data content of the packet as bytestream - * @param e datalink encapsulation for the packet - * + * + * @param data + * content of the packet as bytestream + * @param e + * datalink encapsulation for the packet + * */ public RawPacket(byte[] data, LinkEncap e) throws ConstructionException { if (data == null) { @@ -130,12 +134,13 @@ public class RawPacket { } /** - * Copy Constructor for RawPacket, it perform a copy of the packet - * so each packet can be modified indipendently without worrying - * that source packet content is touched - * - * @param src packet to copy data from - * + * Copy Constructor for RawPacket, it performs a copy of the packet so each + * packet can be modified independently without worrying that source packet + * content is touched + * + * @param src + * packet to copy data from + * */ public RawPacket(RawPacket src) throws ConstructionException { if (src == null) { @@ -143,8 +148,8 @@ public class RawPacket { } if (src.getPacketData() != null) { this.packetData = new byte[src.getPacketData().length]; - System.arraycopy(src.getPacketData(), 0, this.packetData, 0, src - .getPacketData().length); + System.arraycopy(src.getPacketData(), 0, this.packetData, 0, + src.getPacketData().length); } else { throw new ConstructionException("Empty packetData"); } @@ -158,9 +163,10 @@ public class RawPacket { /** * Constructor for RawPacket with Ethernet encapsulation - * - * @param data content of the packet as bytestream - * + * + * @param data + * content of the packet as bytestream + * */ public RawPacket(byte[] data) throws ConstructionException { this(data, LinkEncap.ETHERNET); @@ -168,7 +174,7 @@ public class RawPacket { /** * Read the timestamp when the packet has entered the system - * + * * @return The timestamp when the packet has entered the system */ public TimeStamp getIncomingTime() { @@ -177,9 +183,9 @@ public class RawPacket { /** * Read the packet encapsulation - * - * @return The encapsulation for the raw packet, necessary to - * start parsing the packet + * + * @return The encapsulation for the raw packet, necessary to start parsing + * the packet */ public LinkEncap getEncap() { return this.encap; @@ -187,7 +193,7 @@ public class RawPacket { /** * Get bytestream of the packet body - * + * * @return The raw bytestream composing the packet */ public byte[] getPacketData() { -- 2.36.6