Search in sources :

Example 1 with Type

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

the class OpenstackRoutingFloatingIpHandler method setComputeNodeToGatewayHelper.

// a helper method
private void setComputeNodeToGatewayHelper(InstancePort instPort, Network osNet, Set<OpenstackNode> gateways, boolean install) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(instPort.ipAddress().toIpPrefix()).matchEthDst(Constants.DEFAULT_GATEWAY_MAC);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    OpenstackNode selectedGatewayNode = getGwByComputeDevId(gateways, instPort.deviceId());
    if (selectedGatewayNode == null) {
        log.warn(ERR_FLOW + "no gateway node selected");
        return;
    }
    Type netType = osNetworkService.networkType(osNet.getId());
    switch(netType) {
        case VXLAN:
        case GRE:
        case GENEVE:
            PortNumber portNum = tunnelPortNumByNetId(instPort.networkId(), osNetworkService, osNodeService.node(instPort.deviceId()));
            if (portNum == null) {
                log.warn(ERR_FLOW + "no tunnel port");
                return;
            }
            sBuilder.matchTunnelId(Long.parseLong(osNet.getProviderSegID()));
            tBuilder.extension(buildExtension(deviceService, instPort.deviceId(), selectedGatewayNode.dataIp().getIp4Address()), instPort.deviceId()).setOutput(portNum);
            break;
        case VLAN:
            if (osNodeService.node(instPort.deviceId()).vlanPortNum() == null) {
                log.warn(ERR_FLOW + "no vlan port");
                return;
            }
            sBuilder.matchVlanId(VlanId.vlanId(osNet.getProviderSegID()));
            tBuilder.setOutput(osNodeService.node(instPort.deviceId()).vlanPortNum());
            break;
        default:
            log.warn(ERR_FLOW + "no supported network type");
    }
    osFlowRuleService.setRule(appId, instPort.deviceId(), sBuilder.build(), tBuilder.build(), PRIORITY_EXTERNAL_FLOATING_ROUTING_RULE, ROUTING_TABLE, install);
    log.trace("Succeeded to set flow rules from compute node to gateway on compute node");
}
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) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

Example 2 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 3 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)

Example 4 with Type

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

the class OpenstackRoutingSnatHandler method setSourceNat.

private void setSourceNat(RouterInterface routerIface, boolean install) {
    Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
    Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
    Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
    osNodeService.completeNodes(COMPUTE).forEach(cNode -> {
        setRulesToGateway(cNode, osNet.getProviderSegID(), IpPrefix.valueOf(osSubnet.getCidr()), netType, install);
    });
    if (getStatefulSnatFlag()) {
        setStatefulSnatRules(routerIface, install);
    } else {
        setReactiveSnatRules(routerIface, install);
    }
    final String updateStr = install ? MSG_ENABLED : MSG_DISABLED;
    log.info(updateStr + "external access for subnet({})", osSubnet.getCidr());
}
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)

Example 5 with Type

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

the class OpenstackSwitchingArpHandler method setArpRequestRule.

/**
 * Installs flow rules to match ARP request packets.
 *
 * @param port      instance port
 * @param install   installation flag
 */
private void setArpRequestRule(InstancePort port, boolean install) {
    Type netType = osNetworkService.networkType(port.networkId());
    switch(netType) {
        case VXLAN:
        case GRE:
        case GENEVE:
            setRemoteArpRequestRuleForTunnel(port, install);
            setLocalArpRequestRuleForVnet(port, install);
            break;
        case VLAN:
            setArpRequestRuleForVlan(port, install);
            setLocalArpRequestRuleForVnet(port, install);
            break;
        default:
            break;
    }
}
Also used : Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) NetworkType(org.openstack4j.model.network.NetworkType) EthType(org.onlab.packet.EthType)

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