package org.opendaylight.openflowplugin.openflow.md.core.session;
-import java.math.BigInteger;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDestinguisher;
+import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private SwitchConnectionCookieOFImpl switchConnectionKey;
+ private int seed;
+
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
- switchConnectionKey = createSwitchSessionKey("a1a2a3a4a5a6", (short) 42);
+ seed = 4242;
+ switchConnectionKey = createSwitchSessionKey((short) 42);
}
/**
* @param datapathId
* @return
*/
- private static SwitchConnectionCookieOFImpl createSwitchSessionKey(
- String datapathId, short auxiliary) {
+ private static SwitchConnectionCookieOFImpl createSwitchSessionKey(short auxiliary) {
SwitchConnectionCookieOFImpl key = new SwitchConnectionCookieOFImpl();
- key.setDatapathId(new BigInteger(datapathId, 16));
key.setAuxiliaryId(auxiliary);
return key;
}
*/
@Test
public void testGetId() {
- switchConnectionKey.initId();
- LOG.debug("testKey.id: " + Arrays.toString(switchConnectionKey.getId()));
- byte[] expected = new byte[] { 32, 9, -69, 43, -68, -53, 49, 105, -109,
- -15, -20, 50, -121, -34, -22, 3, 27, 42, 90, -59 };
- Assert.assertArrayEquals(expected, switchConnectionKey.getId());
+ switchConnectionKey.init(seed);
+ LOG.debug("testKey.id: " + Long.toHexString(switchConnectionKey.getCookie()));
+ long expected = 710033450L;
+ Assert.assertEquals(expected, switchConnectionKey.getCookie());
}
/**
@Test
public void testInitId1() {
try {
- switchConnectionKey.setDatapathId(null);
- switchConnectionKey.initId();
+ switchConnectionKey.setAuxiliaryId((short) 0);
+ switchConnectionKey.init(seed);
Assert.fail("init should fail with no datapathId");
} catch (Exception e) {
// expected
@Test
public void testHashAndEquals() {
// insert equal keys
- SwitchConnectionCookieOFImpl key1 = createSwitchSessionKey("1234567890",
- (short) 42);
- key1.initId();
-
- SwitchConnectionCookieOFImpl key2 = createSwitchSessionKey("1234567890",
- (short) 42);
- key2.initId();
-
- SwitchConnectionCookieOFImpl key3 = createSwitchSessionKey("123456789",
- (short) 42);
- key3.initId();
- SwitchConnectionCookieOFImpl key4 = createSwitchSessionKey("123456789",
- (short) 21);
- key4.initId();
-
- Map<SwitchConnectionDestinguisher, Integer> keyLot = new HashMap<>();
+ SwitchConnectionCookieOFImpl key1 = createSwitchSessionKey((short) 42);
+ key1.init(seed);
+
+ SwitchConnectionCookieOFImpl key2 = createSwitchSessionKey((short) 42);
+ key2.init(seed);
+
+ SwitchConnectionCookieOFImpl key3 = createSwitchSessionKey((short) 43);
+ key3.init(seed);
+ SwitchConnectionCookieOFImpl key4 = createSwitchSessionKey((short) 21);
+ key4.init(seed);
+
+ Map<SwitchConnectionDistinguisher, Integer> keyLot = new HashMap<>();
keyLot.put(key1, System.identityHashCode(key1));
Assert.assertEquals(1, keyLot.size());
keyLot.put(key2, System.identityHashCode(key2));
.intValue());
// lookup using not inited key
- SwitchConnectionCookieOFImpl keyWithoutInit = createSwitchSessionKey(
- "123456789", (short) 42);
+ SwitchConnectionCookieOFImpl keyWithoutInit = createSwitchSessionKey((short) 42);
Assert.assertNull(keyLot.get(keyWithoutInit));
// creating brand new key and lookup
- SwitchConnectionCookieOFImpl keyWithInit = createSwitchSessionKey(
- "123456789", (short) 42);
- keyWithInit.initId();
+ SwitchConnectionCookieOFImpl keyWithInit = createSwitchSessionKey((short) 43);
+ keyWithInit.init(seed);
Assert.assertEquals(System.identityHashCode(key3),
keyLot.get(keyWithInit).intValue());
// lookup with key containing encoded part only
- LOG.debug("key3.id: " + Arrays.toString(key3.getId()));
- SwitchConnectionCookieOFImpl keyWithoutDPID = new SwitchConnectionCookieOFImpl(
- new byte[] { -12, -121, -45, -16, 98, 33, -19, -66, -93, -46, -52, 79, -13, -116, -97, 0, 121, 78, -104, 29 });
+ LOG.debug("key3.id: " + Long.toHexString(key3.getCookie()));
+ SwitchConnectionCookieOFImpl keyWithoutDPID = new SwitchConnectionCookieOFImpl(734546075L);
Assert.assertEquals(System.identityHashCode(key3),
keyLot.get(keyWithoutDPID).intValue());
}