Search in sources :

Example 91 with MacAddress

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

the class OpenstackK8sIntegrationWebResource method installCniPtNodeRules.

/**
 * Installs CNI pass-through related flow rules for each kubernetes nodes.
 *
 * @param input JSON string
 * @return 200 ok, 400 BAD_REQUEST if the json is malformed
 * @throws IOException exception
 */
@PUT
@Path("node/pt-install")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response installCniPtNodeRules(InputStream input) throws IOException {
    log.trace("Install K8S CNI pass-through node rules");
    JsonNode json = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
    IpAddress k8sNodeIp = IpAddress.valueOf(json.get(K8S_NODE_IP).asText());
    IpPrefix podCidr = IpPrefix.valueOf(json.get(POD_CIDR).asText());
    IpPrefix serviceCidr = IpPrefix.valueOf(json.get(SERVICE_CIDR).asText());
    IpAddress podGwIp = IpAddress.valueOf(json.get(POD_GW_IP).asText());
    String osK8sIntPortName = json.get(OS_K8S_INT_PORT_NAME).asText();
    MacAddress k8sIntOsPortMac = MacAddress.valueOf(json.get(K8S_INT_OS_PORT_MAC).asText());
    intService.installCniPtNodeRules(k8sNodeIp, podCidr, serviceCidr, podGwIp, osK8sIntPortName, k8sIntOsPortMac);
    return Response.ok().build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) PUT(javax.ws.rs.PUT)

Example 92 with MacAddress

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

the class OpenstackK8sIntegrationWebResource method uninstallCniPtNodeRules.

/**
 * Uninstalls CNI pass-through related flow rules for each kubernetes nodes.
 *
 * @param input JSON string
 * @return 200 ok, 400 BAD_REQUEST if the json is malformed
 * @throws IOException exception
 */
@PUT
@Path("node/pt-uninstall")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response uninstallCniPtNodeRules(InputStream input) throws IOException {
    log.trace("Uninstall K8S CNI pass-through node rules");
    JsonNode json = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
    IpAddress k8sNodeIp = IpAddress.valueOf(json.get(K8S_NODE_IP).asText());
    IpPrefix podCidr = IpPrefix.valueOf(json.get(POD_CIDR).asText());
    IpPrefix serviceCidr = IpPrefix.valueOf(json.get(SERVICE_CIDR).asText());
    IpAddress podGwIp = IpAddress.valueOf(json.get(POD_GW_IP).asText());
    String osK8sIntPortName = json.get(OS_K8S_INT_PORT_NAME).asText();
    MacAddress k8sIntOsPortMac = MacAddress.valueOf(json.get(K8S_INT_OS_PORT_MAC).asText());
    intService.uninstallCniPtNodeRules(k8sNodeIp, podCidr, serviceCidr, podGwIp, osK8sIntPortName, k8sIntOsPortMac);
    return Response.ok().build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) PUT(javax.ws.rs.PUT)

Example 93 with MacAddress

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

the class SimpleFabricManager method refresh.

