Search in sources :

Example 76 with IpAddress

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));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HostLocation(org.onosproject.net.HostLocation) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Test(org.junit.Test) Matchers.hasItems(org.hamcrest.Matchers.hasItems) EthType(org.onlab.packet.EthType) NetTestTools(org.onosproject.net.NetTestTools) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) EthType(org.onlab.packet.EthType) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) HostId(org.onosproject.net.HostId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Test(org.junit.Test)

Example 77 with IpAddress

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);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress)

Example 78 with IpAddress

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()));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress) Test(org.junit.Test)

Example 79 with IpAddress

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);
    }
}
Also used : Device(org.onosproject.net.Device) IpAddress(org.onlab.packet.IpAddress) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 80 with IpAddress

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;
}
Also used : DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) PortNumber(org.onosproject.net.PortNumber)

Aggregations

IpAddress (org.onlab.packet.IpAddress)288 MacAddress (org.onlab.packet.MacAddress)63 VlanId (org.onlab.packet.VlanId)52 ConnectPoint (org.onosproject.net.ConnectPoint)48 Set (java.util.Set)46 DeviceId (org.onosproject.net.DeviceId)44 Logger (org.slf4j.Logger)40 Test (org.junit.Test)37 Collectors (java.util.stream.Collectors)36 Ethernet (org.onlab.packet.Ethernet)36 IpPrefix (org.onlab.packet.IpPrefix)36 HostId (org.onosproject.net.HostId)33 Host (org.onosproject.net.Host)32 Optional (java.util.Optional)30 HostLocation (org.onosproject.net.HostLocation)30 LoggerFactory (org.slf4j.LoggerFactory)30 ApplicationId (org.onosproject.core.ApplicationId)29 CoreService (org.onosproject.core.CoreService)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28