Search in sources :

Example 16 with ExternalPeerRouter

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

the class OpenstackNetworkingUtil method externalPeerRouterForNetwork.

/**
 * Returns the external peer router with supplied network information.
 *
 * @param network network
 * @param osNetworkService openstack network service
 * @param osRouterAdminService openstack router admin service
 * @return external peer router
 */
public static ExternalPeerRouter externalPeerRouterForNetwork(Network network, OpenstackNetworkService osNetworkService, OpenstackRouterAdminService osRouterAdminService) {
    if (network == null) {
        return null;
    }
    Subnet subnet = osNetworkService.subnets(network.getId()).stream().findAny().orElse(null);
    if (subnet == null) {
        return null;
    }
    RouterInterface osRouterIface = osRouterAdminService.routerInterfaces().stream().filter(i -> Objects.equals(i.getSubnetId(), subnet.getId())).findAny().orElse(null);
    if (osRouterIface == null) {
        return null;
    }
    Router osRouter = osRouterAdminService.router(osRouterIface.getId());
    if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
        return null;
    }
    ExternalGateway exGatewayInfo = osRouter.getExternalGatewayInfo();
    return osNetworkService.externalPeerRouter(exGatewayInfo);
}
Also used : NeutronRouterInterface(org.openstack4j.openstack.networking.domain.NeutronRouterInterface) RouterInterface(org.openstack4j.model.network.RouterInterface) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Router(org.openstack4j.model.network.Router) Subnet(org.openstack4j.model.network.Subnet) ExternalGateway(org.openstack4j.model.network.ExternalGateway)

Example 17 with ExternalPeerRouter

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

the class UpdateExternalPeerRouterCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkAdminService service = get(OpenstackNetworkAdminService.class);
    IpAddress externalPeerIpAddress = IpAddress.valueOf(IpAddress.Version.INET, Ip4Address.valueOf(ipAddress).toOctets());
    if (service.externalPeerRouters().isEmpty()) {
        print(NO_ELEMENT);
        return;
    } else if (service.externalPeerRouters().stream().noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
        print(NO_ELEMENT);
        return;
    }
    try {
        if (vlanId.equals(NONE)) {
            service.updateExternalPeerRouter(externalPeerIpAddress, MacAddress.valueOf(macAddress), VlanId.NONE);
        } else {
            service.updateExternalPeerRouter(externalPeerIpAddress, MacAddress.valueOf(macAddress), 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(service.externalPeerRouters());
    for (ExternalPeerRouter router : routers) {
        print(FORMAT, router.ipAddress(), router.macAddress().toString(), router.vlanId());
    }
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) VlanId(org.onlab.packet.VlanId) Argument(org.apache.karaf.shell.api.action.Argument) 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) Completion(org.apache.karaf.shell.api.action.Completion) MacAddress(org.onlab.packet.MacAddress) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IpAddress(org.onlab.packet.IpAddress) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)

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