Search in sources :

Example 11 with ExternalPeerRouter

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

the class ExternalPeerRouterListCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService service = get(OpenstackNetworkService.class);
    List<ExternalPeerRouter> routers = Lists.newArrayList(service.externalPeerRouters());
    if (outputJson()) {
        print("%s", json(this, routers));
    } else {
        print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
        for (ExternalPeerRouter router : routers) {
            print(FORMAT, router.ipAddress(), router.macAddress().toString(), router.vlanId());
        }
    }
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService)

Example 12 with ExternalPeerRouter

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

the class OpenstackRoutingSnatHandler method processSnatPacket.

private void processSnatPacket(PacketContext context, Ethernet eth) {
    if (getStatefulSnatFlag()) {
        return;
    }
    IPv4 iPacket = (IPv4) eth.getPayload();
    InboundPacket packetIn = context.inPacket();
    int patPort = getPortNum();
    InstancePort srcInstPort = instancePortService.instancePort(eth.getSourceMAC());
    if (srcInstPort == null) {
        log.error(ERR_PACKET_IN + "source host(MAC:{}) does not exist", eth.getSourceMAC());
        return;
    }
    IpAddress srcIp = IpAddress.valueOf(iPacket.getSourceAddress());
    Subnet srcSubnet = getSourceSubnet(srcInstPort, srcIp);
    Router osRouter = getRouterFromSubnet(srcSubnet, osRouterService);
    if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
        // this router does not have external connectivity
        log.warn("No router is associated with the given subnet {}", srcSubnet);
        return;
    }
    IpAddress externalGatewayIp = externalGatewayIpSnatEnabled(osRouter, osNetworkAdminService);
    if (externalGatewayIp == null) {
        return;
    }
    ExternalPeerRouter externalPeerRouter = externalPeerRouterFromSubnet(srcSubnet, osRouterService, osNetworkService);
    if (externalPeerRouter == null) {
        return;
    }
    populateSnatFlowRules(context.inPacket(), srcInstPort, TpPort.tpPort(patPort), externalGatewayIp, externalPeerRouter);
    packetOut(eth.duplicate(), packetIn.receivedFrom().deviceId(), patPort, externalGatewayIp, externalPeerRouter);
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IPv4(org.onlab.packet.IPv4) InboundPacket(org.onosproject.net.packet.InboundPacket) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Router(org.openstack4j.model.network.Router) IpAddress(org.onlab.packet.IpAddress) OpenstackNetworkingUtil.externalPeerRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterFromSubnet) Subnet(org.openstack4j.model.network.Subnet) OpenstackNetworkingUtil.getRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getRouterFromSubnet)

Example 13 with ExternalPeerRouter

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

the class OpenstackRoutingSnatHandler method setStatefulSnatRules.

