Skip to content
Snippets Groups Projects
Commit bfcae243 authored by Gregor Maier's avatar Gregor Maier
Browse files

moved unit test for vendor ext to floodlight tree

(the actual files have been moved a while ago, I just missed the unit
tests)
parent 74a98332
No related branches found
No related tags found
No related merge requests found
package com.bigswitch.floodlight.vendor;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import org.openflow.protocol.action.OFAction;
import org.openflow.protocol.action.OFActionType;
import org.openflow.protocol.action.OFActionVendor;
import static org.junit.Assert.*;
public class OFActionNiciraTtlDecrementTest {
protected static byte[] expectedWireFormat = {
(byte) 0xff, (byte) 0xff, // action vendor
0x00, 0x10, // length
0x00, 0x00, 0x23, 0x20, // nicira
0x00, 0x12, // subtype 18 == 0x12
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // pad
};
@Test
public void testAction() {
ChannelBuffer buf = ChannelBuffers.buffer(32);
OFActionNiciraTtlDecrement act = new OFActionNiciraTtlDecrement();
assertEquals(true, act instanceof OFActionNiciraVendor);
assertEquals(true, act instanceof OFActionVendor);
assertEquals(true, act instanceof OFAction);
act.writeTo(buf);
ChannelBuffer buf2 = buf.copy();
assertEquals(16, buf.readableBytes());
byte fromBuffer[] = new byte[16];
buf.readBytes(fromBuffer);
assertArrayEquals(expectedWireFormat, fromBuffer);
// Test parsing. TODO: we don't really have the proper parsing
// infrastructure....
OFActionNiciraVendor act2 = new OFActionNiciraTtlDecrement();
act2.readFrom(buf2);
assertEquals(act, act2);
assertNotSame(act, act2);
assertEquals(OFActionType.VENDOR, act2.getType());
assertEquals(16, act2.getLength());
assertEquals(OFActionNiciraVendor.NICIRA_VENDOR_ID, act2.getVendor());
assertEquals((short)18, act2.getSubtype());
}
}
package com.bigswitch.floodlight.vendor;
import net.floodlightcontroller.packet.IPv4;
import net.floodlightcontroller.test.FloodlightTestCase;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import org.openflow.protocol.action.OFActionType;
import static org.junit.Assert.*;
public class OFActionTunnelDstIPTest extends FloodlightTestCase{
protected static byte[] expectedWireFormat1 = {
(byte) 0xff, (byte) 0xff, // ActionVendor
0x00, 0x10, // 16 bytes
0x00, 0x5c, 0x16, (byte)0xc7, // VendorId BSN
0x00, 0x00, 0x00, 0x02, // subtype 2 (32 bit)
0x11, 0x21, 0x31, 0x41 // IP 17.33.49.65
};
@Test
public void testAction() {
OFActionTunnelDstIP tunnAct1 = new OFActionTunnelDstIP();
assertEquals(0, tunnAct1.dstIPAddr);
OFActionTunnelDstIP tunnAct2 = new OFActionTunnelDstIP(1);
assertEquals(false, tunnAct1.equals(tunnAct2));
tunnAct1.setTunnelDstIP(1);
assertEquals(tunnAct1, tunnAct2);
testAll(tunnAct1);
testAll(tunnAct2);
}
private void testAll(OFActionTunnelDstIP tip) {
assertEquals(OFActionType.VENDOR, tip.getType());
assertEquals(2, tip.getSubtype());
assertEquals(16, tip.getLength());
assertEquals(0x005c16c7, tip.getVendor());
tip.setTunnelDstIP(24);
assertEquals(24, tip.getTunnelDstIP());
// Test wire format
int ip = IPv4.toIPv4Address("17.33.49.65");
tip.setTunnelDstIP(ip);
ChannelBuffer buf = ChannelBuffers.buffer(32);
tip.writeTo(buf);
ChannelBuffer buf2 = buf.copy();
assertEquals(16, buf.readableBytes());
byte fromBuffer[] = new byte[16];
buf.readBytes(fromBuffer);
assertArrayEquals(expectedWireFormat1, fromBuffer);
OFActionTunnelDstIP act2 = new OFActionTunnelDstIP();
act2.readFrom(buf2);
assertEquals(tip, act2);
}
}
package com.bigswitch.floodlight.vendor;
import static org.junit.Assert.assertEquals;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import org.openflow.protocol.action.OFActionVendor;
import org.openflow.protocol.factory.OFVendorActionFactory;
public class OFVendorActionFactoriesTest {
@Test
public void testNiciraVendorActionFactory() {
OFNiciraVendorActionFactory factory =
new OFNiciraVendorActionFactory();
OFActionNiciraTtlDecrement ttl = new OFActionNiciraTtlDecrement();
rereadAndCheck(factory, ttl);
}
@Test
public void testBSNVendorActionFactory() {
OFBigSwitchVendorActionFactory factory =
new OFBigSwitchVendorActionFactory();
OFActionMirror mirror = new OFActionMirror((short) 12);
mirror.setCopyStage((byte) 96);
mirror.setDestPort(123);
mirror.setVlanTag(42);
rereadAndCheck(factory, mirror);
OFActionTunnelDstIP dstIP = new OFActionTunnelDstIP((short) 12);
dstIP.setTunnelDstIP(0x01020304);
rereadAndCheck(factory, dstIP);
}
protected void rereadAndCheck(OFVendorActionFactory factory, OFActionVendor action) {
ChannelBuffer buf= ChannelBuffers.buffer(action.getLengthU());
action.writeTo(buf);
OFActionVendor readAction = factory.readFrom(buf);
assertBeansEqual(action, readAction);
}
public void assertBeansEqual(Object expected, Object actual) {
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(expected.getClass());
for (PropertyDescriptor propertyDesc : beanInfo.getPropertyDescriptors()) {
Object srcValue = propertyDesc.getReadMethod().invoke(expected);
Object dstValue = propertyDesc.getReadMethod().invoke(actual);
assertEquals("Bean Value: "+propertyDesc.getName() + " expected: "+srcValue + " != actual: "+dstValue, srcValue, dstValue);
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
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