use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class BasicHostConfigTest method testConstruction.
/**
* Tests construction, setters and getters of a BasicHostConfig object.
*/
@Test
public void testConstruction() {
BasicHostConfig config = new BasicHostConfig();
ConfigApplyDelegate delegate = configApply -> {
};
ObjectMapper mapper = new ObjectMapper();
HostId hostId = NetTestTools.hid("12:34:56:78:90:ab/1");
IpAddress ip1 = IpAddress.valueOf("1.1.1.1");
IpAddress ip2 = IpAddress.valueOf("1.1.1.2");
IpAddress ip3 = IpAddress.valueOf("1.1.1.3");
Set<IpAddress> ips = ImmutableSet.of(ip1, ip2, ip3);
HostLocation loc1 = new HostLocation(NetTestTools.connectPoint("d1", 1), System.currentTimeMillis());
HostLocation loc2 = new HostLocation(NetTestTools.connectPoint("d2", 2), System.currentTimeMillis());
Set<HostLocation> locs = ImmutableSet.of(loc1, loc2);
HostLocation loc3 = new HostLocation(NetTestTools.connectPoint("d3", 1), System.currentTimeMillis());
HostLocation loc4 = new HostLocation(NetTestTools.connectPoint("d4", 2), System.currentTimeMillis());
Set<HostLocation> auxLocations = ImmutableSet.of(loc3, loc4);
VlanId vlanId = VlanId.vlanId((short) 10);
EthType ethType = EthType.EtherType.lookup((short) 0x88a8).ethType();
config.init(hostId, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
config.setIps(ips).setLocations(locs).setAuxLocations(auxLocations).setInnerVlan(vlanId).setOuterTpid(ethType);
assertThat(config.isValid(), is(true));
assertThat(config.name(), is("-"));
assertThat(config.ipAddresses(), hasSize(3));
assertThat(config.ipAddresses(), hasItems(ip1, ip2, ip3));
assertThat(config.locations(), hasSize(2));
assertThat(config.locations(), hasItems(loc1, loc2));
assertThat(config.auxLocations(), hasSize(2));
assertThat(config.auxLocations(), hasItems(loc3, loc4));
assertThat(config.innerVlan(), is(vlanId));
assertThat(config.outerTpid(), is(ethType));
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class InterfaceConfigTest method getIp.
private InterfaceIpAddress getIp(int index, int position) {
IpPrefix subnet1 = IpPrefix.valueOf("1.2.0.0/16");
IpAddress ip = IpAddress.valueOf("1.2.3." + Integer.toString(index + ((position - 1) * 10)));
return new InterfaceIpAddress(ip, subnet1);
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class InterfaceIpAddressTest method testConstructorForDefaultBroadcastAddress.
/**
* Tests valid class constructor for regular interface address with
* default broadcast address.
*/
@Test
public void testConstructorForDefaultBroadcastAddress() {
InterfaceIpAddress addr = new InterfaceIpAddress(IP_ADDRESS, SUBNET_ADDRESS);
assertThat(addr.ipAddress(), is(IP_ADDRESS));
assertThat(addr.subnetAddress(), is(SUBNET_ADDRESS));
assertThat(addr.broadcastAddress(), is(DEF_BROADCAST_ADDRESS));
assertThat(addr.peerAddress(), nullValue());
IpPrefix subnetAddr = IpPrefix.valueOf("10.2.3.0/24");
InterfaceIpAddress addr1 = new InterfaceIpAddress(IP_ADDRESS2, subnetAddr);
assertThat(addr1.broadcastAddress().toString(), is("10.2.3.255"));
IpAddress ipAddress = IpAddress.valueOf("2001::4");
InterfaceIpAddress addr2 = new InterfaceIpAddress(ipAddress, V6_SUBNET_ADDRESS);
assertThat(addr2.broadcastAddress(), is(nullValue()));
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class KubevirtNetworkHandler method createBridge.
private void createBridge(KubevirtNode node, KubevirtNetwork network) {
Device tenantBridge = deviceService.getDevice(network.tenantDeviceId(node.hostname()));
if (tenantBridge != null && deviceService.isAvailable(tenantBridge.id())) {
log.warn("The tenant bridge {} already exists at node {}", network.tenantBridgeName(), node.hostname());
return;
}
Device device = deviceService.getDevice(node.ovsdb());
IpAddress controllerIp = apiConfigService.apiConfig().controllerIp();
String serviceFqdn = apiConfigService.apiConfig().serviceFqdn();
IpAddress serviceIp = null;
if (controllerIp == null) {
if (serviceFqdn != null) {
serviceIp = resolveHostname(serviceFqdn);
}
if (serviceIp != null) {
controllerIp = serviceIp;
} else {
controllerIp = apiConfigService.apiConfig().ipAddress();
}
}
ControllerInfo controlInfo = new ControllerInfo(controllerIp, DEFAULT_OFPORT, DEFAULT_OF_PROTO);
List<ControllerInfo> controllers = Lists.newArrayList(controlInfo);
String dpid = network.tenantDeviceId(node.hostname()).toString().substring(DPID_BEGIN);
// if the bridge is already available, we skip creating a new bridge
if (!deviceService.isAvailable(DeviceId.deviceId(dpid))) {
BridgeDescription.Builder builder = DefaultBridgeDescription.builder().name(network.tenantBridgeName()).failMode(BridgeDescription.FailMode.SECURE).datapathId(dpid).disableInBand().controllers(controllers);
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
bridgeConfig.addBridge(builder.build());
log.info("Created a new tunnel bridge for network {} at node {}", network.networkId(), node.hostname());
waitFor(3);
}
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class KubevirtPortJsonMatcher method matchesSafely.
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
// check VM name
String jsonVmName = jsonNode.get(VM_NAME).asText();
String vmName = port.vmName();
if (!jsonVmName.equals(vmName)) {
description.appendText("VM name was " + jsonVmName);
return false;
}
// check network ID
String jsonNetworkId = jsonNode.get(NETWORK_ID).asText();
String networkId = port.networkId();
if (!jsonNetworkId.equals(networkId)) {
description.appendText("network ID was " + jsonNetworkId);
return false;
}
// check MAC address
String jsonMacAddress = jsonNode.get(MAC_ADDRESS).asText();
String macAddress = port.macAddress().toString();
if (!jsonMacAddress.equals(macAddress)) {
description.appendText("MAC address was " + jsonMacAddress);
return false;
}
// check IP address
JsonNode jsonIpAddress = jsonNode.get(IP_ADDRESS);
if (jsonIpAddress != null) {
IpAddress ipAddress = port.ipAddress();
if (!jsonIpAddress.asText().equals(ipAddress.toString())) {
description.appendText("IP address was " + jsonIpAddress.asText());
return false;
}
}
// check device ID
JsonNode jsonDeviceId = jsonNode.get(DEVICE_ID);
if (jsonDeviceId != null) {
DeviceId deviceId = port.deviceId();
if (!jsonDeviceId.asText().equals(deviceId.toString())) {
description.appendText("Device ID was " + jsonDeviceId.asText());
return false;
}
}
// check port number
JsonNode jsonPortNumber = jsonNode.get(PORT_NUMBER);
if (jsonPortNumber != null) {
PortNumber portNUmber = port.portNumber();
if (!jsonPortNumber.asText().equals(portNUmber.toString())) {
description.appendText("Port number was " + jsonPortNumber.asText());
return false;
}
}
return true;
}
Aggregations