private void setStatefulSnatRules(RouterInterface routerIface, boolean install) {
    Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
    Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
    Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
    if (netType == FLAT) {
        log.warn("FLAT typed network does not need SNAT rules");
        return;
    }
    Optional<Router> osRouter = osRouterService.routers().stream().filter(router -> routerIface.getId().equals(router.getId())).findAny();
    if (!osRouter.isPresent()) {
        log.warn("Cannot find a router attached with the given router interface {} ", routerIface);
        return;
    }
    IpAddress natAddress = externalGatewayIpSnatEnabled(osRouter.get(), osNetworkAdminService);
    if (natAddress == null) {
        log.debug("NAT address is not found");
        return;
    }
    IpAddress extRouterAddress = getGatewayIpAddress(osRouter.get());
    if (extRouterAddress == null) {
        log.warn("External router address is not found");
        return;
    }
    ExternalPeerRouter externalPeerRouter = osNetworkService.externalPeerRouter(extRouterAddress);
    if (externalPeerRouter == null) {
        log.warn("External peer router not found");
        return;
    }
    Map<OpenstackNode, PortRange> gwPortRangeMap = getAssignedPortsForGateway(ImmutableList.copyOf(osNodeService.nodes(GATEWAY)));
    osNodeService.completeNodes(GATEWAY).forEach(gwNode -> {
        if (install) {
            PortRange gwPortRange = gwPortRangeMap.get(gwNode);
            Map<String, PortRange> netPortRangeMap = getAssignedPortsForNet(getNetIdByRouterId(routerIface.getId()), gwPortRange.min(), gwPortRange.max());
            PortRange netPortRange = netPortRangeMap.get(osNet.getId());
            setStatefulSnatUpstreamRule(gwNode, natAddress, Long.parseLong(osNet.getProviderSegID()), externalPeerRouter, netPortRange.min(), netPortRange.max(), install);
        } else {
            setStatefulSnatUpstreamRule(gwNode, natAddress, Long.parseLong(osNet.getProviderSegID()), externalPeerRouter, 0, 0, install);
        }
    });
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Constants(org.onosproject.openstacknetworking.api.Constants) InstancePortEvent(org.onosproject.openstacknetworking.api.InstancePortEvent) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) USE_STATEFUL_SNAT_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT_DEFAULT) StorageService(org.onosproject.store.service.StorageService) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) OpenstackNetworkingUtil.externalGatewayIpSnatEnabled(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalGatewayIpSnatEnabled) USE_STATEFUL_SNAT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT) RulePopulatorUtil(org.onosproject.openstacknetworking.util.RulePopulatorUtil) InstancePortListener(org.onosproject.openstacknetworking.api.InstancePortListener) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) OpenstackNetworkingUtil.externalPeerRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterFromSubnet) PRIORITY_EXTERNAL_ROUTING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_EXTERNAL_ROUTING_RULE) DeviceId(org.onosproject.net.DeviceId) ROUTING_TABLE(org.onosproject.openstacknetworking.api.Constants.ROUTING_TABLE) Dictionary(java.util.Dictionary) Tools(org.onlab.util.Tools) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) ComponentContext(org.osgi.service.component.ComponentContext) KryoNamespace(org.onlab.util.KryoNamespace) RouterInterface(org.openstack4j.model.network.RouterInterface) Component(org.osgi.service.component.annotations.Component) GW_COMMON_TABLE(org.onosproject.openstacknetworking.api.Constants.GW_COMMON_TABLE) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) DEFAULT_GATEWAY_MAC(org.onosproject.openstacknetworking.api.Constants.DEFAULT_GATEWAY_MAC) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Port(org.openstack4j.model.network.Port) TpPort(org.onlab.packet.TpPort) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) VlanId(org.onlab.packet.VlanId) MoreObjects(com.google.common.base.MoreObjects) IPv4(org.onlab.packet.IPv4) OpenstackRouterListener(org.onosproject.openstacknetworking.api.OpenstackRouterListener) ConfigProperty(org.onosproject.cfg.ConfigProperty) LeadershipService(org.onosproject.cluster.LeadershipService) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) TCP(org.onlab.packet.TCP) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) VLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) OpenstackNetworkingUtil.getPropertyValueAsBoolean(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) PRIORITY_SNAT_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_SNAT_RULE) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) PacketContext(org.onosproject.net.packet.PacketContext) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) IpPrefix(org.onlab.packet.IpPrefix) PRIORITY_STATEFUL_SNAT_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_STATEFUL_SNAT_RULE) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) OpenstackRouterEvent(org.onosproject.openstacknetworking.api.OpenstackRouterEvent) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) ImmutableList(com.google.common.collect.ImmutableList) Router(org.openstack4j.model.network.Router) IP(org.openstack4j.model.network.IP) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ExternalGateway(org.openstack4j.model.network.ExternalGateway) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) Subnet(org.openstack4j.model.network.Subnet) Maps(com.google.common.collect.Maps) UDP(org.onlab.packet.UDP) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) CT_NAT_SRC_FLAG(org.onosproject.openstacknetworking.util.RulePopulatorUtil.CT_NAT_SRC_FLAG) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) DistributedSet(org.onosproject.store.service.DistributedSet) OpenstackNetworkingUtil.getRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getRouterFromSubnet) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Router(org.openstack4j.model.network.Router) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkingUtil.tunnelPortNumByNetType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType) Network(org.openstack4j.model.network.Network) IpAddress(org.onlab.packet.IpAddress) OpenstackNetworkingUtil.externalPeerRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterFromSubnet) Subnet(org.openstack4j.model.network.Subnet) OpenstackNetworkingUtil.getRouterFromSubnet(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getRouterFromSubnet)

