Search in sources :

Example 6 with Type

use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.

the class OpenstackRoutingHandler method setGatewayRules.

private void setGatewayRules(Subnet osSubnet, Router osRouter, boolean install) {
    OpenstackNode srcNatGw = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
    if (srcNatGw == null) {
        return;
    }
    if (Strings.isNullOrEmpty(osSubnet.getGateway())) {
        // do nothing if no gateway is set
        return;
    }
    Network net = osNetworkAdminService.network(osSubnet.getNetworkId());
    Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
    Set<Subnet> routableSubnets = routableSubnets(osRouter, osSubnet.getId());
    // install rules to each compute node for routing IP packets to gateways
    osNodeService.completeNodes(COMPUTE).stream().filter(cNode -> cNode.dataIp() != null).forEach(cNode -> setRulesToGatewayWithRoutableSubnets(cNode, srcNatGw, net.getProviderSegID(), osSubnet, routableSubnets, netType, install));
    // install rules to punt ICMP packets to controller at gateway node
    // this rule is only valid for stateless ICMP SNAT case
    osNodeService.completeNodes(GATEWAY).forEach(gNode -> setReactiveGatewayIcmpRule(IpAddress.valueOf(osSubnet.getGateway()), gNode.intgBridge(), install));
    final String updateStr = install ? MSG_ENABLED : MSG_DISABLED;
    log.debug(updateStr + "IP to {}", osSubnet.getGateway());
}
Also used : OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Constants(org.onosproject.openstacknetworking.api.Constants) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) STAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE) Ethernet(org.onlab.packet.Ethernet) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) PRIORITY_INTERNAL_ROUTING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_INTERNAL_ROUTING_RULE) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) NodeId(org.onosproject.cluster.NodeId) PRIORITY_ICMP_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ICMP_RULE) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) PRIORITY_ADMIN_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ADMIN_RULE) ICMP(org.onlab.packet.ICMP) USE_STATEFUL_SNAT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT) Collectors(java.util.stream.Collectors) OpenstackNetworkingUtil.getPropertyValueAsBoolean(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean) Objects(java.util.Objects) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) ROUTING_TABLE(org.onosproject.openstacknetworking.api.Constants.ROUTING_TABLE) IpPrefix(org.onlab.packet.IpPrefix) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) RouterInterface(org.openstack4j.model.network.RouterInterface) OpenstackRouterEvent(org.onosproject.openstacknetworking.api.OpenstackRouterEvent) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Router(org.openstack4j.model.network.Router) Activate(org.osgi.service.component.annotations.Activate) 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) PRIORITY_ICMP_REQUEST_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ICMP_REQUEST_RULE) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Subnet(org.openstack4j.model.network.Subnet) PRIORITY_SWITCHING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) IPv4(org.onlab.packet.IPv4) OpenstackRouterListener(org.onosproject.openstacknetworking.api.OpenstackRouterListener) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) ConfigProperty(org.onosproject.cfg.ConfigProperty) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) Network(org.openstack4j.model.network.Network) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Subnet(org.openstack4j.model.network.Subnet)

Example 7 with Type

use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.

the class OpenstackRoutingHandler method setRouterAdminRules.

private void setRouterAdminRules(String segmentId, Type networkType, boolean install) {
    TrafficTreatment treatment;
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
    switch(networkType) {
        case VXLAN:
        case GRE:
        case GENEVE:
            sBuilder.matchTunnelId(Long.parseLong(segmentId));
            break;
        case VLAN:
            sBuilder.matchVlanId(VlanId.vlanId(segmentId));
            break;
        default:
            final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, networkType.toString());
            throw new IllegalStateException(error);
    }
    treatment = DefaultTrafficTreatment.builder().drop().build();
    osNodeService.completeNodes().stream().filter(osNode -> osNode.type() == COMPUTE).forEach(osNode -> {
        osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), treatment, PRIORITY_ADMIN_RULE, ROUTING_TABLE, install);
    });
}
Also used : OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Constants(org.onosproject.openstacknetworking.api.Constants) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) STAT_OUTBOUND_TABLE(org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE) Ethernet(org.onlab.packet.Ethernet) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) PRIORITY_INTERNAL_ROUTING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_INTERNAL_ROUTING_RULE) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) NodeId(org.onosproject.cluster.NodeId) PRIORITY_ICMP_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ICMP_RULE) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) PRIORITY_ADMIN_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ADMIN_RULE) ICMP(org.onlab.packet.ICMP) USE_STATEFUL_SNAT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT) Collectors(java.util.stream.Collectors) OpenstackNetworkingUtil.getPropertyValueAsBoolean(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean) Objects(java.util.Objects) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) ROUTING_TABLE(org.onosproject.openstacknetworking.api.Constants.ROUTING_TABLE) IpPrefix(org.onlab.packet.IpPrefix) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) RouterInterface(org.openstack4j.model.network.RouterInterface) OpenstackRouterEvent(org.onosproject.openstacknetworking.api.OpenstackRouterEvent) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Router(org.openstack4j.model.network.Router) Activate(org.osgi.service.component.annotations.Activate) 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) PRIORITY_ICMP_REQUEST_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ICMP_REQUEST_RULE) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Subnet(org.openstack4j.model.network.Subnet) PRIORITY_SWITCHING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) IPv4(org.onlab.packet.IPv4) OpenstackRouterListener(org.onosproject.openstacknetworking.api.OpenstackRouterListener) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) ConfigProperty(org.onosproject.cfg.ConfigProperty) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 8 with Type

