Search in sources :

Example 6 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class ReactiveRoutingFib method setUpConnectivityHostToInternet.

@Override
public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix, IpAddress nextHopIpAddress) {
    // Find the attachment point (egress interface) of the next hop
    Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
    if (egressInterface == null) {
        log.warn("No outgoing interface found for {}", nextHopIpAddress);
        return;
    }
    Set<Host> hosts = hostService.getHostsByIp(nextHopIpAddress);
    if (hosts.isEmpty()) {
        log.warn("No host found for next hop IP address");
        return;
    }
    MacAddress nextHopMacAddress = null;
    for (Host host : hosts) {
        nextHopMacAddress = host.mac();
        break;
    }
    hosts = hostService.getHostsByIp(hostIp);
    if (hosts.isEmpty()) {
        log.warn("No host found for host IP address");
        return;
    }
    Host host = hosts.stream().findFirst().get();
    ConnectPoint ingressPoint = host.location();
    // Generate the intent itself
    ConnectPoint egressPort = egressInterface.connectPoint();
    log.debug("Generating intent for prefix {}, next hop mac {}", prefix, nextHopMacAddress);
    // Match the destination IP prefix at the first hop
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (prefix.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        selector.matchIPDst(prefix);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        selector.matchIPv6Dst(prefix);
    }
    // Rewrite the destination MAC address
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(nextHopMacAddress);
    if (!egressInterface.vlan().equals(VlanId.NONE)) {
        treatment.setVlanId(egressInterface.vlan());
        // If we set VLAN ID, we have to make sure a VLAN tag exists.
        // TODO support no VLAN -> VLAN routing
        selector.matchVlanId(VlanId.ANY);
    }
    int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
    Key key = Key.of(prefix.toString() + "-reactive", appId);
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(Collections.singleton(new FilteredConnectPoint(ingressPoint))).filteredEgressPoint(new FilteredConnectPoint(egressPort)).priority(priority).constraints(CONSTRAINTS).build();
    submitReactiveIntent(prefix, intent);
}
Also used : Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Constraint(org.onosproject.net.intent.Constraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Interface(org.onosproject.net.intf.Interface) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 7 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class VirtualHostCreateCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
    Set<IpAddress> hostIps = new HashSet<>();
    if (hostIpStrings != null) {
        Arrays.stream(hostIpStrings).forEach(s -> hostIps.add(IpAddress.valueOf(s)));
    }
    HostLocation hostLocation = new HostLocation(DeviceId.deviceId(hostLocationDeviceId), PortNumber.portNumber(hostLocationPortNumber), System.currentTimeMillis());
    MacAddress macAddress = MacAddress.valueOf(mac);
    VlanId vlanId = VlanId.vlanId(vlan);
    service.createVirtualHost(NetworkId.networkId(networkId), HostId.hostId(macAddress, vlanId), macAddress, vlanId, hostLocation, hostIps);
    print("Virtual host successfully created.");
}
Also used : HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 8 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class VirtualHostCodecTest method testEncode.

@Test
public void testEncode() {
    MockCodecContext context = new MockCodecContext();
    NetworkId networkId = NetworkId.networkId(TEST_NETWORK_ID);
    HostId id = NetTestTools.hid(TEST_HOST_ID);
    MacAddress mac = MacAddress.valueOf(TEST_MAC_ADDRESS);
    VlanId vlan = VlanId.vlanId(TEST_VLAN_ID);
    HostLocation location = new HostLocation(CONNECT_POINT, 0L);
    Set<IpAddress> ips = ImmutableSet.of(IpAddress.valueOf(TEST_IP1), IpAddress.valueOf(TEST_IP2));
    VirtualHost host = new DefaultVirtualHost(networkId, id, mac, vlan, location, ips);
    JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
    ObjectNode node = codec.encode(host, context);
    assertThat(node.get(VirtualHostCodec.NETWORK_ID).asLong(), is(TEST_NETWORK_ID));
    assertThat(node.get(VirtualHostCodec.HOST_ID).asText(), is(TEST_HOST_ID));
    assertThat(node.get(VirtualHostCodec.MAC_ADDRESS).asText(), is(TEST_MAC_ADDRESS));
    assertThat(node.get(VirtualHostCodec.VLAN).asInt(), is((int) TEST_VLAN_ID));
    assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("elementId").asText(), is(location.deviceId().toString()));
    assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("port").asLong(), is(location.port().toLong()));
    JsonNode jsonIps = node.get(VirtualHostCodec.IP_ADDRESSES);
    assertThat(jsonIps, notNullValue());
    assertThat(jsonIps.isArray(), is(true));
    assertThat(jsonIps.size(), is(ips.size()));
    IntStream.of(0, 1).forEach(index -> assertThat(jsonIps.get(index).asText(), isOneOf(TEST_IP1, TEST_IP2)));
}
Also used : DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) MockCodecContext(org.onosproject.codec.impl.MockCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) HostId(org.onosproject.net.HostId) MacAddress(org.onlab.packet.MacAddress) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

