Search in sources :

Example 1 with SimpleFabricEvent

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

the class SimpleFabricManager method dumpToStream.

@Override
public void dumpToStream(String subject, OutputStream out) {
    SimpleFabricEvent event = new SimpleFabricEvent(SimpleFabricEvent.Type.SIMPLE_FABRIC_DUMP, subject, out);
    // dump in itself
    dump(event.subject(), event.out());
    // dump in sub modules
    process(event);
}
Also used : SimpleFabricEvent(org.onosproject.simplefabric.api.SimpleFabricEvent)

Example 2 with SimpleFabricEvent

use of org.onosproject.simplefabric.api.SimpleFabricEvent 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)

Aggregations

SimpleFabricEvent (org.onosproject.simplefabric.api.SimpleFabricEvent)2 DefaultByteArrayNodeFactory (com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory)1 ConcurrentInvertedRadixTree (com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree)1 HashSet (java.util.HashSet)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 Host (org.onosproject.net.Host)1 Interface (org.onosproject.net.intf.Interface)1 RouteTools.createBinaryString (org.onosproject.routeservice.RouteTools.createBinaryString)1 FabricNetwork (org.onosproject.simplefabric.api.FabricNetwork)1 FabricRoute (org.onosproject.simplefabric.api.FabricRoute)1 FabricSubnet (org.onosproject.simplefabric.api.FabricSubnet)1