Search in sources :

Example 1 with IP

use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.

the class OpenstackRouterListCommand method getRouterIfaceIp.

private String getRouterIfaceIp(RouterInterface iface) {
    Port osPort = netService.port(iface.getPortId());
    IP ipAddr = osPort.getFixedIps().stream().filter(ip -> ip.getSubnetId().equals(iface.getSubnetId())).findAny().orElse(null);
    return ipAddr == null ? "" : ipAddr.getIpAddress();
}
Also used : Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP)

Example 2 with IP

use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.

the class OpenstackRouterListCommand method doExecute.

@Override
protected void doExecute() {
    List<Router> routers = Lists.newArrayList(routerService.routers());
    routers.sort(Comparator.comparing(Router::getId));
    if (outputJson()) {
        print("%s", json(routers));
    } else {
        print(FORMAT, "ID", "Name", "External", "Internal");
        for (Router router : routers) {
            String exNetId = router.getExternalGatewayInfo() != null ? router.getExternalGatewayInfo().getNetworkId() : null;
            List<String> externals = Lists.newArrayList();
            if (exNetId != null) {
                // FIXME fix openstack4j to provide external gateway ip info
                externals = netService.ports(exNetId).stream().filter(port -> Objects.equals(port.getDeviceId(), router.getId())).flatMap(port -> port.getFixedIps().stream()).map(IP::getIpAddress).collect(Collectors.toList());
            }
            List<String> internals = Lists.newArrayList();
            routerService.routerInterfaces(router.getId()).forEach(iface -> {
                internals.add(getRouterIfaceIp(iface));
            });
            print(FORMAT, router.getId(), deriveResourceName(router), externals, internals);
        }
    }
}
Also used : OpenstackRouterService(org.onosproject.openstacknetworking.api.OpenstackRouterService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RouterInterface(org.openstack4j.model.network.RouterInterface) Collectors(java.util.stream.Collectors) Command(org.apache.karaf.shell.api.action.Command) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Objects(java.util.Objects) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) List(java.util.List) Lists(com.google.common.collect.Lists) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Router(org.openstack4j.model.network.Router) IP(org.openstack4j.model.network.IP) NeutronRouter(org.openstack4j.openstack.networking.domain.NeutronRouter) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Comparator(java.util.Comparator) OpenstackNetworkingUtil.modelEntityToJson(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson) OpenstackNetworkingUtil.prettyJson(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson) Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP) Router(org.openstack4j.model.network.Router) NeutronRouter(org.openstack4j.openstack.networking.domain.NeutronRouter)

Example 3 with IP

use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.

the class OpenstackNetworkManager method getExternalGatewaySourceIp.

private IpAddress getExternalGatewaySourceIp(ExternalGateway externalGateway, Router router) {
    Port exGatewayPort = ports(externalGateway.getNetworkId()).stream().filter(port -> Objects.equals(port.getDeviceId(), router.getId())).findAny().orElse(null);
    if (exGatewayPort == null) {
        log.warn("no external gateway port for router({})", deriveResourceName(router));
        return null;
    }
    IP ipAddress = exGatewayPort.getFixedIps().stream().findFirst().orElse(null);
    return ipAddress == null ? null : IpAddress.valueOf(ipAddress.getIpAddress());
}
Also used : Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP)

Example 4 with IP

use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.

the class OpenstackNetworkManager method gatewayIp.

@Override
public String gatewayIp(String portId) {
    checkNotNull(portId);
    Port port = port(portId);
    checkNotNull(port);
    IpAddress ipAddress = port.getFixedIps().stream().map(ip -> IpAddress.valueOf(ip.getIpAddress())).findAny().orElse(null);
    checkNotNull(ipAddress);
    Network network = network(port.getNetworkId());
    checkNotNull(network);
    return subnets(network.getId()).stream().filter(s -> IpPrefix.valueOf(s.getCidr()).contains(ipAddress)).map(Subnet::getGateway).findAny().orElse(null);
}
Also used : ListenerRegistry(org.onosproject.event.ListenerRegistry) ConsistentMap(org.onosproject.store.service.ConsistentMap) LOCAL(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.LOCAL) OpenstackNetworkingUtil.getIntfNameFromPciAddress(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) ARP(org.onlab.packet.ARP) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) StorageService(org.onosproject.store.service.StorageService) DIRECT(org.onosproject.openstacknetworking.api.Constants.DIRECT) VLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkStore(org.onosproject.openstacknetworking.api.OpenstackNetworkStore) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) GRE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE) Serializer(org.onosproject.store.service.Serializer) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) OpenstackNetworkStoreDelegate(org.onosproject.openstacknetworking.api.OpenstackNetworkStoreDelegate) Deactivate(org.osgi.service.component.annotations.Deactivate) PCISLOT(org.onosproject.openstacknetworking.api.Constants.PCISLOT) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) Optional(java.util.Optional) IpPrefix(org.onlab.packet.IpPrefix) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) KryoNamespace(org.onlab.util.KryoNamespace) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Objects.requireNonNull(java.util.Objects.requireNonNull) Router(org.openstack4j.model.network.Router) IP(org.openstack4j.model.network.IP) Activate(org.osgi.service.component.annotations.Activate) NoSuchElementException(java.util.NoSuchElementException) IpAddress(org.onlab.packet.IpAddress) Port(org.openstack4j.model.network.Port) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ExternalGateway(org.openstack4j.model.network.ExternalGateway) OpenstackNetwork(org.onosproject.openstacknetworking.api.OpenstackNetwork) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) GENEVE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GENEVE) Subnet(org.openstack4j.model.network.Subnet) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) VXLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Port(org.openstack4j.model.network.Port) Network(org.openstack4j.model.network.Network) OpenstackNetwork(org.onosproject.openstacknetworking.api.OpenstackNetwork) IpAddress(org.onlab.packet.IpAddress) Subnet(org.openstack4j.model.network.Subnet)

