Search in sources :

Example 26 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackConfigStatefulSnatCommand method syncRules.

private void syncRules() {
    // All handlers in this application reacts the node complete event and
    // tries to re-configure flow rules for the complete node.
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    OpenstackNodeAdminService osNodeAdminService = get(OpenstackNodeAdminService.class);
    if (osNodeService == null) {
        error("Failed to re-install flow rules for OpenStack networking.");
        return;
    }
    osNodeService.completeNodes().forEach(osNode -> {
        OpenstackNode updated = osNode.updateState(NodeState.INIT);
        osNodeAdminService.updateNode(updated);
    });
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 27 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackDiffStateCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackSecurityGroupAdminService osSgService = get(OpenstackSecurityGroupAdminService.class);
    OpenstackNetworkAdminService osNetService = get(OpenstackNetworkAdminService.class);
    OpenstackRouterAdminService osRouterService = get(OpenstackRouterAdminService.class);
    OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
    Map<String, String> headerMap = new HashMap<>();
    headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
    Optional<OpenstackNode> node = osNodeService.nodes(CONTROLLER).stream().findFirst();
    if (!node.isPresent()) {
        error("Keystone auth info has not been configured. " + "Please specify auth info via network-cfg.json.");
        return;
    }
    OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
    if (osClient == null) {
        return;
    }
    if (!clear) {
        show = true;
    }
    if (show && clear) {
        error("Either --show (-s) or --clear (-c) option should be specified.");
    }
    if (show) {
        print("\nComparing OpenStack floating IPs");
    } else if (clear) {
        print("\nClearing OpenStack floating IPs");
    }
    Set<String> cachedFips = osRouterService.floatingIps().stream().map(NetFloatingIP::getId).collect(Collectors.toSet());
    Set<String> osFips = osClient.headers(headerMap).networking().floatingip().list().stream().map(NetFloatingIP::getId).collect(Collectors.toSet());
    print(FLOATING_IP_FORMAT, "ID", "Floating IP", "Fixed IP");
    getDiff(cachedFips, osFips).forEach(fipId -> {
        printFloatingIp(osRouterService.floatingIp(fipId));
        if (clear) {
            osRouterService.removeFloatingIp(fipId);
        }
    });
    Set<String> cachedPorts = osNetService.ports().stream().map(IdEntity::getId).collect(Collectors.toSet());
    Set<String> osPorts = osClient.headers(headerMap).networking().port().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
    if (show) {
        print("\nComparing OpenStack router interfaces");
    } else if (clear) {
        print("\nClearing OpenStack router interfaces");
    }
    print(ROUTER_INTF_FORMAT, "ID", "Tenant ID", "Subnet ID");
    getDiff(cachedPorts, osPorts).forEach(portId -> {
        RouterInterface ri = osRouterService.routerInterface(portId);
        if (ri != null) {
            printRouterIntf(ri);
            if (clear) {
                osRouterService.removeRouterInterface(portId);
            }
        }
    });
    if (show) {
        print("\nComparing OpenStack ports");
    } else if (clear) {
        print("\nClearing OpenStack ports");
    }
    print(PORT_FORMAT, "ID", "Network", "MAC", "Fixed IPs");
    getDiff(cachedPorts, osPorts).forEach(portId -> {
        printPort(osNetService.port(portId), osNetService);
        if (clear) {
            osNetService.removePort(portId);
        }
    });
    if (show) {
        print("\nComparing OpenStack routers");
    } else if (clear) {
        print("\nClearing OpenStack routers");
    }
    Set<String> cachedRouters = osRouterService.routers().stream().map(IdEntity::getId).collect(Collectors.toSet());
    Set<String> osRouters = osClient.headers(headerMap).networking().router().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
    print(ROUTER_FORMAT, "ID", "Name", "External", "Internal");
    getDiff(cachedRouters, osRouters).forEach(routerId -> {
        printRouter(osRouterService.router(routerId), osNetService);
        if (clear) {
            osRouterService.removeRouter(routerId);
        }
    });
    if (show) {
        print("\nComparing OpenStack subnets");
    } else if (clear) {
        print("\nClearing OpenStack subnets");
    }
    Set<String> cachedSubnets = osNetService.subnets().stream().map(IdEntity::getId).collect(Collectors.toSet());
    Set<String> osSubnets = osClient.headers(headerMap).networking().subnet().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
    print(SUBNET_FORMAT, "ID", "Network", "CIDR");
    getDiff(cachedSubnets, osSubnets).forEach(subnetId -> {
        printSubnet(osNetService.subnet(subnetId), osNetService);
        if (clear) {
            osNetService.removeSubnet(subnetId);
        }
    });
    if (show) {
        print("\nComparing OpenStack networks");
    } else if (clear) {
        print("\nClearing OpenStack networks");
    }
    Set<String> cachedNets = osNetService.networks().stream().map(IdEntity::getId).collect(Collectors.toSet());
    Set<String> osNets = osClient.headers(headerMap).networking().network().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
    print(NETWORK_FORMAT, "ID", "Name", "VNI", "Subnets");
    getDiff(cachedNets, osNets).forEach(netId -> {
        printNetwork(osNetService.network(netId));
        if (clear) {
            osNetService.removeNetwork(netId);
        }
    });
    if (show) {
        print("\nComparing OpenStack security groups");
    } else if (clear) {
        print("\nClearing OpenStack security groups");
    }
    Set<String> cachedSgs = osSgService.securityGroups().stream().map(IdEntity::getId).collect(Collectors.toSet());
    Set<String> osSgs = osClient.headers(headerMap).networking().securitygroup().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
    print(SECURITY_GROUP_FORMAT, "ID", "Name");
    getDiff(cachedSgs, osSgs).forEach(sgId -> {
        printSecurityGroup(osSgService.securityGroup(sgId));
        if (clear) {
            osSgService.removeSecurityGroup(sgId);
        }
    });
}
Also used : OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) HashMap(java.util.HashMap) OpenstackRouterAdminService(org.onosproject.openstacknetworking.api.OpenstackRouterAdminService) OSClient(org.openstack4j.api.OSClient) RouterInterface(org.openstack4j.model.network.RouterInterface) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) OpenstackSecurityGroupAdminService(org.onosproject.openstacknetworking.api.OpenstackSecurityGroupAdminService) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)

