Search in sources :

Example 16 with Type

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

the class OpenstackRoutingHandler method routerIfaceAdded.

private void routerIfaceAdded(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, true);
    }
    setInternalRoutes(osRouter, osSubnet, true);
    setGatewayRules(osSubnet, osRouter, true);
    log.info("Connected subnet({}) to {}", 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 17 with Type

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

the class OpenstackRoutingHandler method routerRemove.

private void routerRemove(Router osRouter) {
    osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> {
        Network network = osNetworkAdminService.network(osNetworkAdminService.subnet(iface.getSubnetId()).getNetworkId());
        Type netType = osNetworkAdminService.networkType(osNetworkAdminService.subnet(iface.getSubnetId()).getNetworkId());
        setRouterAdminRules(network.getProviderSegID(), netType, false);
    });
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) Network(org.openstack4j.model.network.Network)

Example 18 with Type

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

the class OpenstackRoutingFloatingIpHandler method setDownstreamExternalRulesHelper.

private void setDownstreamExternalRulesHelper(NetFloatingIP floatingIp, Network osNet, InstancePort instPort, ExternalPeerRouter externalPeerRouter, Set<OpenstackNode> gateways, boolean install) {
    OpenstackNode cNode = osNodeService.node(instPort.deviceId());
    Type netType = osNetworkService.networkType(osNet.getId());
    if (cNode == null) {
        final String error = String.format("Cannot find openstack node for device %s", instPort.deviceId());
        throw new IllegalStateException(error);
    }
    if (netType == VXLAN && cNode.dataIp() == null) {
        final String errorFormat = ERR_FLOW + "VXLAN mode is not ready for %s";
        final String error = String.format(errorFormat, floatingIp, cNode.hostname());
        throw new IllegalStateException(error);
    }
    if (netType == GRE && cNode.dataIp() == null) {
        final String errorFormat = ERR_FLOW + "GRE mode is not ready for %s";
        final String error = String.format(errorFormat, floatingIp, cNode.hostname());
        throw new IllegalStateException(error);
    }
    if (netType == GENEVE && cNode.dataIp() == null) {
        final String errorFormat = ERR_FLOW + "GENEVE mode is not ready for %s";
        final String error = String.format(errorFormat, floatingIp, cNode.hostname());
        throw new IllegalStateException(error);
    }
    if (netType == VLAN && cNode.vlanIntf() == null) {
        final String errorFormat = ERR_FLOW + "VLAN mode is not ready for %s";
        final String error = String.format(errorFormat, floatingIp, cNode.hostname());
        throw new IllegalStateException(error);
    }
    IpAddress floating = IpAddress.valueOf(floatingIp.getFloatingIpAddress());
    OpenstackNode selectedGatewayNode = getGwByComputeDevId(gateways, instPort.deviceId());
    if (selectedGatewayNode == null) {
        final String errorFormat = ERR_FLOW + "no gateway node selected";
        throw new IllegalStateException(errorFormat);
    }
    TrafficSelector.Builder externalSelectorBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(selectedGatewayNode.uplinkPortNum()).matchIPDst(floating.toIpPrefix());
    TrafficTreatment.Builder externalTreatmentBuilder = DefaultTrafficTreatment.builder().setEthSrc(Constants.DEFAULT_GATEWAY_MAC).setEthDst(instPort.macAddress()).setIpDst(instPort.ipAddress().getIp4Address());
    if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
        externalSelectorBuilder.matchVlanId(externalPeerRouter.vlanId()).build();
        externalTreatmentBuilder.popVlan();
    }
    switch(netType) {
        case VXLAN:
        case GRE:
        case GENEVE:
            PortNumber portNum = tunnelPortNumByNetId(instPort.networkId(), osNetworkService, selectedGatewayNode);
            externalTreatmentBuilder.setTunnelId(Long.valueOf(osNet.getProviderSegID())).extension(buildExtension(deviceService, selectedGatewayNode.intgBridge(), cNode.dataIp().getIp4Address()), selectedGatewayNode.intgBridge()).setOutput(portNum);
            break;
        case VLAN:
            externalTreatmentBuilder.pushVlan().setVlanId(VlanId.vlanId(osNet.getProviderSegID())).setOutput(selectedGatewayNode.vlanPortNum());
            break;
        default:
            final String error = String.format(ERR_UNSUPPORTED_NET_TYPE, osNet.getNetworkType());
            throw new IllegalStateException(error);
    }
    osFlowRuleService.setRule(appId, selectedGatewayNode.intgBridge(), externalSelectorBuilder.build(), externalTreatmentBuilder.build(), PRIORITY_FLOATING_EXTERNAL, GW_COMMON_TABLE, install);
    setArpRule(floatingIp, instPort.macAddress(), selectedGatewayNode, install);
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

Example 19 with Type

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

the class OpenstackRoutingFloatingIpHandler method setUpstreamRules.

private void setUpstreamRules(NetFloatingIP floatingIp, Network osNet, InstancePort instPort, ExternalPeerRouter externalPeerRouter, boolean install) {
    IpAddress floating = IpAddress.valueOf(floatingIp.getFloatingIpAddress());
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(instPort.ipAddress().toIpPrefix());
    Type netType = osNetworkService.networkType(osNet.getId());
    switch(netType) {
        case VXLAN:
        case GRE:
        case GENEVE:
            sBuilder.matchTunnelId(Long.valueOf(osNet.getProviderSegID()));
            break;
        case VLAN:
            sBuilder.matchVlanId(VlanId.vlanId(osNet.getProviderSegID()));
            break;
        default:
            final String error = String.format(ERR_UNSUPPORTED_NET_TYPE, osNet.getNetworkType());
            throw new IllegalStateException(error);
    }
    TrafficSelector selector = sBuilder.build();
    osNodeService.completeNodes(GATEWAY).forEach(gNode -> {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpSrc(floating.getIp4Address()).setEthSrc(instPort.macAddress()).setEthDst(externalPeerRouter.macAddress());
        if (netType == VLAN) {
            tBuilder.popVlan();
        }
        if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
            tBuilder.pushVlan().setVlanId(externalPeerRouter.vlanId());
        }
        osFlowRuleService.setRule(appId, gNode.intgBridge(), selector, tBuilder.setOutput(gNode.uplinkPortNum()).build(), PRIORITY_FLOATING_EXTERNAL, GW_COMMON_TABLE, install);
    });
    log.trace("Succeeded to set flow rules for upstream on gateway nodes");
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 20 with Type

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

the class OpenstackRoutingSnatHandler method setReactiveSnatRules.

private void setReactiveSnatRules(RouterInterface routerIface, boolean install) {
    Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
    Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
    Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
    osNodeService.completeNodes(GATEWAY).forEach(gwNode -> setRulesToController(gwNode.intgBridge(), osNet.getProviderSegID(), IpPrefix.valueOf(osSubnet.getCidr()), netType, install));
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) Network(org.openstack4j.model.network.Network) OpenstackNetworkingUtil.externalPeerRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterFromSubnet) Subnet(org.openstack4j.model.network.Subnet) OpenstackNetworkingUtil.getRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getRouterFromSubnet)

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