Search in sources :

Example 1 with ExternalPeerRouter

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

the class UpdateExternalPeerRouterVlanCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkAdminService osNetAdminService = get(OpenstackNetworkAdminService.class);
    OpenstackRouterService osRouterService = get(OpenstackRouterService.class);
    IpAddress externalPeerIpAddress = IpAddress.valueOf(IpAddress.Version.INET, Ip4Address.valueOf(ipAddress).toOctets());
    if (osNetAdminService.externalPeerRouters().isEmpty()) {
        print(NO_ELEMENT);
        return;
    } else if (osNetAdminService.externalPeerRouters().stream().noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
        print(NO_ELEMENT);
        return;
    }
    Subnet subnet = osNetAdminService.subnets().stream().filter(s -> s.getGateway().equals(ipAddress)).findAny().orElse(null);
    if (subnet == null) {
        return;
    }
    Network network = osNetAdminService.network(subnet.getNetworkId());
    if (network == null) {
        return;
    }
    Router router = osRouterService.routers().stream().filter(r -> r.getExternalGatewayInfo().getNetworkId().equals(network.getId())).findAny().orElse(null);
    if (router == null) {
        return;
    }
    try {
        if (vlanId.equals(NONE)) {
            osNetAdminService.updateExternalPeerRouterVlan(externalPeerIpAddress, VlanId.NONE);
            osNetAdminService.deriveExternalPeerRouterMac(router.getExternalGatewayInfo(), router, VlanId.NONE);
        } else {
            osNetAdminService.updateExternalPeerRouterVlan(externalPeerIpAddress, VlanId.vlanId(vlanId));
            osNetAdminService.deriveExternalPeerRouterMac(router.getExternalGatewayInfo(), router, VlanId.vlanId(vlanId));
        }
    } catch (IllegalArgumentException e) {
        log.error("Exception occurred because of {}", e.toString());
    }
    print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
    List<ExternalPeerRouter> routers = Lists.newArrayList(osNetAdminService.externalPeerRouters());
    for (ExternalPeerRouter r : routers) {
        print(FORMAT, r.ipAddress(), r.macAddress().toString(), r.vlanId());
    }
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService) Network(org.openstack4j.model.network.Network) VlanId(org.onlab.packet.VlanId) Argument(org.apache.karaf.shell.api.action.Argument) Subnet(org.openstack4j.model.network.Subnet) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Lists(com.google.common.collect.Lists) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Router(org.openstack4j.model.network.Router) Completion(org.apache.karaf.shell.api.action.Completion) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Network(org.openstack4j.model.network.Network) Router(org.openstack4j.model.network.Router) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) Subnet(org.openstack4j.model.network.Subnet) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService)

Example 2 with ExternalPeerRouter

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

the class OpenstackRoutingFloatingIpHandler method processGratuitousArpPacket.

private void processGratuitousArpPacket(NetFloatingIP floatingIP, InstancePort instancePort) {
    Set<OpenstackNode> gws = ImmutableSet.copyOf(osNodeService.completeNodes(GATEWAY));
    Network osNet = osNetworkService.network(instancePort.networkId());
    OpenstackNode selectedGw = getGwByInstancePort(gws, instancePort);
    ExternalPeerRouter externalPeerRouter = externalPeerRouterForNetwork(osNet, osNetworkService, osRouterAdminService);
    if (externalPeerRouter == null) {
        log.error("Failed to process GARP packet for floating ip {}, because ", NO_EXT_PEER_ROUTER_MSG);
        return;
    }
    processGarpPacketForFloatingIp(floatingIP, instancePort, externalPeerRouter.vlanId(), selectedGw, packetService);
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Network(org.openstack4j.model.network.Network) OpenstackNetworkingUtil.externalPeerRouterForNetwork(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterForNetwork) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 3 with ExternalPeerRouter

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

the class OpenstackRoutingFloatingIpHandler method setFloatingIpRules.

private void setFloatingIpRules(NetFloatingIP floatingIp, InstancePort instPort, OpenstackNode gateway, ExternalPeerRouter peerRouter, boolean install) {
    if (instPort == null) {
        log.debug("No instance port found");
        return;
    }
    Network osNet = osNetworkService.network(instPort.networkId());
    ExternalPeerRouter externalPeerRouter = peerRouter != null ? peerRouter : externalPeerRouterForNetwork(osNet, osNetworkService, osRouterAdminService);
    if (externalPeerRouter == null) {
        log.warn("External peer router is not ready for now, " + "floating IP rules will be installed/uninstalled " + "when external peer router is available...");
        return;
    }
    if (install) {
        preCommitPortService.subscribePreCommit(instPort.portId(), OPENSTACK_PORT_PRE_REMOVE, this.getClass().getName());
        log.info("Subscribed the port {} on listening pre-remove event", instPort.portId());
    } else {
        preCommitPortService.unsubscribePreCommit(instPort.portId(), OPENSTACK_PORT_PRE_REMOVE, instancePortService, this.getClass().getName());
        log.info("Unsubscribed the port {} on listening pre-remove event", instPort.portId());
    }
    updateComputeNodeRules(instPort, osNet, gateway, install);
    updateGatewayNodeRules(floatingIp, instPort, osNet, externalPeerRouter, gateway, install);
    // TODO: need to refactor setUpstreamRules if possible
    setUpstreamRules(floatingIp, osNet, instPort, externalPeerRouter, install);
    log.trace("Succeeded to set flow rules for floating ip {}:{} and install: {}", floatingIp.getFloatingIpAddress(), floatingIp.getFixedIpAddress(), install);
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Network(org.openstack4j.model.network.Network) OpenstackNetworkingUtil.externalPeerRouterForNetwork(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterForNetwork)

Example 4 with ExternalPeerRouter

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

the class OpenstackRoutingSnatHandler method routerUpdated.

private void routerUpdated(Router osRouter) {
    ExternalGateway exGateway = osRouter.getExternalGatewayInfo();
    ExternalPeerRouter externalPeerRouter = osNetworkAdminService.externalPeerRouter(exGateway);
    VlanId vlanId = externalPeerRouter == null ? VlanId.NONE : externalPeerRouter.vlanId();
    if (exGateway == null) {
        deleteUnassociatedExternalPeerRouter();
        osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> setSourceNat(iface, false));
    } else {
        osNetworkAdminService.deriveExternalPeerRouterMac(exGateway, osRouter, vlanId);
        osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> setSourceNat(iface, exGateway.isEnableSnat()));
    }
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) ExternalGateway(org.openstack4j.model.network.ExternalGateway) VlanId(org.onlab.packet.VlanId)

Example 5 with ExternalPeerRouter

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

the class OpenstackNetworkManager method updateExternalPeerRouter.

@Override
public void updateExternalPeerRouter(IpAddress ipAddress, MacAddress macAddress, VlanId vlanId) {
    checkNotNull(ipAddress, ERR_NULL_PEER_ROUTER_IP);
    ExternalPeerRouter existingPeerRouter = osNetworkStore.externalPeerRouter(ipAddress.toString());
    if (existingPeerRouter != null) {
        ExternalPeerRouter.Builder urBuilder = DefaultExternalPeerRouter.builder().ipAddress(ipAddress);
        if (macAddress == null) {
            urBuilder.macAddress(existingPeerRouter.macAddress());
        } else {
            urBuilder.macAddress(macAddress);
        }
        if (vlanId == null) {
            urBuilder.vlanId(existingPeerRouter.vlanId());
        } else {
            urBuilder.vlanId(vlanId);
        }
        osNetworkStore.updateExternalPeerRouter(urBuilder.build());
    }
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter)

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