Search in sources :

Example 41 with MacAddress

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

the class K8sNetworkingUtil method syncPortFromPod.

/**
 * Synchronizes port from kubernetes POD.
 *
 * @param pod               kubernetes POD
 * @param adminService      admin service
 */
public static void syncPortFromPod(Pod pod, K8sNetworkAdminService adminService) {
    Map<String, String> annotations = pod.getMetadata().getAnnotations();
    if (annotations != null && !annotations.isEmpty() && annotations.get(PORT_ID) != null) {
        String portId = annotations.get(PORT_ID);
        K8sPort oldPort = adminService.port(portId);
        String networkId = annotations.get(NETWORK_ID);
        DeviceId deviceId = DeviceId.deviceId(annotations.get(DEVICE_ID));
        PortNumber portNumber = PortNumber.portNumber(annotations.get(PORT_NUMBER));
        IpAddress ipAddress = IpAddress.valueOf(annotations.get(IP_ADDRESS));
        MacAddress macAddress = MacAddress.valueOf(annotations.get(MAC_ADDRESS));
        K8sPort newPort = DefaultK8sPort.builder().portId(portId).networkId(networkId).deviceId(deviceId).ipAddress(ipAddress).macAddress(macAddress).portNumber(portNumber).state(INACTIVE).build();
        if (oldPort == null) {
            adminService.createPort(newPort);
        } else {
            adminService.updatePort(newPort);
        }
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultK8sPort(org.onosproject.k8snetworking.api.DefaultK8sPort) K8sPort(org.onosproject.k8snetworking.api.K8sPort) IpAddress(org.onlab.packet.IpAddress) PortNumber(org.onosproject.net.PortNumber) MacAddress(org.onlab.packet.MacAddress)

Example 42 with MacAddress

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

the class ReactiveRoutingFib method setUpConnectivityHostToHost.

@Override
public void setUpConnectivityHostToHost(IpAddress dstIpAddress, IpAddress srcIpAddress, MacAddress srcMacAddress, ConnectPoint srcConnectPoint) {
    checkNotNull(dstIpAddress);
    checkNotNull(srcIpAddress);
    checkNotNull(srcMacAddress);
    checkNotNull(srcConnectPoint);
    IpPrefix srcIpPrefix = srcIpAddress.toIpPrefix();
    IpPrefix dstIpPrefix = dstIpAddress.toIpPrefix();
    ConnectPoint dstConnectPoint = null;
    MacAddress dstMacAddress = null;
    for (Host host : hostService.getHostsByIp(dstIpAddress)) {
        if (host.mac() != null) {
            dstMacAddress = host.mac();
            dstConnectPoint = host.location();
            break;
        }
    }
    if (dstMacAddress == null) {
        hostService.startMonitoringIp(dstIpAddress);
        return;
    }
    // 
    // Handle intent from source host to destination host
    // 
    MultiPointToSinglePointIntent srcToDstIntent = hostToHostIntentGenerator(dstIpAddress, dstConnectPoint, dstMacAddress, srcConnectPoint);
    submitReactiveIntent(dstIpPrefix, srcToDstIntent);
    // first.
    if (mp2pIntentExists(srcIpPrefix)) {
        updateExistingMp2pIntent(srcIpPrefix, dstConnectPoint);
        return;
    } else {
        // There is no existing intent, create a new one.
        MultiPointToSinglePointIntent dstToSrcIntent = hostToHostIntentGenerator(srcIpAddress, srcConnectPoint, srcMacAddress, dstConnectPoint);
        submitReactiveIntent(srcIpPrefix, dstToSrcIntent);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent)

Example 43 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 44 with MacAddress

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

the class ReactiveRoutingFib method setUpConnectivityInternetToHost.

@Override
public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) {
    checkNotNull(hostIpAddress);
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (hostIpAddress.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
    }
    // Match the destination IP prefix at the first hop
    IpPrefix ipPrefix = hostIpAddress.toIpPrefix();
    selector.matchIPDst(ipPrefix);
    // Rewrite the destination MAC address
    MacAddress hostMac = null;
    FilteredConnectPoint egressPoint = null;
    for (Host host : hostService.getHostsByIp(hostIpAddress)) {
        if (host.mac() != null) {
            hostMac = host.mac();
            egressPoint = new FilteredConnectPoint(host.location());
            break;
        }
    }
    if (hostMac == null) {
        hostService.startMonitoringIp(hostIpAddress);
        return;
    }
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthDst(hostMac);
    Key key = Key.of(ipPrefix.toString(), appId);
    int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
    Set<ConnectPoint> interfaceConnectPoints = interfaceService.getInterfaces().stream().map(intf -> intf.connectPoint()).collect(Collectors.toSet());
    if (interfaceConnectPoints.isEmpty()) {
        log.error("The interface connect points are empty!");
        return;
    }
    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    for (ConnectPoint connectPoint : interfaceConnectPoints) {
        if (!connectPoint.equals(egressPoint.connectPoint())) {
            ingressPoints.add(new FilteredConnectPoint(connectPoint));
        }
    }
    MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(appId).key(key).selector(selector.build()).treatment(treatment.build()).filteredIngressPoints(ingressPoints).filteredEgressPoint(egressPoint).priority(priority).constraints(CONSTRAINTS).build();
    log.trace("Generates ConnectivityInternetToHost intent {}", intent);
    submitReactiveIntent(ipPrefix, intent);
}
Also used : Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) HashSet(java.util.HashSet) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) IntentSynchronizationService(org.onosproject.intentsync.IntentSynchronizationService) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Constraint(org.onosproject.net.intent.Constraint) Key(org.onosproject.net.intent.Key) MacAddress(org.onlab.packet.MacAddress) Collections(java.util.Collections) IpPrefix(org.onlab.packet.IpPrefix) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) 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) IpPrefix(org.onlab.packet.IpPrefix) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 45 with MacAddress

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

