Skip to content
Snippets Groups Projects
Commit 7390524f authored by Mandeep Dhami's avatar Mandeep Dhami
Browse files

Added more instrumentation on receiving curroupted packets

parent d0aec691
No related branches found
No related tags found
No related merge requests found
......@@ -113,7 +113,19 @@ public class BasicFactory implements OFMessageFactory, OFActionFactory,
return ofm;
} catch (Exception e) {
throw new MessageParseException(e);
/* Write the offending data along with the error message */
data.resetReaderIndex();
int len = data.readableBytes();
StringBuffer sb = new StringBuffer();
for (int i=0 ; i<len; i++) {
sb.append(String.format(" %02x", data.getUnsignedByte(i)));
if (i%16 == 15) sb.append("\n");
}
String msg =
"Message Parse Error for packet: " + sb.toString() +
"\nException: " + e.toString();
throw new MessageParseException(msg, e);
}
}
......
......@@ -15,6 +15,7 @@ public class MessageParseException extends Exception {
public MessageParseException(String message, Throwable cause) {
super(message, cause);
this.setStackTrace(cause.getStackTrace());
}
public MessageParseException(String message) {
......@@ -23,5 +24,6 @@ public class MessageParseException extends Exception {
public MessageParseException(Throwable cause) {
super(cause);
this.setStackTrace(cause.getStackTrace());
}
}
......@@ -28,6 +28,7 @@ import org.openflow.util.U16;
import junit.framework.TestCase;
public class BasicFactoryTest extends TestCase {
public void testCreateAndParse() throws MessageParseException {
BasicFactory factory = new BasicFactory();
OFMessage m = factory.getMessage(OFType.HELLO);
......@@ -46,4 +47,34 @@ public class BasicFactoryTest extends TestCase {
TestCase.assertEquals(message.size(), 1);
TestCase.assertTrue(message.get(0).getType() == OFType.ECHO_REQUEST);
}
public void testInvalidMsgParse() throws MessageParseException {
BasicFactory factory = new BasicFactory();
OFMessage m = factory.getMessage(OFType.HELLO);
m.setVersion((byte) 1);
m.setType(OFType.ECHO_REQUEST);
m.setLength(U16.t(16));
m.setXid(0xdeadbeef);
ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
m.writeTo(bb);
List<OFMessage> message = factory.parseMessage(bb);
TestCase.assertNull(message);
}
public void testCurrouptedMsgParse() throws MessageParseException {
BasicFactory factory = new BasicFactory();
OFMessage m = factory.getMessage(OFType.HELLO);
m.setVersion((byte) 1);
m.setType(OFType.ERROR);
m.setLength(U16.t(8));
m.setXid(0xdeadbeef);
ChannelBuffer bb = ChannelBuffers.dynamicBuffer();
m.writeTo(bb);
try {
factory.parseMessage(bb);
}
catch(Exception e) {
TestCase.assertEquals(MessageParseException.class, e.getClass());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment