Search in sources :

Example 1 with FabricSubnet

use of org.onosproject.simplefabric.api.FabricSubnet in project onos by opennetworkinglab.

the class SimpleFabricConfig method fabricSubnets.

/**
 * Gets the set of configured local subnets.
 *
 * @return a set of subnets
 */
public Set<FabricSubnet> fabricSubnets() {
    Set<FabricSubnet> subnets = Sets.newHashSet();
    JsonNode subnetsNode = object.get(FABRIC_SUBNETS);
    if (subnetsNode == null) {
        log.warn("FabricSubnets is null!");
        return subnets;
    }
    subnetsNode.forEach(jsonNode -> {
        // NONE or VLAN
        String encapsulation = NONE_ENCAPSULATION;
        if (jsonNode.hasNonNull(ENCAPSULATION)) {
            encapsulation = jsonNode.get(ENCAPSULATION).asText();
        }
        try {
            subnets.add(DefaultFabricSubnet.builder().prefix(IpPrefix.valueOf(jsonNode.get(PREFIX).asText())).gatewayIp(IpAddress.valueOf(jsonNode.get(GATEWAY_IP).asText())).gatewayMac(MacAddress.valueOf(jsonNode.get(GATEWAY_MAC).asText())).encapsulation(EncapsulationType.enumFromString(encapsulation)).networkName(jsonNode.get(NETWORK_NAME).asText()).build());
        } catch (Exception e) {
            log.warn("Fabric subnet parse failed; skip: jsonNode={}", jsonNode);
        }
    });
    return subnets;
}
Also used : FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with FabricSubnet

use of org.onosproject.simplefabric.api.FabricSubnet in project onos by opennetworkinglab.

the class SimpleFabricManager method dump.

// Dump handler
protected void dump(String subject, PrintStream out) {
    if ("show".equals(subject)) {
        out.println("Static Configuration Flag:");
        out.println("    ALLOW_IPV6=" + ALLOW_IPV6);
        out.println("    ALLOW_ETH_ADDRESS_SELECTOR=" + ALLOW_ETH_ADDRESS_SELECTOR);
        out.println("    REACTIVE_SINGLE_TO_SINGLE=" + REACTIVE_SINGLE_TO_SINGLE);
        out.println("    REACTIVE_ALLOW_LINK_CP=" + REACTIVE_ALLOW_LINK_CP);
        out.println("    REACTIVE_HASHED_PATH_SELECTION=" + REACTIVE_HASHED_PATH_SELECTION);
        out.println("    REACTIVE_MATCH_IP_PROTO=" + REACTIVE_MATCH_IP_PROTO);
        out.println("");
        out.println("SimpleFabricAppId:");
        out.println("    " + appId());
        out.println("");
        out.println("fabricNetworks:");
        for (FabricNetwork fabricNetwork : fabricNetworks()) {
            out.println("    " + fabricNetwork);
        }
        out.println("");
        out.println("fabricSubnets:");
        for (FabricSubnet fabricIpSubnet : defaultFabricSubnets()) {
            out.println("    " + fabricIpSubnet);
        }
        out.println("");
        out.println("fabricRoutes:");
        for (FabricRoute route : fabricRoutes()) {
            out.println("    " + route);
        }
    }
}
Also used : FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) FabricRoute(org.onosproject.simplefabric.api.FabricRoute)

Example 3 with FabricSubnet

use of org.onosproject.simplefabric.api.FabricSubnet in project onos by opennetworkinglab.

the class SimpleFabricRouting method refreshIntercepts.

/**
 * Refresh device flow rules for intercepts on local fabricSubnets.
 */
private void refreshIntercepts() {
    Set<FlowRule> newInterceptFlowRules = new HashSet<>();
    for (Device device : deviceService.getAvailableDevices()) {
        for (FabricSubnet subnet : simpleFabric.defaultFabricSubnets()) {
            newInterceptFlowRules.add(generateInterceptFlowRule(true, device.id(), subnet.prefix()));
            // check if this devices has the fabricSubnet, then add ip broadcast flue rule
            FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(subnet.networkName());
            if (fabricNetwork != null && fabricNetwork.contains(device.id())) {
                newInterceptFlowRules.add(generateLocalSubnetIpBctFlowRule(device.id(), subnet.prefix(), fabricNetwork));
            }
        // JUST FOR FLOW RULE TEST ONLY
        // newInterceptFlowRules.add(generateTestFlowRule(device.id(), subnet.ipPrefix()));
        }
        for (FabricRoute route : simpleFabric.fabricRoutes()) {
            newInterceptFlowRules.add(generateInterceptFlowRule(false, device.id(), route.prefix()));
        }
    }
    if (!newInterceptFlowRules.equals(interceptFlowRules)) {
        // NOTE: DO NOT REMOVE INTERCEPT FLOW RULES FOR FAILED DEVICE FLOW UPDATE MIGHT BE BLOCKED
        /*
            interceptFlowRules.stream()
                .filter(rule -> !newInterceptFlowRules.contains(rule))
                .forEach(rule -> {
                    flowRuleService.removeFlowRules(rule);
                    log.info("simple fabric reactive routing remove intercept flow rule: {}", rule);
                });
            */
        newInterceptFlowRules.stream().filter(rule -> !interceptFlowRules.contains(rule)).forEach(rule -> {
            flowRuleService.applyFlowRules(rule);
            log.info("simple fabric routing apply intercept flow rule: {}", rule);
        });
        interceptFlowRules = newInterceptFlowRules;
    }
}
Also used : HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) REACTIVE_MATCH_IP_PROTO(org.onosproject.simplefabric.api.Constants.REACTIVE_MATCH_IP_PROTO) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) Interface(org.onosproject.net.intf.Interface) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ALLOW_ETH_ADDRESS_SELECTOR(org.onosproject.simplefabric.api.Constants.ALLOW_ETH_ADDRESS_SELECTOR) ROUTING_APP_ID(org.onosproject.simplefabric.api.Constants.ROUTING_APP_ID) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) FlowRuleService(org.onosproject.net.flow.FlowRuleService) SimpleFabricEvent(org.onosproject.simplefabric.api.SimpleFabricEvent) ApplicationId(org.onosproject.core.ApplicationId) Ip4Prefix(org.onlab.packet.Ip4Prefix) PRI_REACTIVE_BORDER_STEP(org.onosproject.simplefabric.api.Constants.PRI_REACTIVE_BORDER_STEP) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) ALLOW_IPV6(org.onosproject.simplefabric.api.Constants.ALLOW_IPV6) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) ICMP(org.onlab.packet.ICMP) PacketService(org.onosproject.net.packet.PacketService) Constraint(org.onosproject.net.intent.Constraint) EthType(org.onlab.packet.EthType) Key(org.onosproject.net.intent.Key) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) EncapsulationType(org.onosproject.net.EncapsulationType) REACTIVE_SINGLE_TO_SINGLE(org.onosproject.simplefabric.api.Constants.REACTIVE_SINGLE_TO_SINGLE) FlowRule(org.onosproject.net.flow.FlowRule) PacketContext(org.onosproject.net.packet.PacketContext) LinkService(org.onosproject.net.link.LinkService) PRI_REACTIVE_BORDER_INTERCEPT(org.onosproject.simplefabric.api.Constants.PRI_REACTIVE_BORDER_INTERCEPT) DeviceId(org.onosproject.net.DeviceId) PRI_REACTIVE_LOCAL_FORWARD(org.onosproject.simplefabric.api.Constants.PRI_REACTIVE_LOCAL_FORWARD) IpPrefix(org.onlab.packet.IpPrefix) REACTIVE_HASHED_PATH_SELECTION(org.onosproject.simplefabric.api.Constants.REACTIVE_HASHED_PATH_SELECTION) ICMP6(org.onlab.packet.ICMP6) Host(org.onosproject.net.Host) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) SimpleFabricListener(org.onosproject.simplefabric.api.SimpleFabricListener) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) IntentService(org.onosproject.net.intent.IntentService) OutboundPacket(org.onosproject.net.packet.OutboundPacket) Intent(org.onosproject.net.intent.Intent) PartialFailureConstraint(org.onosproject.net.intent.constraint.PartialFailureConstraint) Activate(org.osgi.service.component.annotations.Activate) FabricRoute(org.onosproject.simplefabric.api.FabricRoute) PRI_REACTIVE_BORDER_FORWARD(org.onosproject.simplefabric.api.Constants.PRI_REACTIVE_BORDER_FORWARD) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) SimpleFabricService(org.onosproject.simplefabric.api.SimpleFabricService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PrintStream(java.io.PrintStream) PRI_REACTIVE_BORDER_BASE(org.onosproject.simplefabric.api.Constants.PRI_REACTIVE_BORDER_BASE) Logger(org.slf4j.Logger) PRI_REACTIVE_LOCAL_INTERCEPT(org.onosproject.simplefabric.api.Constants.PRI_REACTIVE_LOCAL_INTERCEPT) VlanId(org.onlab.packet.VlanId) FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) Ip6Prefix(org.onlab.packet.Ip6Prefix) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) REACTIVE_ALLOW_LINK_CP(org.onosproject.simplefabric.api.Constants.REACTIVE_ALLOW_LINK_CP) MacAddress(org.onlab.packet.MacAddress) PacketPriority(org.onosproject.net.packet.PacketPriority) Reference(org.osgi.service.component.annotations.Reference) Comparator(java.util.Comparator) Collections(java.util.Collections) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) Device(org.onosproject.net.Device) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) HashSet(java.util.HashSet) FabricRoute(org.onosproject.simplefabric.api.FabricRoute)

Example 4 with FabricSubnet

use of org.onosproject.simplefabric.api.FabricSubnet 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 5 with FabricSubnet

use of org.onosproject.simplefabric.api.FabricSubnet in project onos by opennetworkinglab.

the class SimpleFabricManager method requestMac.

@Override
public boolean requestMac(IpAddress ip) {
    FabricSubnet fabricSubnet = fabricSubnet(ip);
    if (fabricSubnet == null) {
        log.warn("simple fabric request mac failed for unknown fabricSubnet: {}", ip);
        return false;
    }
    FabricNetwork fabricNetwork = fabricNetwork(fabricSubnet.networkName());
    if (fabricNetwork == null) {
        log.warn("simple fabric request mac failed for unknown fabricNetwork name {}: {}", fabricSubnet.networkName(), ip);
        return false;
    }
    log.debug("simple fabric send request mac fabricNetwork {}: {}", fabricNetwork.name(), ip);
    for (Interface iface : fabricNetwork.interfaces()) {
        Ethernet neighbourReq;
        if (ip.isIp4()) {
            neighbourReq = ARP.buildArpRequest(fabricSubnet.gatewayMac().toBytes(), fabricSubnet.gatewayIp().toOctets(), ip.toOctets(), iface.vlan().toShort());
        } else {
            byte[] soliciteIp = IPv6.getSolicitNodeAddress(ip.toOctets());
            neighbourReq = NeighborSolicitation.buildNdpSolicit(ip.getIp6Address(), fabricSubnet.gatewayIp().getIp6Address(), Ip6Address.valueOf(soliciteIp), MacAddress.valueOf(fabricSubnet.gatewayMac().toBytes()), MacAddress.valueOf(IPv6.getMCastMacAddress(soliciteIp)), iface.vlan());
        }
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(iface.connectPoint().port()).build();
        OutboundPacket packet = new DefaultOutboundPacket(iface.connectPoint().deviceId(), treatment, ByteBuffer.wrap(neighbourReq.serialize()));
        packetService.emit(packet);
    }
    return true;
}
Also used : FabricSubnet(org.onosproject.simplefabric.api.FabricSubnet) Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork) Interface(org.onosproject.net.intf.Interface) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Aggregations

FabricSubnet (org.onosproject.simplefabric.api.FabricSubnet)7 FabricNetwork (org.onosproject.simplefabric.api.FabricNetwork)5 FabricRoute (org.onosproject.simplefabric.api.FabricRoute)4 IpAddress (org.onlab.packet.IpAddress)3 MacAddress (org.onlab.packet.MacAddress)3 HashSet (java.util.HashSet)2 Ethernet (org.onlab.packet.Ethernet)2 IpPrefix (org.onlab.packet.IpPrefix)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 EncapsulationType (org.onosproject.net.EncapsulationType)2 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)2 Host (org.onosproject.net.Host)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 Interface (org.onosproject.net.intf.Interface)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 DefaultByteArrayNodeFactory (com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory)1 ConcurrentInvertedRadixTree (com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree)1 PrintStream (java.io.PrintStream)1 ByteBuffer (java.nio.ByteBuffer)1