Example 28 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackNetworkingUtil method getGwByIndex.

/**
 * Obtains gateway instance by giving index number.
 *
 * @param gws       a collection of gateway nodes
 * @param index     index number
 * @return gateway instance
 */
private static OpenstackNode getGwByIndex(Set<OpenstackNode> gws, int index) {
    Map<String, OpenstackNode> hashMap = new HashMap<>();
    gws.forEach(gw -> hashMap.put(gw.hostname(), gw));
    TreeMap<String, OpenstackNode> treeMap = new TreeMap<>(hashMap);
    Iterator<String> iteratorKey = treeMap.keySet().iterator();
    int intIndex = 0;
    OpenstackNode gw = null;
    while (iteratorKey.hasNext()) {
        String key = iteratorKey.next();
        if (intIndex == index) {
            gw = treeMap.get(key);
        }
        intIndex++;
    }
    return gw;
}
Also used : HashMap(java.util.HashMap) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) TreeMap(java.util.TreeMap)

Example 29 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackSwitchingArpHandler method setArpReplyRuleForGre.

/**
 * Installs flow rules to match ARP reply packets only for GRE.
 *
 * @param port      instance port
 * @param install   installation flag
 */
private void setArpReplyRuleForGre(InstancePort port, boolean install) {
    OpenstackNode localNode = osNodeService.node(port.deviceId());
    TrafficSelector selector = getArpReplySelectorForGre(port);
    setLocalArpReplyTreatmentForGre(selector, port, install);
    setRemoteArpTreatmentForTunnel(selector, port, localNode, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 30 with OpenstackNode

use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.

the class OpenstackSwitchingArpHandler method setFakeGatewayArpRule.

/**
 * Installs flow rules which convert ARP request packet into ARP reply
 * by adding a fake gateway MAC address as Source Hardware Address.
 *
 * @param osSubnet  openstack subnet
 * @param network   openstack network
 * @param install   flag which indicates whether to install rule or remove rule
 * @param osNode    openstack node
 */
private void setFakeGatewayArpRule(Subnet osSubnet, Network network, boolean install, OpenstackNode osNode) {
    if (ARP_BROADCAST_MODE.equals(getArpMode())) {
        Type netType = osNetworkService.networkType(network.getId());
        String gateway = osSubnet.getGateway();
        if (gateway == null) {
            return;
        }
        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
        if (netType == VLAN) {
            sBuilder.matchVlanId(VlanId.vlanId(network.getProviderSegID()));
        } else if (netType == VXLAN || netType == GRE || netType == GENEVE) {
            // different networks
            if (!install) {
                long numOfDupGws = osNetworkService.subnets().stream().filter(s -> !s.getId().equals(osSubnet.getId())).filter(s -> s.getGateway() != null).filter(s -> s.getGateway().equals(osSubnet.getGateway())).count();
                if (numOfDupGws > 0) {
                    return;
                }
            }
        }
        sBuilder.matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(gateway));
        if (osNode == null) {
            osNodeService.completeNodes(COMPUTE).forEach(n -> {
                Device device = deviceService.getDevice(n.intgBridge());
                TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
                if (netType == VLAN) {
                    tBuilder.popVlan();
                }
                tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setEthSrc(MacAddress.valueOf(gatewayMac)).setOutput(PortNumber.IN_PORT);
                osFlowRuleService.setRule(appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
            });
        } else {
            Device device = deviceService.getDevice(osNode.intgBridge());
            TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
            if (netType == VLAN) {
                tBuilder.popVlan();
            }
            tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setOutput(PortNumber.IN_PORT);
            osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
        }
    }
}
Also used : OpenstackGroupRuleService(org.onosproject.openstacknetworking.api.OpenstackGroupRuleService) CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ARP(org.onlab.packet.ARP) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) PRIORITY_ARP_REQUEST_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REQUEST_RULE) InstancePortEvent(org.onosproject.openstacknetworking.api.InstancePortEvent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) PRIORITY_ARP_REPLY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REPLY_RULE) Ethernet(org.onlab.packet.Ethernet) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) VLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) RulePopulatorUtil.buildMoveEthSrcToDstExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveEthSrcToDstExtension) RulePopulatorUtil.buildMoveArpShaToThaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpShaToThaExtension) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) ALL(org.onosproject.net.group.GroupDescription.Type.ALL) GRE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Ip4Address(org.onlab.packet.Ip4Address) Device(org.onosproject.net.Device) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) ARP_PROXY_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_PROXY_MODE) Deactivate(org.osgi.service.component.annotations.Deactivate) PRIORITY_ARP_GROUP_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GROUP_RULE) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) InstancePortListener(org.onosproject.openstacknetworking.api.InstancePortListener) NetworkType(org.openstack4j.model.network.NetworkType) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) PacketContext(org.onosproject.net.packet.PacketContext) OpenstackNetworkingUtil.swapStaleLocation(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.swapStaleLocation) ClusterService(org.onosproject.cluster.ClusterService) ARP_MODE_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE_DEFAULT) OpenstackNetworkingUtil.tunnelPortNumByNetId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetId) Dictionary(java.util.Dictionary) IdEntity(org.openstack4j.model.common.IdEntity) Tools(org.onlab.util.Tools) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) GATEWAY_MAC_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC_DEFAULT) ComponentContext(org.osgi.service.component.ComponentContext) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) GroupBucket(org.onosproject.net.group.GroupBucket) RulePopulatorUtil.buildMoveArpSpaToTpaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpSpaToTpaExtension) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) GATEWAY_MAC(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC) ARP_TABLE(org.onosproject.openstacknetworking.api.Constants.ARP_TABLE) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ARP_MODE(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) GENEVE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GENEVE) Subnet(org.openstack4j.model.network.Subnet) PRIORITY_ARP_GATEWAY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GATEWAY_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) GroupId(org.onosproject.core.GroupId) ConfigProperty(org.onosproject.cfg.ConfigProperty) Modified(org.osgi.service.component.annotations.Modified) MacAddress(org.onlab.packet.MacAddress) VXLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN) Reference(org.osgi.service.component.annotations.Reference) PRIORITY_ARP_CONTROL_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_CONTROL_RULE) LeadershipService(org.onosproject.cluster.LeadershipService) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) RulePopulatorUtil.buildGroupBucket(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildGroupBucket) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) NetworkType(org.openstack4j.model.network.NetworkType) EthType(org.onlab.packet.EthType) Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)76 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)22 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)19 PortNumber (org.onosproject.net.PortNumber)14 DefaultOpenstackNode (org.onosproject.openstacknode.api.DefaultOpenstackNode)14 DeviceService (org.onosproject.net.device.DeviceService)13 Set (java.util.Set)12 Test (org.junit.Test)12 IpAddress (org.onlab.packet.IpAddress)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 Objects (java.util.Objects)9 Optional (java.util.Optional)9 ExecutorService (java.util.concurrent.ExecutorService)9 Collectors (java.util.stream.Collectors)9 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)9 Produces (javax.ws.rs.Produces)8 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)7