/*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015 NEC Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
private int maxRedirections;
+ /**
+ * A boolean value that determines whether to enable host tracking in the
+ * vBridge.
+ */
+ @XmlElement(name = "host-tracking")
+ private Boolean hostTracking;
+
/**
* MAC address of the controller used as source MAC address of ARP packet.
* It is determined by the controller if omitted.
builder.setMaxRedirections(DEFAULT_MAX_REDIRECTIONS);
}
+ if (builder.isHostTracking() == null) {
+ builder.setHostTracking(true);
+ }
+
if (builder.getControllerMacAddress() == null) {
builder.setControllerMacAddress(mac.getMacAddress());
}
setBulkFlowModTimeout(vcfg.getBulkFlowModTimeout()).
setInitTimeout(vcfg.getInitTimeout()).
setMaxRedirections(vcfg.getMaxRedirections()).
+ setHostTracking(vcfg.isHostTracking()).
setControllerMacAddress(vcfg.getControllerMacAddress());
}
newConf.getInitTimeout());
diff(list, "max-redirections", oldConf.getMaxRedirections(),
newConf.getMaxRedirections());
+ diff(list, "host-tracking", oldConf.isHostTracking(),
+ newConf.isHostTracking());
EtherAddress oldMac = oldConf.getControllerMacAddress();
EtherAddress newMac = newConf.getControllerMacAddress();
}
}
+ /**
+ * Add a string that indicates the change of parameter to the given list.
+ *
+ * @param list A list of strings that indicates diferrences of parameters.
+ * @param name The name of the parameter.
+ * @param o Old value of the parameter.
+ * @param n New value of the parameter.
+ */
+ private static void diff(List<String> list, String name, boolean o,
+ boolean n) {
+ if (o != n) {
+ StringBuilder builder = new StringBuilder(name);
+ builder.append("=(").append(o).append(RIGHT_ARROW).append(n).
+ append(')');
+ list.add(builder.toString());
+ }
+ }
+
/**
* Construct a new instance which contains default parameter values.
*
bulkFlowModTimeout = decode(vcfg.getBulkFlowModTimeout());
initTimeout = decode(vcfg.getInitTimeout());
maxRedirections = decode(vcfg.getMaxRedirections());
+ hostTracking = vcfg.isHostTracking();
controllerMacAddress = decode(vcfg.getControllerMacAddress());
if (mac != null && controllerMacAddress == null) {
controllerMacAddress = mac;
setBulkFlowModTimeout(encode(bulkFlowModTimeout)).
setInitTimeout(encode(initTimeout)).
setMaxRedirections(encode(maxRedirections)).
+ setHostTracking(hostTracking).
setControllerMacAddress(encode(controllerMacAddress));
return builder.build();
*/
public VtnConfigBuilder getJaxbValue() {
return createJaxbValue().
+ setHostTracking(hostTracking).
setControllerMacAddress(encode(controllerMacAddress));
}
*/
@Override
public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
-
- boolean result = false;
- if (o != null && getClass().equals(o.getClass())) {
+ boolean result = (o == this);
+ if (!result && o != null && getClass().equals(o.getClass())) {
VTNConfigImpl vconf = (VTNConfigImpl)o;
if (topologyWait == vconf.topologyWait &&
initTimeout == vconf.initTimeout &&
maxRedirections == vconf.maxRedirections) {
result = (equalsFlowParams(vconf) &&
+ Objects.equals(hostTracking, vconf.hostTracking) &&
Objects.equals(controllerMacAddress,
vconf.controllerMacAddress));
}
@Override
public int hashCode() {
return Objects.hash(topologyWait, l2FlowPriority, flowModTimeout,
- bulkFlowModTimeout, initTimeout,
- maxRedirections, controllerMacAddress);
+ bulkFlowModTimeout, initTimeout, maxRedirections,
+ hostTracking, controllerMacAddress);
}
// JAXB methods.
return (i == null) ? UNDEFINED : i.intValue();
}
+ /**
+ * Determine whether the given object is {@code null} or not.
+ *
+ * @param obj An object to be tested.
+ * @param def The default value.
+ * @param <T> The type of the object.
+ * @return {@code obj} if it is not {@code null}.
+ * {@code def} if {@code obj} is {@code null}.
+ */
+ private <T> T checkNotNull(T obj, T def) {
+ return (obj == null) ? def : obj;
+ }
+
/**
* Return an {@link EtherAddress} instance that represents the given
* {@link MacAddress} instance.
return intValue(maxRedirections, DEFAULT_MAX_REDIRECTIONS);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isHostTracking() {
+ return (hostTracking == null || hostTracking.booleanValue());
+ }
+
/**
* {@inheritDoc}
*/
/*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015 NEC Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
all.setMaxRedirections(value);
allTest.set(ConfigType.MAX_REDIRECTIONS, value);
+ // Set host-tracking.
+ Boolean htrack = Boolean.FALSE;
+ builder = new VtnConfigBuilder().setHostTracking(htrack);
+ assertSame(builder, VTNConfigImpl.fillDefault(builder, mac));
+ new TestVtnConfigBuilder().set(ConfigType.HOST_TRACKING, htrack).
+ set(ConfigType.CONTROLLER_MAC_ADDRESS, defMac).fillDefault().
+ verify(builder);
+ assertEquals(null, builder.isInitState());
+
+ htrack = Boolean.TRUE;
+ all.setHostTracking(htrack);
+ allTest.set(ConfigType.HOST_TRACKING, htrack);
+
// Set controller-mac-address.
MacAddress macAddr = new MacAddress("12:34:56:78:9a:bc");
builder = new VtnConfigBuilder().setControllerMacAddress(macAddr);
all.setMaxRedirections(value);
allTest.set(ConfigType.MAX_REDIRECTIONS, value);
+ // Set host-tracking.
+ Boolean htrack = Boolean.FALSE;
+ vcfg = new VtnConfigBuilder().setHostTracking(htrack).build();
+ builder = VTNConfigImpl.builder(vcfg, mac);
+ new TestVtnConfigBuilder().set(ConfigType.HOST_TRACKING, htrack).
+ set(ConfigType.CONTROLLER_MAC_ADDRESS, defMac).fillDefault().
+ verify(builder);
+ assertEquals(null, builder.isInitState());
+
+ htrack = Boolean.TRUE;
+ all.setHostTracking(htrack);
+ allTest.set(ConfigType.HOST_TRACKING, htrack);
+
// Set controller-mac-address.
MacAddress macAddr = new MacAddress("12:34:56:78:9a:bc");
vcfg = new VtnConfigBuilder().setControllerMacAddress(macAddr).
all2.setMaxRedirections(nv1);
diffList.add("max-redirections=(" + nv + "->" + nv1 + ")");
+ // Change host-tracking.
+ boolean ob = vconfOld.isHostTracking();
+ boolean nb = false;
+ vcfg = new VtnConfigBuilder().setHostTracking(nb).build();
+ vconfNew = new VTNConfigImpl(vcfg);
+ expected = "host-tracking=(" + ob + "->" + nb + ")";
+ assertEquals(expected, VTNConfigImpl.diff(vconfOld, vconfNew));
+
+ all1.setHostTracking(nb);
+ all2.setHostTracking(ob);
+ diffList.add("host-tracking=(" + nb + "->" + ob + ")");
+
// Change controller-mac-address.
EtherAddress omac = vconfOld.getControllerMacAddress();
EtherAddress nmac = new EtherAddress(0xfafbfcfdfeffL);
vcfg = new VtnConfigBuilder().setTopologyWait(value).build();
vconf = (mac == null)
? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
- test.resetIntegers().set(type, value).verify(vconf);
+ test.reset().set(type, value).verify(vconf);
value = 1;
all.setTopologyWait(value);
vcfg = new VtnConfigBuilder().setL2FlowPriority(value).build();
vconf = (mac == null)
? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
- test.resetIntegers().set(type, value).verify(vconf);
+ test.reset().set(type, value).verify(vconf);
value = 1;
all.setL2FlowPriority(value);
vcfg = new VtnConfigBuilder().setFlowModTimeout(value).build();
vconf = (mac == null)
? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
- test.resetIntegers().set(type, value).verify(vconf);
+ test.reset().set(type, value).verify(vconf);
value = 200;
all.setFlowModTimeout(value);
vcfg = new VtnConfigBuilder().setBulkFlowModTimeout(value).build();
vconf = (mac == null)
? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
- test.resetIntegers().set(type, value).verify(vconf);
+ test.reset().set(type, value).verify(vconf);
value = 3300;
all.setBulkFlowModTimeout(value);
vcfg = new VtnConfigBuilder().setInitTimeout(value).build();
vconf = (mac == null)
? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
- test.resetIntegers().set(type, value).verify(vconf);
+ test.reset().set(type, value).verify(vconf);
value = 200;
all.setInitTimeout(value);
vcfg = new VtnConfigBuilder().setMaxRedirections(value).build();
vconf = (mac == null)
? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
- test.resetIntegers().set(type, value).verify(vconf);
+ test.reset().set(type, value).verify(vconf);
value = 11;
all.setMaxRedirections(value);
allTest.set(type, value);
+ // Set host-tracking.
+ type = ConfigType.HOST_TRACKING;
+ Boolean htrack = Boolean.FALSE;
+ vcfg = new VtnConfigBuilder().setHostTracking(htrack).build();
+ vconf = (mac == null)
+ ? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
+ test.reset().set(type, htrack).verify(vconf);
+
// Set ccontroller-mac-address.
MacAddress macAddr = new MacAddress("12:34:56:78:9a:bc");
type = ConfigType.CONTROLLER_MAC_ADDRESS;
build();
vconf = (mac == null)
? new VTNConfigImpl(vcfg) : new VTNConfigImpl(vcfg, mac);
- test.resetIntegers().set(type, macAddr).verify(vconf);
+ test.reset().set(type, macAddr).verify(vconf);
macAddr = new MacAddress("11:22:33:44:55:66");
all.setControllerMacAddress(macAddr);
all.setMaxRedirections(value);
allTest.set(ConfigType.MAX_REDIRECTIONS, value);
+ // Set host-tracking.
+ Boolean htrack = Boolean.FALSE;
+ vcfg = new VtnConfigBuilder().setHostTracking(htrack).build();
+ vcfg = new VTNConfigImpl(vcfg).toVtnConfig();
+ new TestVtnConfigBuilder().set(ConfigType.HOST_TRACKING, htrack).
+ verify(vcfg);
+ assertEquals(null, vcfg.isInitState());
+
+ value = 10;
+ all.setHostTracking(htrack);
+ allTest.set(ConfigType.HOST_TRACKING, htrack);
+
// Set controller-mac-address.
MacAddress macAddr = new MacAddress("12:34:56:78:9a:bc");
vcfg = new VtnConfigBuilder().setControllerMacAddress(macAddr).
testEquals(set, vconf1, vconf2);
}
+ boolean[] bools = {true, false};
+ for (boolean b: bools) {
+ builder.setHostTracking(b);
+ VTNConfigImpl vconf1 = new VTNConfigImpl(builder.build());
+ VTNConfigImpl vconf2 = new VTNConfigImpl(builder.build());
+ assertEquals(b, vconf1.isHostTracking());
+ testEquals(set, vconf1, vconf2);
+ }
+
String[] addrs = {
"aa:bb:cc:dd:ee:ff",
"99:88:77:66:55:44",
int expected = neWaits.length + l2Priorities.length +
flowModTimeouts.length + bulkFlowModTimeouts.length +
- initTimeouts.length + maxRedirections.length + addrs.length + 1;
+ initTimeouts.length + maxRedirections.length + bools.length +
+ addrs.length + 1;
assertEquals(expected, set.size());
}
VtnConfig vcfg = new VtnConfigBuilder().setTopologyWait(v).build();
vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
XML_ROOT);
- test.resetIntegers().set(type, v).verify(vconf);
+ test.reset().set(type, v).verify(vconf);
assertEquals(vcfg, vconf.getJaxbValue().build());
allBuilder.setTopologyWait(v);
build();
vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
XML_ROOT);
- test.resetIntegers().set(type, v).verify(vconf);
+ test.reset().set(type, v).verify(vconf);
assertEquals(vcfg, vconf.getJaxbValue().build());
allBuilder.setL2FlowPriority(v);
build();
vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
XML_ROOT);
- test.resetIntegers().set(type, v).verify(vconf);
+ test.reset().set(type, v).verify(vconf);
assertEquals(vcfg, vconf.getJaxbValue().build());
allBuilder.setFlowModTimeout(v);
build();
vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
XML_ROOT);
- test.resetIntegers().set(type, v).verify(vconf);
+ test.reset().set(type, v).verify(vconf);
assertEquals(vcfg, vconf.getJaxbValue().build());
allBuilder.setBulkFlowModTimeout(v);
VtnConfig vcfg = new VtnConfigBuilder().setInitTimeout(v).build();
vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
XML_ROOT);
- test.resetIntegers().set(type, v).verify(vconf);
+ test.reset().set(type, v).verify(vconf);
assertEquals(vcfg, vconf.getJaxbValue().build());
allBuilder.setInitTimeout(v);
build();
vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
XML_ROOT);
- test.resetIntegers().set(type, v).verify(vconf);
+ test.reset().set(type, v).verify(vconf);
assertEquals(vcfg, vconf.getJaxbValue().build());
allBuilder.setMaxRedirections(v);
vconf.setJaxbMaxRedirections(null);
assertEquals(null, vconf.getJaxbMaxRedirections());
+ type = ConfigType.HOST_TRACKING;
+ Boolean[] bools = {null, Boolean.TRUE, Boolean.FALSE};
+ for (Boolean b: bools) {
+ VtnConfig vcfg = new VtnConfigBuilder().setHostTracking(b).
+ build();
+ vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
+ XML_ROOT);
+ test.reset().set(type, b).verify(vconf);
+ assertEquals(vcfg, vconf.getJaxbValue().build());
+
+ allBuilder.setHostTracking(b);
+ VtnConfig all = allBuilder.build();
+ vconf = jaxbTest(new VTNConfigImpl(all), VTNConfigImpl.class,
+ XML_ROOT);
+ allTest.set(type, b).verify(vconf);
+ assertEquals(all, vconf.getJaxbValue().build());
+ }
+
type = ConfigType.CONTROLLER_MAC_ADDRESS;
String[] addrs = {
"aa:bb:cc:dd:ee:ff",
setControllerMacAddress(maddr).build();
vconf = jaxbTest(new VTNConfigImpl(vcfg), VTNConfigImpl.class,
XML_ROOT);
- test.resetIntegers().set(type, maddr).verify(vconf);
+ test.reset().set(type, maddr).verify(vconf);
assertEquals(vcfg, vconf.getJaxbValue().build());
allBuilder.setControllerMacAddress(maddr);
jaxbErrorTest(VTNConfigImpl.class,
new XmlValueType("controller-mac-address",
EtherAddress.class).add(XML_ROOT),
- new XmlValueType("topology-wait", Integer.class).
- add(XML_ROOT),
- new XmlValueType("l2-flow-priority", Integer.class).
- add(XML_ROOT),
- new XmlValueType("flow-mod-timeout", Integer.class).
- add(XML_ROOT),
- new XmlValueType("bulk-flow-mod-timeout", Integer.class).
- add(XML_ROOT),
- new XmlValueType("init-timeout", Integer.class).
- add(XML_ROOT),
- new XmlValueType("max-redirections", Integer.class).
- add(XML_ROOT));
+ new XmlValueType("topology-wait",
+ Integer.class).add(XML_ROOT),
+ new XmlValueType("l2-flow-priority",
+ Integer.class).add(XML_ROOT),
+ new XmlValueType("flow-mod-timeout",
+ Integer.class).add(XML_ROOT),
+ new XmlValueType("bulk-flow-mod-timeout",
+ Integer.class).add(XML_ROOT),
+ new XmlValueType("init-timeout",
+ Integer.class).add(XML_ROOT),
+ new XmlValueType("max-redirections",
+ Integer.class).add(XML_ROOT));
}
}
/*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015 NEC Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
// Write configuration with the minimum values.
String minimum = "minimum";
+ Boolean minBool = Boolean.FALSE;
EtherAddress minMac = new EtherAddress(0L);
File baseDir = getConfigDir();
File dir = new File(baseDir, type.toString());
for (ConfigType ctype: configTypes) {
Object min = ctype.getMinimumValue();
if (min == null) {
- min = minMac;
+ min = (ctype.isBoolean()) ? minBool : minMac;
}
ps.println(ctype.getXmlElement(min));
}
// Write configuration with the maximum values.
String maximum = "maximum";
+ Boolean maxBool = Boolean.TRUE;
EtherAddress maxMac = new EtherAddress(0xffffffffffffL);
file = new File(dir, maximum + ".xml");
ps = new PrintStream(new FileOutputStream(file));
for (ConfigType ctype: configTypes) {
Object max = ctype.getMaximumValue();
if (max == null) {
- max = maxMac;
+ max = (ctype.isBoolean()) ? maxBool : maxMac;
}
ps.println(ctype.getXmlElement(max));
}
Object value = ctype.get(min);
Object expected = ctype.getMinimumValue();
if (expected == null) {
- expected = minMac;
+ expected = (ctype.isBoolean()) ? minBool : minMac;
}
assertEquals(expected, value);
}
Object value = ctype.get(max);
Object expected = ctype.getMaximumValue();
if (expected == null) {
- expected = maxMac;
+ expected = (ctype.isBoolean()) ? maxBool : maxMac;
}
assertEquals(expected, value);
}
// Test with broken value.
String bad = "bad";
for (ConfigType ctype: configTypes) {
- file = new File(dir, bad + ".xml");
- ps = new PrintStream(new FileOutputStream(file));
- ps.printf("<vtn-config>\n");
- ps.println(ctype.getXmlElement("bad value"));
- ps.printf("</vtn-config>\n");
- ps.close();
- assertEquals(true, file.isFile());
- assertEquals(ctype.toString(), null,
- XmlConfigFile.load(type, bad, cls));
- assertEquals(false, file.isFile());
+ if (!ctype.isBoolean()) {
+ file = new File(dir, bad + ".xml");
+ ps = new PrintStream(new FileOutputStream(file));
+ ps.printf("<vtn-config>\n");
+ ps.println(ctype.getXmlElement("bad value"));
+ ps.printf("</vtn-config>\n");
+ ps.close();
+ assertEquals(true, file.isFile());
+ assertEquals(ctype.toString(), null,
+ XmlConfigFile.load(type, bad, cls));
+ assertEquals(false, file.isFile());
+ }
}
// Test with too small values.