the class JuniperUtils method parseJuniperLldp.

/**
 * Parses neighbours discovery information and returns a list of
 * link abstractions.
 *
 * @param info interface configuration
 * @return set of link abstractions
 */
public static Set<LinkAbstraction> parseJuniperLldp(HierarchicalConfiguration info) {
    Set<LinkAbstraction> neighbour = new HashSet<>();
    List<HierarchicalConfiguration> subtrees = info.configurationsAt(LLDP_LIST_NBR_INFO);
    for (HierarchicalConfiguration neighborsInfo : subtrees) {
        List<HierarchicalConfiguration> neighbors = neighborsInfo.configurationsAt(LLDP_NBR_INFO);
        for (HierarchicalConfiguration neighbor : neighbors) {
            String localPortName = neighbor.getString(LLDP_LO_PORT);
            MacAddress mac = MacAddress.valueOf(neighbor.getString(LLDP_REM_CHASS));
            String remotePortId = null;
            long remotePortIndex = -1;
            String remotePortIdSubtype = neighbor.getString(LLDP_REM_PORT_SUBTYPE, null);
            if (remotePortIdSubtype != null) {
                if (remotePortIdSubtype.equals(LLDP_SUBTYPE_MAC) || remotePortIdSubtype.equals(LLDP_SUBTYPE_INTERFACE_NAME)) {
                    remotePortId = neighbor.getString(LLDP_REM_PORT, null);
                } else {
                    remotePortIndex = neighbor.getLong(LLDP_REM_PORT, -1);
                }
            }
            String remotePortDescription = neighbor.getString(LLDP_REM_PORT_DES, null);
            LinkAbstraction link = new LinkAbstraction(localPortName, mac.toLong(), remotePortIndex, remotePortId, remotePortDescription);
            neighbour.add(link);
        }
    }
    return neighbour;
}
Also used : XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) MacAddress(org.onlab.packet.MacAddress) HashSet(java.util.HashSet)

Aggregations

MacAddress (org.onlab.packet.MacAddress)175 VlanId (org.onlab.packet.VlanId)67 IpAddress (org.onlab.packet.IpAddress)65 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)44 TrafficSelector (org.onosproject.net.flow.TrafficSelector)40 Host (org.onosproject.net.Host)38 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)36 Set (java.util.Set)33 HostLocation (org.onosproject.net.HostLocation)32 Logger (org.slf4j.Logger)32 Ethernet (org.onlab.packet.Ethernet)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