Example 14 with ExternalPeerRouter

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

the class OpenstackNetworkManager method externalPeerRouterMac.

@Override
public MacAddress externalPeerRouterMac(ExternalGateway externalGateway) {
    IpAddress ipAddress = getExternalPeerRouterIp(externalGateway);
    if (ipAddress == null) {
        return null;
    }
    ExternalPeerRouter peerRouter = osNetworkStore.externalPeerRouter(ipAddress.toString());
    if (peerRouter == null) {
        throw new NoSuchElementException();
    } else {
        return peerRouter.macAddress();
    }
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) NoSuchElementException(java.util.NoSuchElementException)

Example 15 with ExternalPeerRouter

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

the class OpenstackNetworkManager method deriveExternalPeerRouterMac.

@Override
public void deriveExternalPeerRouterMac(ExternalGateway externalGateway, Router router, VlanId vlanId) {
    log.info("deriveExternalPeerRouterMac called");
    IpAddress sourceIp = getExternalGatewaySourceIp(externalGateway, router);
    IpAddress targetIp = getExternalPeerRouterIp(externalGateway);
    if (sourceIp == null || targetIp == null) {
        log.warn("Failed to derive external router mac address because " + "source IP {} or target IP {} is null", sourceIp, targetIp);
        return;
    }
    ExternalPeerRouter peerRouter = osNetworkStore.externalPeerRouter(targetIp.toString());
    // MAC address has been derived
    if (peerRouter != null && !peerRouter.macAddress().equals(MacAddress.NONE)) {
        return;
    }
    MacAddress sourceMac = Constants.DEFAULT_GATEWAY_MAC;
    Ethernet ethRequest = ARP.buildArpRequest(sourceMac.toBytes(), sourceIp.toOctets(), targetIp.toOctets(), vlanId.id());
    if (osNodeService.completeNodes(GATEWAY).isEmpty()) {
        log.warn("There's no complete gateway");
        return;
    }
    OpenstackNode gatewayNode = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
    if (gatewayNode == null) {
        return;
    }
    if (gatewayNode.uplinkPortNum() == null) {
        log.warn("There's no uplink port for gateway node {}", gatewayNode.toString());
        return;
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(gatewayNode.uplinkPortNum()).build();
    packetService.emit(new DefaultOutboundPacket(gatewayNode.intgBridge(), treatment, ByteBuffer.wrap(ethRequest.serialize())));
    ExternalPeerRouter derivedRouter = DefaultExternalPeerRouter.builder().ipAddress(targetIp).macAddress(MacAddress.NONE).vlanId(vlanId).build();
    osNetworkStore.createExternalPeerRouter(derivedRouter);
    log.info("Initializes external peer router map with peer router IP {}", targetIp.toString());
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

ExternalPeerRouter (org.onosproject.openstacknetworking.api.ExternalPeerRouter)17 IpAddress (org.onlab.packet.IpAddress)6 VlanId (org.onlab.packet.VlanId)4 OpenstackNetworkAdminService (org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)4 Router (org.openstack4j.model.network.Router)4 Subnet (org.openstack4j.model.network.Subnet)4 List (java.util.List)3 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)3 ExternalGateway (org.openstack4j.model.network.ExternalGateway)3 Network (org.openstack4j.model.network.Network)3 Lists (com.google.common.collect.Lists)2 Argument (org.apache.karaf.shell.api.action.Argument)2 Command (org.apache.karaf.shell.api.action.Command)2 Test (org.junit.Test)2 Ethernet (org.onlab.packet.Ethernet)2 IPv4 (org.onlab.packet.IPv4)2 MacAddress (org.onlab.packet.MacAddress)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)2