Skip to content

Commit

Permalink
Adding additional debug messages using OFMessageFilterManager functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Srinivasan Ramasubramanian committed Dec 31, 2011
1 parent b7f2ee8 commit 8bfbb08
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,17 @@ public HashSet<String> getMatchedFilters(OFMessage m, FloodlightContext cntx) {
if (m.getType() == OFType.PACKET_IN) {
eth = IFloodlightProvider.bcStore.get(cntx,
IFloodlightProvider.CONTEXT_PI_PAYLOAD);


} else if (m.getType() == OFType.PACKET_OUT) {
eth = new Ethernet();
OFPacketOut p = (OFPacketOut) m;
eth.deserialize(p.getPacketData(), 0, p.getPacketData().length);

// No MAC match if packetOut doesn't have the packet.
if (p.getPacketData() == null) return null;

eth.deserialize(p.getPacketData(), 0, p.getPacketData().length);
} else if (m.getType() == OFType.FLOW_MOD) {
// no action performed.
// flow-mod can't be matched by mac.
return null;
}

if (eth == null) return null;
Expand All @@ -238,10 +240,11 @@ public HashSet<String> getMatchedFilters(OFMessage m, FloodlightContext cntx) {
while (fieldIt.hasNext()) {
String filterFieldType = fieldIt.next();
String filterFieldValue = filter.get(filterFieldType);
if (filterFieldType == "mac") {
if (filterFieldType.equals("mac")) {

String srcMac = HexString.toHexString(eth.getSourceMACAddress());
String dstMac = HexString.toHexString(eth.getDestinationMACAddress());
log.debug("srcMac: {}, dstMac: {}", srcMac, dstMac);

if (filterFieldValue.equals(srcMac) ||
filterFieldValue.equals(dstMac)){
Expand Down Expand Up @@ -343,7 +346,7 @@ public boolean isCallbackOrderingPrereq(OFType type, String name) {

@Override
public boolean isCallbackOrderingPostreq(OFType type, String name) {
return false;
return (type == OFType.PACKET_IN && name.equals("learningswitch"));
}

@Override
Expand All @@ -368,7 +371,7 @@ public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
log.error("sendPacket exception: {}", e);
}
}

return Command.CONTINUE;
}

Expand Down Expand Up @@ -421,7 +424,6 @@ protected void sendPacket(HashSet<String> matchedFilters, IOFSwitch sw,
OFPacketIn pktIn = (OFPacketIn)msg;
packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), pktIn.getInPort()));
bb = ChannelBuffers.buffer(pktIn.getLength());
log.debug("Packet-In length is: {}", pktIn.getLength());
pktIn.writeTo(bb);
packet.setData(getData(sw, msg, cntx));
break;
Expand Down Expand Up @@ -473,7 +475,7 @@ protected void sendPacket(HashSet<String> matchedFilters, IOFSwitch sw,
}
}

private byte[] getData(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
public String getDataAsString(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {

Ethernet eth;
StringBuffer sb = new StringBuffer("");
Expand All @@ -488,7 +490,7 @@ private byte[] getData(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
case PACKET_IN:
OFPacketIn pktIn = (OFPacketIn) msg;
sb.append("packet_in [ ");
sb.append(HexString.toHexString(sw.getId()));
sb.append(sw.getStringId());
sb.append(" -> Controller");
sb.append(" ]");

Expand Down Expand Up @@ -558,10 +560,15 @@ private byte[] getData(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
}

sb.append("\n\n");
return sb.toString().getBytes();
return sb.toString();

}

public byte[] getData(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
return this.getDataAsString(sw, msg, cntx).getBytes();
}

private String getStringFromEthernetPacket(Ethernet eth) {
public String getStringFromEthernetPacket(Ethernet eth) {

StringBuffer sb = new StringBuffer("\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,16 @@ protected void handleMessage(IOFSwitch sw, OFMessage m,
eth);
}

// Print the packet-in for debugging purposes at this point
// The context would have the necessary information for
// the OFMessageFilterManager's getDataToString to work
// for packet-ins.
if (log.isDebugEnabled()) {
String str = messageFilterManager.getDataAsString(sw, m, bc);
log.debug("{}", str);
}


// Get the starting time (overall and per-component) of
// the processing chain for this packet if performance
// monitoring is turned on
Expand Down Expand Up @@ -785,7 +795,6 @@ protected void handleMessage(IOFSwitch sw, OFMessage m,
} else {
log.error("Unhandled OF Message: {} from {}", m, sw);
}
break;
}
}

Expand Down Expand Up @@ -1001,6 +1010,11 @@ public boolean injectOfMessage(IOFSwitch sw, OFMessage msg) {
@Override
public void handleOutgoingMessage(IOFSwitch sw, OFMessage m,
FloodlightContext bc) {
if (log.isDebugEnabled()) {
String str = messageFilterManager.getDataAsString(sw, m, bc);
log.debug("{}", str);
}

List<IOFMessageListener> listeners = null;
if (messageListeners.containsKey(m.getType())) {
listeners =
Expand Down Expand Up @@ -1312,7 +1326,7 @@ protected void run() {
final ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool(), 1));
Executors.newCachedThreadPool()));

bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void testHandleMessages() throws Exception {
reset(test1, test2, sw);
expect(test1.receive(eq(sw), eq(pi), isA(FloodlightContext.class))).andReturn(Command.STOP);
expect(test1.getId()).andReturn(0).anyTimes();
expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00");
expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
expect(sw.getFeaturesReply()).andReturn(new OFFeaturesReply()).anyTimes();
replay(test1, test2, sw);
controller.handleMessage(sw, pi, null);
Expand Down

0 comments on commit 8bfbb08

Please sign in to comment.