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

more unit tests

parent 93bd1935
No related branches found
No related tags found
No related merge requests found
......@@ -6,13 +6,13 @@ import org.openflow.protocol.vendor.OFVendorData;
/**
* Base class for vendor data corresponding to BigSwitch vendor extensions
* BigSwitch vendor data always starts with a 4-byte integer data type value
*
*
* @author Munish Mehta (munish.mehta@bigswitch.com)
*/
public class OFBigSwitchVendorData implements OFVendorData {
public static final int BSN_VENDOR_ID = 0x005c16c7;
/**
* The value of the integer data type at the beginning of the vendor data
*/
......@@ -26,7 +26,7 @@ public class OFBigSwitchVendorData implements OFVendorData {
super();
this.dataType = dataType;
}
/**
* Get the data type value at the beginning of the vendor data
* @return
......@@ -74,4 +74,22 @@ public class OFBigSwitchVendorData implements OFVendorData {
data.writeInt(dataType);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + dataType;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
OFBigSwitchVendorData other = (OFBigSwitchVendorData) obj;
if (dataType != other.dataType) return false;
return true;
}
}
......@@ -121,4 +121,30 @@ public class OFBsnPktinSuppressionSetRequestVendorData
data.writeShort(priority);
data.writeLong(cookie);
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (int) (cookie ^ (cookie >>> 32));
result = prime * result + hardTimeout;
result = prime * result + idleTimeout;
result = prime * result + priority;
result = prime * result + (suppressionEnabled ? 1231 : 1237);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!super.equals(obj)) return false;
if (getClass() != obj.getClass()) return false;
OFBsnPktinSuppressionSetRequestVendorData other = (OFBsnPktinSuppressionSetRequestVendorData) obj;
if (cookie != other.cookie) return false;
if (hardTimeout != other.hardTimeout) return false;
if (idleTimeout != other.idleTimeout) return false;
if (priority != other.priority) return false;
if (suppressionEnabled != other.suppressionEnabled) return false;
return true;
}
}
package com.bigswitch.floodlight.vendor;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import static org.junit.Assert.*;
public class OFBsnPktinSupressionSetRequestVendorDataTest {
protected static byte[] expectedWireFormat = {
0x00, 0x00, 0x00, 0x0b, // type == 11
0x01, // enabled
0x00, // pad
0x00, 0x5a, // idle timeout
(byte) 0xf0, (byte) 0xe0, // hard timeout
0x12, 0x34, // priority
0x33, 0x33, 0x66, 0x66,
0x77, 0x77, (byte) 0x99, (byte) 0x99 // cookie
};
@Test
public void test() {
ChannelBuffer buf = ChannelBuffers.buffer(32);
OFBsnPktinSuppressionSetRequestVendorData vendorData =
new OFBsnPktinSuppressionSetRequestVendorData(
true,
(short)0x5a,
(short)0xf0e0,
(short)0x1234,
0x3333666677779999L);
assertEquals(11, vendorData.getDataType());
assertEquals(true, vendorData instanceof OFBigSwitchVendorData);
vendorData.writeTo(buf);
ChannelBuffer buf2 = buf.copy();
assertEquals(20, buf.readableBytes());
byte fromBuffer[] = new byte[20];
buf.readBytes(fromBuffer);
assertArrayEquals(expectedWireFormat, fromBuffer);
OFBsnPktinSuppressionSetRequestVendorData vendorData2 =
new OFBsnPktinSuppressionSetRequestVendorData();
assertEquals(11, vendorData2.getDataType());
vendorData2.setIdleTimeout((short)1);
assertEquals((short)1, vendorData2.getIdleTimeout());
vendorData2.setHardTimeout((short)2);
assertEquals((short)2, vendorData2.getHardTimeout());
vendorData2.setPriority((short)3);
assertEquals((short)3, vendorData2.getPriority());
vendorData2.setCookie(12345678901234L);
assertEquals(12345678901234L, vendorData2.getCookie());
vendorData2.readFrom(buf2, buf2.readableBytes());
assertEquals(vendorData, vendorData2);
}
}
......@@ -16,34 +16,67 @@
package net.floodlightcontroller.core.internal;
import net.floodlightcontroller.core.SwitchDriverSubHandshakeAlreadyStarted;
import net.floodlightcontroller.core.SwitchDriverSubHandshakeCompleted;
import net.floodlightcontroller.core.SwitchDriverSubHandshakeNotStarted;
import net.floodlightcontroller.core.IFloodlightProviderService.Role;
import net.floodlightcontroller.test.FloodlightTestCase;
import org.junit.Before;
import org.junit.Test;
import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFType;
import org.openflow.protocol.factory.BasicFactory;
public class OFSwitchImplTest extends FloodlightTestCase {
import static org.junit.Assert.*;
public class OFSwitchImplTest {
protected OFSwitchImpl sw;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
sw = new OFSwitchImpl();
}
}
@Test
public void testSetHARoleReply() {
sw.setHARole(Role.MASTER);
assertEquals(Role.MASTER, sw.getHARole());
sw.setHARole(Role.EQUAL);
assertEquals(Role.EQUAL, sw.getHARole());
sw.setHARole(Role.SLAVE);
assertEquals(Role.SLAVE, sw.getHARole());
}
@Test
public void testSubHandshake() {
OFMessage m = BasicFactory.getInstance().getMessage(OFType.VENDOR);
// test execptions before handshake is started
try {
sw.processDriverHandshakeMessage(m);
fail("expected exception not thrown");
} catch (SwitchDriverSubHandshakeNotStarted e) { /* expected */ }
try {
sw.isDriverHandshakeComplete();
fail("expected exception not thrown");
} catch (SwitchDriverSubHandshakeNotStarted e) { /* expected */ }
// start the handshake -- it should immediately complete
sw.startDriverHandshake();
assertTrue("Handshake should be complete",
sw.isDriverHandshakeComplete());
// test exceptions after handshake is completed
try {
sw.processDriverHandshakeMessage(m);
fail("expected exception not thrown");
} catch (SwitchDriverSubHandshakeCompleted e) { /* expected */ }
try {
sw.startDriverHandshake();
fail("Expected exception not thrown");
} catch (SwitchDriverSubHandshakeAlreadyStarted e) { /* expected */ }
}
}
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