use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.

the class OpenstackRoutingHandler method routerIfaceRemoved.

private void routerIfaceRemoved(Router osRouter, RouterInterface osRouterIface) {
    Subnet osSubnet = osNetworkAdminService.subnet(osRouterIface.getSubnetId());
    if (osSubnet == null) {
        final String error = String.format("Failed to set flows for router %s: subnet %s does not exist", osRouterIface.getId(), osRouterIface.getSubnetId());
        throw new IllegalStateException(error);
    }
    if (!osRouter.isAdminStateUp()) {
        Network network = osNetworkAdminService.network(osSubnet.getNetworkId());
        Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
        setRouterAdminRules(network.getProviderSegID(), netType, false);
    }
    setInternalRoutes(osRouter, osSubnet, false);
    setGatewayRules(osSubnet, osRouter, false);
    log.info("Disconnected subnet({}) from {}", osSubnet.getCidr(), deriveResourceName(osRouter));
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) Network(org.openstack4j.model.network.Network) Subnet(org.openstack4j.model.network.Subnet)

Example 9 with Type

use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.

the class OpenstackRoutingSnatHandler method populateSnatFlowRules.

private void populateSnatFlowRules(InboundPacket packetIn, InstancePort srcInstPort, TpPort patPort, IpAddress externalIp, ExternalPeerRouter externalPeerRouter) {
    Network osNet = osNetworkService.network(srcInstPort.networkId());
    Type netType = osNetworkService.networkType(srcInstPort.networkId());
    if (osNet == null) {
        final String error = String.format("%s network %s not found", ERR_PACKET_IN, srcInstPort.networkId());
        throw new IllegalStateException(error);
    }
    setStatelessSnatDownstreamRules(srcInstPort, osNet.getProviderSegID(), netType, externalIp, externalPeerRouter, patPort, packetIn);
    setStatelessSnatUpstreamRules(osNet.getProviderSegID(), netType, externalIp, externalPeerRouter, patPort, packetIn);
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) Network(org.openstack4j.model.network.Network)

Example 10 with Type

use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.

the class OpenstackRoutingSnatHandler method setGatewayToInstanceDownstreamRule.

private void setGatewayToInstanceDownstreamRule(OpenstackNode gwNode, InstancePort instPort, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(instPort.ipAddress(), VM_PREFIX)).build();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setEthDst(instPort.macAddress());
    Type netType = osNetworkAdminService.networkType(instPort.networkId());
    String segId = osNetworkAdminService.segmentId(instPort.networkId());
    switch(netType) {
        case VXLAN:
        case GRE:
        case GENEVE:
            tBuilder.setTunnelId(Long.valueOf(segId));
            break;
        case VLAN:
        default:
            final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, netType.name());
            throw new IllegalStateException(error);
    }
    OpenstackNode srcNode = osNodeService.node(instPort.deviceId());
    TrafficTreatment treatment = getDownstreamTreatment(netType, tBuilder, gwNode, srcNode);
    osFlowRuleService.setRule(appId, gwNode.intgBridge(), selector, treatment, PRIORITY_STATEFUL_SNAT_RULE, GW_COMMON_TABLE, install);
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

Type (org.onosproject.openstacknetworking.api.OpenstackNetwork.Type)22 Network (org.openstack4j.model.network.Network)13 OpenstackNetworkingUtil.tunnelPortNumByNetType (org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType)12 Subnet (org.openstack4j.model.network.Subnet)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)9 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)9 IpAddress (org.onlab.packet.IpAddress)8 PortNumber (org.onosproject.net.PortNumber)7 Set (java.util.Set)6 ExecutorService (java.util.concurrent.ExecutorService)6 Collectors (java.util.stream.Collectors)6 VlanId (org.onlab.packet.VlanId)6 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)6 CoreService (org.onosproject.core.CoreService)6 DeviceService (org.onosproject.net.device.DeviceService)6 OPENSTACK_NETWORKING_APP_ID (org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID)6 Objects (java.util.Objects)5