import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.math.BigInteger;
import org.junit.Test;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.flow._case.MultipartRequestFlowBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
public class FlowCreatorUtilTest {
*/
@Test
public void testCanModifyFlow() {
- final Short of10 = Short.valueOf(OFConstants.OFP_VERSION_1_0);
- final Short of13 = Short.valueOf(OFConstants.OFP_VERSION_1_3);
- final Short[] versions = {null, of10, of13};
+ final Uint8[] versions = {null, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3};
final Boolean[] bools = {null, Boolean.TRUE, Boolean.FALSE};
- final Integer defPri = Integer.valueOf(0x8000);
- final Integer defIdle = Integer.valueOf(0);
- final Integer defHard = Integer.valueOf(0);
+ final Uint16 defPri = Uint16.valueOf(0x8000);
+ final Uint16 defIdle = Uint16.ZERO;
+ final Uint16 defHard = Uint16.ZERO;
final FlowModFlags defFlags = FlowModFlags.getDefaultInstance("sENDFLOWREM");
final FlowModFlags flags = new FlowModFlags(false, true, false, true, false);
- final FlowCookie defCookie = new FlowCookie(BigInteger.ZERO);
- final FlowCookie cookie = new FlowCookie(BigInteger.valueOf(0x12345L));
- final FlowCookie cookie1 = new FlowCookie(BigInteger.valueOf(0x67890L));
- final FlowCookie cookieMask = new FlowCookie(BigInteger.valueOf(0xffff00L));
+ final FlowCookie defCookie = new FlowCookie(Uint64.ZERO);
+ final FlowCookie cookie = new FlowCookie(Uint64.valueOf(0x12345));
+ final FlowCookie cookie1 = new FlowCookie(Uint64.valueOf(0x67890));
+ final FlowCookie cookieMask = new FlowCookie(Uint64.valueOf(0xffff00));
- for (final Short ver : versions) {
+ for (final Uint8 ver : versions) {
final OriginalFlowBuilder originalBuilder = new OriginalFlowBuilder();
final UpdatedFlowBuilder updatedBuilder = new UpdatedFlowBuilder();
canModifyFlowTest(true, originalBuilder, updatedBuilder, ver);
// Set non-default values.
canModifyFlowTest(true, originalBuilder.setMatch(createMatch(0x800L)),
updatedBuilder.setMatch(createMatch(0x800L)), ver);
- canModifyFlowTest(true, originalBuilder.setIdleTimeout(600), updatedBuilder.setIdleTimeout(600), ver);
- canModifyFlowTest(true, originalBuilder.setHardTimeout(1200), updatedBuilder.setHardTimeout(1200), ver);
- canModifyFlowTest(true, originalBuilder.setPriority(100), updatedBuilder.setPriority(100), ver);
+ canModifyFlowTest(true, originalBuilder.setIdleTimeout(Uint16.valueOf(600)),
+ updatedBuilder.setIdleTimeout(Uint16.valueOf(600)), ver);
+ canModifyFlowTest(true, originalBuilder.setHardTimeout(Uint16.valueOf(1200)),
+ updatedBuilder.setHardTimeout(Uint16.valueOf(1200)), ver);
+ canModifyFlowTest(true, originalBuilder.setPriority(Uint16.valueOf(100)),
+ updatedBuilder.setPriority(Uint16.valueOf(100)), ver);
canModifyFlowTest(true, originalBuilder.setFlags(flags), updatedBuilder.setFlags(flags), ver);
canModifyFlowTest(true, originalBuilder.setCookie(cookie), updatedBuilder.setCookie(cookie), ver);
}
// Set different idle-timeout, hard-timeout, priority.
- final Integer[] integers = {null, Integer.valueOf(3600)};
+ final Integer[] integers = {null, 3600};
for (final Integer i : integers) {
- canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setIdleTimeout(i), ver);
- canModifyFlowTest(false, new OriginalFlowBuilder(org).setIdleTimeout(i), updatedBuilder, ver);
+ final Uint16 uint = i == null ? null : Uint16.valueOf(i);
+ canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setIdleTimeout(uint), ver);
+ canModifyFlowTest(false, new OriginalFlowBuilder(org).setIdleTimeout(uint), updatedBuilder, ver);
- canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setHardTimeout(i), ver);
- canModifyFlowTest(false, new OriginalFlowBuilder(org).setHardTimeout(i), updatedBuilder, ver);
+ canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setHardTimeout(uint), ver);
+ canModifyFlowTest(false, new OriginalFlowBuilder(org).setHardTimeout(uint), updatedBuilder, ver);
- canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setPriority(i), ver);
- canModifyFlowTest(false, new OriginalFlowBuilder(org).setPriority(i), updatedBuilder, ver);
+ canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setPriority(uint), ver);
+ canModifyFlowTest(false, new OriginalFlowBuilder(org).setPriority(uint), updatedBuilder, ver);
}
// Set different FLOW_MOD flags.
}
// Set different cookie.
- final FlowCookie[] cookies = {null, defCookie, new FlowCookie(BigInteger.valueOf(0x123456L)),};
+ final FlowCookie[] cookies = {null, defCookie, new FlowCookie(Uint64.valueOf(0x123456L)),};
for (final FlowCookie c : cookies) {
canModifyFlowTest(false, originalBuilder, new UpdatedFlowBuilder(upd).setCookie(c), ver);
canModifyFlowTest(false, new OriginalFlowBuilder(org).setCookie(c), updatedBuilder, ver);
canModifyFlowTest(false, originalBuilder, updatedBuilder, ver);
updatedBuilder.setCookieMask(cookieMask);
- final boolean expected = (of13.equals(ver) && !Boolean.TRUE.equals(strict));
+ final boolean expected = OFConstants.OFP_VERSION_1_3.equals(ver) && !Boolean.TRUE.equals(strict);
canModifyFlowTest(expected, originalBuilder, updatedBuilder, ver);
}
}
*/
@Test
public void testEqualsFlowModFlags() {
- final FlowModFlags[] defaults = {null, new FlowModFlags(false, false, false, false, false), new FlowModFlags(
- false, null, false, null, Boolean.FALSE),};
+ final FlowModFlags[] defaults = {
+ null,
+ new FlowModFlags(false, false, false, false, false),
+ new FlowModFlags(false, false, false, false, false)
+ };
final FlowModFlags all = new FlowModFlags(true, true, true, true, true);
- final FlowModFlags none = new FlowModFlags(null, null, null, null, null);
+ final FlowModFlags none = new FlowModFlags(false, false, false, false, false);
for (final FlowModFlags f : defaults) {
assertTrue(FlowCreatorUtil.equalsFlowModFlags(f, null));
assertEquals(expected, FlowCreatorUtil.equalsFlowModFlags(f, flags));
}
- final boolean overlap = (bit == 0);
- final boolean noByte = (bit == 1);
- final boolean noPacket = (bit == 2);
- final boolean reset = (bit == 3);
- final boolean flowRem = (bit == 4);
+ final boolean overlap = bit == 0;
+ final boolean noByte = bit == 1;
+ final boolean noPacket = bit == 2;
+ final boolean reset = bit == 3;
+ final boolean flowRem = bit == 4;
FlowModFlags flowModFlags = new FlowModFlags(overlap, noByte, noPacket, reset, flowRem);
assertTrue(FlowCreatorUtil.equalsFlowModFlags(flags, flowModFlags));
assertTrue(FlowCreatorUtil.equalsFlowModFlags(flowModFlags, flags));
assertTrue(FlowCreatorUtil.equalsWithDefault(def, null, def));
assertTrue(FlowCreatorUtil.equalsWithDefault(null, def, def));
- final Boolean inv = Boolean.valueOf(!def.booleanValue());
+ final Boolean inv = !def.booleanValue();
assertFalse(FlowCreatorUtil.equalsWithDefault(null, inv, def));
assertFalse(FlowCreatorUtil.equalsWithDefault(inv, null, def));
}
// Integer
- final Integer[] integers = {Integer.valueOf(-100), Integer.valueOf(0), Integer.valueOf(100),};
+ final Integer[] integers = {-1000, 0, 1000,};
for (final Integer def : integers) {
- final Integer same = new Integer(def.intValue());
+ final Integer same = Integer.valueOf(def);
assertTrue(FlowCreatorUtil.equalsWithDefault(null, null, def));
assertTrue(FlowCreatorUtil.equalsWithDefault(same, null, def));
assertTrue(FlowCreatorUtil.equalsWithDefault(null, same, def));
- final Integer diff = new Integer(def.intValue() + 1);
+ final Integer diff = Integer.valueOf(def.intValue() + 1);
assertFalse(FlowCreatorUtil.equalsWithDefault(null, diff, def));
assertFalse(FlowCreatorUtil.equalsWithDefault(diff, null, def));
}
}
private static void assertMatch(final Match match) {
- assertTrue(match.getType().getClass().isInstance(OxmMatchType.class));
+ assertEquals(OxmMatchType.VALUE, match.getType());
}
private static void assertMatch(final MatchV10 matchV10) {
* @param version OpenFlow protocol version.
*/
private static void canModifyFlowTest(final boolean expected, final OriginalFlowBuilder org,
- final UpdatedFlowBuilder upd, final Short version) {
+ final UpdatedFlowBuilder upd, final Uint8 version) {
final boolean result = FlowCreatorUtil.canModifyFlow(org.build(), upd.build(), version);
assertEquals(expected, result);
}
*/
private static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match createMatch(
final long etherType) {
- final EthernetTypeBuilder ethType = new EthernetTypeBuilder().setType(new EtherType(etherType));
+ final EthernetTypeBuilder ethType = new EthernetTypeBuilder().setType(new EtherType(Uint32.valueOf(etherType)));
final EthernetMatchBuilder ether = new EthernetMatchBuilder().setEthernetType(ethType.build());
return new MatchBuilder().setEthernetMatch(ether.build()).build();
}