Search in sources :

Example 1 with FLAT

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

the class OpenstackSwitchingHostProvider method processPortAdded.

/**
 * Processes port addition event.
 * Once a port addition event is detected, it tries to create a host instance
 * with openstack augmented host information such as networkId, portId,
 * createTime, segmentId and notifies to host provider.
 *
 * @param port port object used in ONOS
 */
void processPortAdded(Port port) {
    // TODO check the node state is COMPLETE
    org.openstack4j.model.network.Port osPort = osNetworkService.port(port);
    if (osPort == null) {
        log.warn(ERR_ADD_HOST + "OpenStack port for {} not found", port);
        return;
    }
    Network osNet = osNetworkService.network(osPort.getNetworkId());
    if (osNet == null) {
        log.warn(ERR_ADD_HOST + "OpenStack network {} not found", osPort.getNetworkId());
        return;
    }
    if (osPort.getFixedIps().isEmpty()) {
        log.warn(ERR_ADD_HOST + "no fixed IP for port {}", osPort.getId());
        return;
    }
    MacAddress mac = MacAddress.valueOf(osPort.getMacAddress());
    HostId hostId = HostId.hostId(mac);
    /* typically one openstack port should only be bound to one fix IP address;
           however, openstack4j binds multiple fixed IPs to one port, this might
           be a defect of openstack4j implementation */
    // TODO: we need to find a way to bind multiple ports from multiple
    // openstack networks into one host sooner or later
    Set<IpAddress> fixedIps = osPort.getFixedIps().stream().map(ip -> IpAddress.valueOf(ip.getIpAddress())).collect(Collectors.toSet());
    // connect point is the combination of switch ID with port number where
    // the host is attached to
    ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
    long createTime = System.currentTimeMillis();
    // we check whether the host already attached to same locations
    Host host = hostService.getHost(hostId);
    // build host annotations to include a set of meta info from neutron
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, osPort.getNetworkId()).set(ANNOTATION_PORT_ID, osPort.getId()).set(ANNOTATION_CREATE_TIME, String.valueOf(createTime));
    // FLAT typed network does not require segment ID
    Type netType = osNetworkService.networkType(osNet.getId());
    if (netType != FLAT) {
        annotations.set(ANNOTATION_SEGMENT_ID, osNet.getProviderSegID());
    }
    // build host description object
    HostDescription hostDesc = new DefaultHostDescription(mac, VlanId.NONE, new HostLocation(connectPoint, createTime), fixedIps, annotations.build());
    if (host != null) {
        Set<HostLocation> locations = host.locations().stream().filter(l -> l.deviceId().equals(connectPoint.deviceId())).filter(l -> l.port().equals(connectPoint.port())).collect(Collectors.toSet());
        // therefore, we simply add this into the location list
        if (locations.isEmpty()) {
            hostProviderService.addLocationToHost(hostId, new HostLocation(connectPoint, createTime));
        }
        // the hostDetected method invocation in turn triggers host Update event
        if (locations.size() == 1) {
            hostProviderService.hostDetected(hostId, hostDesc, false);
        }
    } else {
        hostProviderService.hostDetected(hostId, hostDesc, false);
    }
}
Also used : HostLocation(org.onosproject.net.HostLocation) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) ConnectPoint(org.onosproject.net.ConnectPoint) HostProviderService(org.onosproject.net.host.HostProviderService) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) TUNNEL_TYPE(org.onosproject.openstacknetworking.api.Constants.TUNNEL_TYPE) Port(org.onosproject.net.Port) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Constants.portNamePrefixMap(org.onosproject.openstacknetworking.api.Constants.portNamePrefixMap) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) HostDescription(org.onosproject.net.host.HostDescription) ANNOTATION_NETWORK_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_NETWORK_ID) HostProviderRegistry(org.onosproject.net.host.HostProviderRegistry) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) PORT_NAME_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_VM) HostService(org.onosproject.net.host.HostService) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) PORT_NAME_VHOST_USER_PREFIX_VM(org.onosproject.openstacknetworking.api.Constants.PORT_NAME_VHOST_USER_PREFIX_VM) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) Component(org.osgi.service.component.annotations.Component) ANNOTATION_SEGMENT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_SEGMENT_ID) Activate(org.osgi.service.component.annotations.Activate) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) AbstractProvider(org.onosproject.net.provider.AbstractProvider) ANNOTATION_PORT_ID(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_PORT_ID) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) HostProvider(org.onosproject.net.host.HostProvider) VlanId(org.onlab.packet.VlanId) ANNOTATION_CREATE_TIME(org.onosproject.openstacknetworking.api.Constants.ANNOTATION_CREATE_TIME) ProviderId(org.onosproject.net.provider.ProviderId) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) ConnectPoint(org.onosproject.net.ConnectPoint) HostDescription(org.onosproject.net.host.HostDescription) DefaultHostDescription(org.onosproject.net.host.DefaultHostDescription) OpenstackNetworkingUtil.vnicType(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) Network(org.openstack4j.model.network.Network) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress)

Example 2 with FLAT

use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT 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)

Aggregations

Optional (java.util.Optional)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 Collectors (java.util.stream.Collectors)2 IpAddress (org.onlab.packet.IpAddress)2 VlanId (org.onlab.packet.VlanId)2 Tools (org.onlab.util.Tools)2 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)2 CoreService (org.onosproject.core.CoreService)2 MastershipService (org.onosproject.mastership.MastershipService)2 DeviceService (org.onosproject.net.device.DeviceService)2 MoreObjects (com.google.common.base.MoreObjects)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 ByteBuffer (java.nio.ByteBuffer)1 Dictionary (java.util.Dictionary)1 List (java.util.List)1