// Set up from configuration
// returns found isDirty and refresh listeners are called (true) or not (false)
private boolean refresh() {
    log.debug("simple fabric refresh");
    boolean dirty = false;
    SimpleFabricConfig config = configService.getConfig(coreService.registerApplication(APP_ID), SimpleFabricConfig.class);
    if (config == null) {
        log.debug("No simple fabric config available!");
        return false;
    }
    // fabricNetworks
    Set<FabricNetwork> newFabricNetworks = new HashSet<>();
    Set<Interface> newInterfaces = new HashSet<>();
    for (FabricNetwork newFabricNetworkConfig : config.fabricNetworks()) {
        FabricNetwork newFabricNetwork = DefaultFabricNetwork.of(newFabricNetworkConfig);
        // fill up interfaces and Hosts with active port only
        for (String ifaceName : newFabricNetworkConfig.interfaceNames()) {
            Interface iface = getInterfaceByName(ifaceName);
            if (iface != null && deviceService.isAvailable(iface.connectPoint().deviceId())) {
                newFabricNetwork.addInterface(iface);
                newInterfaces.add(iface);
            }
        }
        for (Host host : hostService.getHosts()) {
            // consider host with ip only
            if (!host.ipAddresses().isEmpty()) {
                Interface iface = findAvailableDeviceHostInterface(host);
                if (iface != null && newFabricNetwork.contains(iface)) {
                    newFabricNetwork.addHost(host);
                }
            }
        }
        newFabricNetwork.setDirty(true);
        // update newFabricNetwork's isDirty flags if same entry already exists
        for (FabricNetwork prevFabricNetwork : fabricNetworks) {
            if (prevFabricNetwork.equals(newFabricNetwork)) {
                newFabricNetwork.setDirty(prevFabricNetwork.isDirty());
                break;
            }
        }
        newFabricNetworks.add(newFabricNetwork);
    }
    if (!fabricNetworks.equals(newFabricNetworks)) {
        fabricNetworks = newFabricNetworks;
        dirty = true;
    }
    if (!networkInterfaces.equals(newInterfaces)) {
        networkInterfaces = newInterfaces;
        dirty = true;
    }
    // default Fabric Subnets
    Set<FabricSubnet> newFabricSubnets = config.fabricSubnets();
    InvertedRadixTree<FabricSubnet> newIp4SubnetTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    InvertedRadixTree<FabricSubnet> newIp6SubnetTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
    Map<IpAddress, MacAddress> newVirtualGatewayIpMacMap = Maps.newConcurrentMap();
    for (FabricSubnet subnet : newFabricSubnets) {
        if (subnet.prefix().isIp4()) {
            newIp4SubnetTable.put(createBinaryString(subnet.prefix()), subnet);
        } else {
            newIp6SubnetTable.put(createBinaryString(subnet.prefix()), subnet);
        }
        newVirtualGatewayIpMacMap.put(subnet.gatewayIp(), subnet.gatewayMac());
    }
    if (!fabricSubnets.equals(newFabricSubnets)) {
        fabricSubnets = newFabricSubnets;
        ip4SubnetTable = newIp4SubnetTable;
        ip6SubnetTable = newIp6SubnetTable;
        dirty = true;
    }
    if (!virtualGatewayIpMacMap.equals(newVirtualGatewayIpMacMap)) {
        virtualGatewayIpMacMap = newVirtualGatewayIpMacMap;
        dirty = true;
    }
    // fabricRoutes config handling
    Set<FabricRoute> newFabricRoutes = config.fabricRoutes();
    if (!fabricRoutes.equals(newFabricRoutes)) {
        InvertedRadixTree<FabricRoute> newIp4BorderRouteTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
        InvertedRadixTree<FabricRoute> newIp6BorderRouteTable = new ConcurrentInvertedRadixTree<>(new DefaultByteArrayNodeFactory());
        for (FabricRoute route : newFabricRoutes) {
            if (route.prefix().isIp4()) {
                newIp4BorderRouteTable.put(createBinaryString(route.prefix()), route);
            } else {
                newIp6BorderRouteTable.put(createBinaryString(route.prefix()), route);
            }
        }
        fabricRoutes = newFabricRoutes;
        ip4BorderRouteTable = newIp4BorderRouteTable;
        ip6BorderRouteTable = newIp6BorderRouteTable;
        dirty = true;
    }
    // notify to SimpleFabric listeners
    if (dirty) {
        log.info("simple fabric refresh; notify events");
        process(new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_UPDATED, "updated"));
    }
    return dirty;
}
Also used : DefaultByteArrayNodeFactory(com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory) Host(org.onosproject.net.Host) RouteTools.createBinaryString(org.onosproject.routeservice.RouteTools.createBinaryString) MacAddress(org.onlab.packet.MacAddress) SimpleFabricEvent(org.onosproject.simplefabric.api.SimpleFabricEvent) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) FabricRoute(org.onosproject.simplefabric.api.FabricRoute) FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) IpAddress(org.onlab.packet.IpAddress) ConcurrentInvertedRadixTree(com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree) Interface(org.onosproject.net.intf.Interface) HashSet(java.util.HashSet)

Example 94 with MacAddress

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

the class SimpleFabricRouting method ipPacketReactiveProcessor.

/**
 * Routes packet reactively.
 */
private void ipPacketReactiveProcessor(PacketContext context, Ethernet ethPkt, ConnectPoint srcCp, IpAddress srcIp, IpAddress dstIp, byte ipProto) {
    /* check reactive handling and forward packet */
    log.trace("ip packet: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
    EncapsulationType encap = EncapsulationType.NONE;
    // prefix and nextHop for local Subnet
    IpPrefix srcPrefix = srcIp.toIpPrefix();
    IpPrefix dstPrefix = dstIp.toIpPrefix();
    IpAddress srcNextHop = srcIp;
    IpAddress dstNextHop = dstIp;
    MacAddress treatmentSrcMac = ethPkt.getDestinationMAC();
    int borderRoutePrefixLength = 0;
    boolean updateMac = simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC());
    // check subnet local or route
    FabricSubnet srcSubnet = simpleFabric.fabricSubnet(srcIp);
    if (srcSubnet == null) {
        FabricRoute route = simpleFabric.fabricRoute(srcIp);
        if (route == null) {
            log.warn("unknown srcIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
            return;
        }
        srcPrefix = route.prefix();
        srcNextHop = route.nextHop();
        borderRoutePrefixLength = route.prefix().prefixLength();
    }
    FabricSubnet dstSubnet = simpleFabric.fabricSubnet(dstIp);
    if (dstSubnet == null) {
        FabricRoute route = simpleFabric.fabricRoute(dstIp);
        if (route == null) {
            log.warn("unknown dstIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
            return;
        }
        dstPrefix = route.prefix();
        dstNextHop = route.nextHop();
        borderRoutePrefixLength = route.prefix().prefixLength();
    }
    if (dstSubnet != null) {
        // destination is local subnet ip
        if (ALLOW_ETH_ADDRESS_SELECTOR && dstSubnet.equals(srcSubnet)) {
            // NOTE: if ALLOW_ETH_ADDRESS_SELECTOR=false; isForward is always false
            FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.networkName());
            treatmentSrcMac = ethPkt.getSourceMAC();
            if (fabricNetwork != null && fabricNetwork.isForward()) {
                // NOTE: no reactive route action but do forward packet for L2Forward do not handle packet
                // update mac only if dstMac is virtualGatewayMac, else assume valid mac already for the l2 network
                log.info("LOCAL FORWARD ONLY: " + "srcCp={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
                forwardPacketToDstIp(context, dstIp, treatmentSrcMac, updateMac);
                return;
            }
        }
        encap = dstSubnet.encapsulation();
        if (encap == EncapsulationType.NONE && srcSubnet != null) {
            encap = srcSubnet.encapsulation();
        }
    } else {
        // destination is external network
        if (srcSubnet == null) {
            // both are externel network
            log.warn("INVALID PACKET: srcIp and dstIp are both NON-LOCAL: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
            return;
        }
        encap = srcSubnet.encapsulation();
    }
    log.info("REGI AND FORWARD: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
    setUpConnectivity(srcCp, ipProto, srcPrefix, dstPrefix, dstNextHop, treatmentSrcMac, encap, updateMac, dstSubnet != null, borderRoutePrefixLength);
    forwardPacketToDstIp(context, dstNextHop, treatmentSrcMac, updateMac);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) EncapsulationType(org.onosproject.net.EncapsulationType) FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) ConnectPoint(org.onosproject.net.ConnectPoint) Constraint(org.onosproject.net.intent.Constraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FabricRoute(org.onosproject.simplefabric.api.FabricRoute)

Example 95 with MacAddress

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

the class SimpleFabricRouting method setUpConnectivity.

/**
 * Update intents for connectivity.
 *
 * ToHost: dstPrefix = dstHostIp.toIpPrefix(), nextHopIp = destHostIp
 * ToInternet: dstPrefix = route.prefix(), nextHopIp = route.nextHopIp
 * returns intent submitted or not
 */
private boolean setUpConnectivity(ConnectPoint srcCp, byte ipProto, IpPrefix srcPrefix, IpPrefix dstPrefix, IpAddress nextHopIp, MacAddress treatmentSrcMac, EncapsulationType encap, boolean updateMac, boolean isDstLocalSubnet, int borderRoutePrefixLength) {
    if (!(simpleFabric.fabricNetwork(srcCp, VlanId.NONE) != null || (REACTIVE_ALLOW_LINK_CP && !linkService.getIngressLinks(srcCp).isEmpty()))) {
        log.warn("NO REGI for srcCp not in DefaultFabricNetwork; srcCp={} srcPrefix={} dstPrefix={} nextHopIp={}", srcCp, srcPrefix, dstPrefix, nextHopIp);
        return false;
    }
    MacAddress nextHopMac = null;
    ConnectPoint egressPoint = null;
    for (Host host : hostService.getHostsByIp(nextHopIp)) {
        if (host.mac() != null) {
            nextHopMac = host.mac();
            egressPoint = host.location();
            break;
        }
    }
    if (nextHopMac == null || egressPoint == null) {
        log.info("NO REGI for unknown nextHop Cp and Mac: srcPrefix={} dstPrefix={} nextHopIp={}", srcPrefix, dstPrefix, nextHopIp);
        hostService.startMonitoringIp(nextHopIp);
        simpleFabric.requestMac(nextHopIp);
        return false;
    }
    TrafficTreatment treatment;
    if (updateMac && ALLOW_ETH_ADDRESS_SELECTOR) {
        treatment = generateSetMacTreatment(nextHopMac, treatmentSrcMac);
    } else {
        treatment = DefaultTrafficTreatment.builder().build();
    }
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (dstPrefix.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        if (REACTIVE_SINGLE_TO_SINGLE && srcPrefix.prefixLength() > 0) {
            selector.matchIPSrc(srcPrefix);
        }
        if (dstPrefix.prefixLength() > 0) {
            selector.matchIPDst(dstPrefix);
        }
        if (ipProto != 0 && REACTIVE_MATCH_IP_PROTO) {
            selector.matchIPProtocol(ipProto);
        }
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        if (REACTIVE_SINGLE_TO_SINGLE && srcPrefix.prefixLength() > 0) {
            selector.matchIPv6Src(srcPrefix);
        }
        if (dstPrefix.prefixLength() > 0) {
            selector.matchIPv6Dst(dstPrefix);
        }
        if (ipProto != 0 && REACTIVE_MATCH_IP_PROTO) {
            selector.matchIPProtocol(ipProto);
        }
    }
    Key key;
    String keyProtoTag = "";
    if (REACTIVE_MATCH_IP_PROTO) {
        keyProtoTag = "-p" + ipProto;
    }
    if (REACTIVE_SINGLE_TO_SINGLE) {
        // allocate intent per (srcPrefix, dstPrefix)
        key = Key.of(srcPrefix.toString() + "-to-" + dstPrefix.toString() + keyProtoTag, appId);
    } else {
        // allocate intent per (srcDeviceId, dstPrefix)
        key = Key.of(srcCp.deviceId().toString() + "-to-" + dstPrefix.toString() + keyProtoTag, appId);
    }
    // check and merge already existing ingress points
    Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
    MultiPointToSinglePointIntent existingIntent = (MultiPointToSinglePointIntent) intentService.getIntent(key);
    if (existingIntent != null) {
        ingressPoints.addAll(existingIntent.filteredIngressPoints());
        if (// alread exists and dst not changed
        !ingressPoints.add(new FilteredConnectPoint(srcCp)) && egressPoint.equals(existingIntent.egressPoint()) && treatment.equals(existingIntent.treatment())) {
            log.warn("srcCP is already in mp2p intent: srcPrefix={} dstPrefix={} srcCp={}", srcPrefix, dstPrefix, srcCp);
            return false;
        }
        log.info("update mp2p intent: srcPrefix={} dstPrefix={} srcCp={}", srcPrefix, dstPrefix, srcCp);
    } else {
        log.info("create mp2p intent: srcPrefix={} dstPrefix={} srcCp={}", srcPrefix, dstPrefix, srcCp);
        ingressPoints.add(new FilteredConnectPoint(srcCp));
    }
    // priority for forwarding case
    int priority = reactivePriority(true, isDstLocalSubnet, borderRoutePrefixLength);
    MultiPointToSinglePointIntent newIntent = MultiPointToSinglePointIntent.builder().key(key).appId(appId).selector(selector.build()).treatment(treatment).filteredIngressPoints(ingressPoints).filteredEgressPoint(new FilteredConnectPoint(egressPoint)).priority(priority).constraints(buildConstraints(reactiveConstraints, encap)).build();
    log.info("submit mp2p intent: srcPrefix={} dstPrefix={} srcCp={} " + "newIntent={} nextHopIp={} nextHopMac={} priority={}", srcPrefix, dstPrefix, ingressPoints, newIntent, nextHopIp, nextHopMac, priority);
    toBePurgedIntentKeys.remove(newIntent.key());
    intentService.submit(newIntent);
    return true;
}
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) HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) ConnectPoint(org.onosproject.net.ConnectPoint) Constraint(org.onosproject.net.intent.Constraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) 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)

Aggregations

MacAddress (org.onlab.packet.MacAddress)122 IpAddress (org.onlab.packet.IpAddress)52 VlanId (org.onlab.packet.VlanId)46 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)41 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)41 ConnectPoint (org.onosproject.net.ConnectPoint)33 Host (org.onosproject.net.Host)30 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)29 TrafficSelector (org.onosproject.net.flow.TrafficSelector)29 HostLocation (org.onosproject.net.HostLocation)27 HostId (org.onosproject.net.HostId)26 Ethernet (org.onlab.packet.Ethernet)24 DeviceId (org.onosproject.net.DeviceId)23 Interface (org.onosproject.net.intf.Interface)22 Set (java.util.Set)20 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)19 Device (org.onosproject.net.Device)19 Logger (org.slf4j.Logger)19 ProviderId (org.onosproject.net.provider.ProviderId)18 Ip4Address (org.onlab.packet.Ip4Address)16