Example 5 with IP

use of org.openstack4j.model.network.IP in project onos by opennetworkinglab.

the class OpenstackNetworkManager method ipPrefix.

@Override
public IpPrefix ipPrefix(String portId) {
    checkNotNull(portId);
    Port port = port(portId);
    checkNotNull(port);
    IpAddress ipAddress = port.getFixedIps().stream().map(ip -> IpAddress.valueOf(ip.getIpAddress())).findAny().orElse(null);
    checkNotNull(ipAddress);
    Network network = network(port.getNetworkId());
    checkNotNull(network);
    return subnets(network.getId()).stream().map(s -> IpPrefix.valueOf(s.getCidr())).filter(prefix -> prefix.contains(ipAddress)).findAny().orElse(null);
}
Also used : ListenerRegistry(org.onosproject.event.ListenerRegistry) ConsistentMap(org.onosproject.store.service.ConsistentMap) LOCAL(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.LOCAL) OpenstackNetworkingUtil.getIntfNameFromPciAddress(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) ARP(org.onlab.packet.ARP) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) StorageService(org.onosproject.store.service.StorageService) DIRECT(org.onosproject.openstacknetworking.api.Constants.DIRECT) VLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkStore(org.onosproject.openstacknetworking.api.OpenstackNetworkStore) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) GRE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE) Serializer(org.onosproject.store.service.Serializer) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) OpenstackNetworkStoreDelegate(org.onosproject.openstacknetworking.api.OpenstackNetworkStoreDelegate) Deactivate(org.osgi.service.component.annotations.Deactivate) PCISLOT(org.onosproject.openstacknetworking.api.Constants.PCISLOT) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) Optional(java.util.Optional) IpPrefix(org.onlab.packet.IpPrefix) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) KryoNamespace(org.onlab.util.KryoNamespace) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Objects.requireNonNull(java.util.Objects.requireNonNull) Router(org.openstack4j.model.network.Router) IP(org.openstack4j.model.network.IP) Activate(org.osgi.service.component.annotations.Activate) NoSuchElementException(java.util.NoSuchElementException) IpAddress(org.onlab.packet.IpAddress) Port(org.openstack4j.model.network.Port) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ExternalGateway(org.openstack4j.model.network.ExternalGateway) OpenstackNetwork(org.onosproject.openstacknetworking.api.OpenstackNetwork) VlanId(org.onlab.packet.VlanId) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) GENEVE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GENEVE) Subnet(org.openstack4j.model.network.Subnet) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) VXLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Port(org.openstack4j.model.network.Port) Network(org.openstack4j.model.network.Network) OpenstackNetwork(org.onosproject.openstacknetworking.api.OpenstackNetwork) IpAddress(org.onlab.packet.IpAddress)

Aggregations

IP (org.openstack4j.model.network.IP)12 Port (org.openstack4j.model.network.Port)11 Network (org.openstack4j.model.network.Network)6 Subnet (org.openstack4j.model.network.Subnet)6 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 OpenstackNetworkService (org.onosproject.openstacknetworking.api.OpenstackNetworkService)5 List (java.util.List)4 Objects (java.util.Objects)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Sets (com.google.common.collect.Sets)3 ByteBuffer (java.nio.ByteBuffer)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 Set (java.util.Set)3 L3InterfaceIpv6AddressList (org.onap.aai.domain.yang.L3InterfaceIpv6AddressList)3 ARP (org.onlab.packet.ARP)3 Ethernet (org.onlab.packet.Ethernet)3 IpAddress (org.onlab.packet.IpAddress)3 MacAddress (org.onlab.packet.MacAddress)3 OpenstackNetworkingUtil.deriveResourceName (org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName)3