Example 9 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class VbngManager method statusRecovery.

/**
 * Recovers from XOS record. Re-sets up the mapping between private IP
 * address and public IP address, re-calculates intents and re-installs
 * those intents.
 */
private void statusRecovery() {
    log.info("vBNG starts to recover from XOS record......");
    ObjectNode map;
    try {
        RestClient restClient = new RestClient(vbngConfigurationService.getXosIpAddress(), vbngConfigurationService.getXosRestPort());
        map = restClient.getRest();
    } catch (Exception e) {
        log.warn("Could not contact XOS {}", e.getMessage());
        return;
    }
    if (map == null) {
        log.info("Stop to recover vBNG status due to the vBNG map " + "is null!");
        return;
    }
    log.info("Get record from XOS: {}", map);
    ArrayNode array = (ArrayNode) map.get(VBNG_MAP_NAME);
    Iterator<JsonNode> entries = array.elements();
    while (entries.hasNext()) {
        ObjectNode entry = (ObjectNode) entries.next();
        IpAddress hostIpAdddress = IpAddress.valueOf(entry.get("private_ip").asText());
        IpAddress publicIpAddress = IpAddress.valueOf(entry.get("routeable_subnet").asText());
        MacAddress macAddress = MacAddress.valueOf(entry.get("mac").asText());
        String hostName = entry.get("hostname").asText();
        // Create vBNG
        createVbng(hostIpAdddress, publicIpAddress, macAddress, hostName);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) MacAddress(org.onlab.packet.MacAddress)

Example 10 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class NetworkConfigHostProvider method readInitialConfig.

private void readInitialConfig() {
    networkConfigRegistry.getSubjects(HostId.class).forEach(hostId -> {
        MacAddress mac = hostId.mac();
        VlanId vlan = hostId.vlanId();
        BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
        Set<IpAddress> ipAddresses = hostConfig.ipAddresses();
        Set<HostLocation> locs = hostConfig.locations();
        if (locs != null) {
            Set<HostLocation> locations = locs.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
            // auxLocations allows to be null
            Set<HostLocation> auxLocations = hostConfig.auxLocations();
            if (auxLocations != null) {
                auxLocations = auxLocations.stream().map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis())).collect(Collectors.toSet());
            }
            VlanId innerVlan = hostConfig.innerVlan();
            EthType outerTpid = hostConfig.outerTpid();
            addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
        } else {
            log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
        }
    });
}
Also used : NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) HostLocation(org.onosproject.net.HostLocation) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Host(org.onosproject.net.Host) CoreService(org.onosproject.core.CoreService) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LoggerFactory(org.slf4j.LoggerFactory) HostProviderService(org.onosproject.net.host.HostProviderService) Component(org.osgi.service.component.annotations.Component) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) ApplicationId(org.onosproject.core.ApplicationId) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) AbstractProvider(org.onosproject.net.provider.AbstractProvider) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) EthType(org.onlab.packet.EthType) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) HostDescription(org.onosproject.net.host.HostDescription) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Collections(java.util.Collections) EthType(org.onlab.packet.EthType) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) HostId(org.onosproject.net.HostId) MacAddress(org.onlab.packet.MacAddress) VlanId(org.onlab.packet.VlanId) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig)

Aggregations

MacAddress (org.onlab.packet.MacAddress)171 VlanId (org.onlab.packet.VlanId)66 IpAddress (org.onlab.packet.IpAddress)63 ConnectPoint (org.onosproject.net.ConnectPoint)55 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)54 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)53 DeviceId (org.onosproject.net.DeviceId)43 Host (org.onosproject.net.Host)38 TrafficSelector (org.onosproject.net.flow.TrafficSelector)37 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)36 Set (java.util.Set)33 HostLocation (org.onosproject.net.HostLocation)32 Ethernet (org.onlab.packet.Ethernet)31 Logger (org.slf4j.Logger)31 PortNumber (org.onosproject.net.PortNumber)29 List (java.util.List)27 HostId (org.onosproject.net.HostId)27 Interface (org.onosproject.net.intf.Interface)27 IpPrefix (org.onlab.packet.IpPrefix)26 LoggerFactory (org.slf4j.LoggerFactory)24