Search in sources :

Example 1 with VLAN

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

the class OpenstackSwitchingArpHandler method setFakeGatewayArpRule.

/**
 * Installs flow rules which convert ARP request packet into ARP reply
 * by adding a fake gateway MAC address as Source Hardware Address.
 *
 * @param osSubnet  openstack subnet
 * @param network   openstack network
 * @param install   flag which indicates whether to install rule or remove rule
 * @param osNode    openstack node
 */
private void setFakeGatewayArpRule(Subnet osSubnet, Network network, boolean install, OpenstackNode osNode) {
    if (ARP_BROADCAST_MODE.equals(getArpMode())) {
        Type netType = osNetworkService.networkType(network.getId());
        String gateway = osSubnet.getGateway();
        if (gateway == null) {
            return;
        }
        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
        if (netType == VLAN) {
            sBuilder.matchVlanId(VlanId.vlanId(network.getProviderSegID()));
        } else if (netType == VXLAN || netType == GRE || netType == GENEVE) {
            // different networks
            if (!install) {
                long numOfDupGws = osNetworkService.subnets().stream().filter(s -> !s.getId().equals(osSubnet.getId())).filter(s -> s.getGateway() != null).filter(s -> s.getGateway().equals(osSubnet.getGateway())).count();
                if (numOfDupGws > 0) {
                    return;
                }
            }
        }
        sBuilder.matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(gateway));
        if (osNode == null) {
            osNodeService.completeNodes(COMPUTE).forEach(n -> {
                Device device = deviceService.getDevice(n.intgBridge());
                TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
                if (netType == VLAN) {
                    tBuilder.popVlan();
                }
                tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setEthSrc(MacAddress.valueOf(gatewayMac)).setOutput(PortNumber.IN_PORT);
                osFlowRuleService.setRule(appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
            });
        } else {
            Device device = deviceService.getDevice(osNode.intgBridge());
            TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
            if (netType == VLAN) {
                tBuilder.popVlan();
            }
            tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setOutput(PortNumber.IN_PORT);
            osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
        }
    }
}
Also used : OpenstackGroupRuleService(org.onosproject.openstacknetworking.api.OpenstackGroupRuleService) CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ARP(org.onlab.packet.ARP) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) PRIORITY_ARP_REQUEST_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REQUEST_RULE) InstancePortEvent(org.onosproject.openstacknetworking.api.InstancePortEvent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) PRIORITY_ARP_REPLY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_REPLY_RULE) Ethernet(org.onlab.packet.Ethernet) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) VLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) RulePopulatorUtil.buildMoveEthSrcToDstExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveEthSrcToDstExtension) RulePopulatorUtil.buildMoveArpShaToThaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpShaToThaExtension) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) ALL(org.onosproject.net.group.GroupDescription.Type.ALL) GRE(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.GRE) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Ip4Address(org.onlab.packet.Ip4Address) Device(org.onosproject.net.Device) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) ARP_PROXY_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_PROXY_MODE) Deactivate(org.osgi.service.component.annotations.Deactivate) PRIORITY_ARP_GROUP_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GROUP_RULE) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) InstancePortListener(org.onosproject.openstacknetworking.api.InstancePortListener) NetworkType(org.openstack4j.model.network.NetworkType) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) FLAT(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.FLAT) PacketContext(org.onosproject.net.packet.PacketContext) OpenstackNetworkingUtil.swapStaleLocation(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.swapStaleLocation) ClusterService(org.onosproject.cluster.ClusterService) ARP_MODE_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE_DEFAULT) OpenstackNetworkingUtil.tunnelPortNumByNetId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetId) Dictionary(java.util.Dictionary) IdEntity(org.openstack4j.model.common.IdEntity) Tools(org.onlab.util.Tools) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) GATEWAY_MAC_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC_DEFAULT) ComponentContext(org.osgi.service.component.ComponentContext) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) GroupBucket(org.onosproject.net.group.GroupBucket) RulePopulatorUtil.buildMoveArpSpaToTpaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpSpaToTpaExtension) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) GATEWAY_MAC(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC) ARP_TABLE(org.onosproject.openstacknetworking.api.Constants.ARP_TABLE) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ARP_MODE(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.ACTIVE) 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) PRIORITY_ARP_GATEWAY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GATEWAY_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) GroupId(org.onosproject.core.GroupId) ConfigProperty(org.onosproject.cfg.ConfigProperty) Modified(org.osgi.service.component.annotations.Modified) MacAddress(org.onlab.packet.MacAddress) VXLAN(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN) Reference(org.osgi.service.component.annotations.Reference) PRIORITY_ARP_CONTROL_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_CONTROL_RULE) LeadershipService(org.onosproject.cluster.LeadershipService) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) RulePopulatorUtil.buildGroupBucket(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildGroupBucket) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) NetworkType(org.openstack4j.model.network.NetworkType) EthType(org.onlab.packet.EthType) Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 ByteBuffer (java.nio.ByteBuffer)1 Dictionary (java.util.Dictionary)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)1 Collectors (java.util.stream.Collectors)1 ARP (org.onlab.packet.ARP)1 EthType (org.onlab.packet.EthType)1 Ethernet (org.onlab.packet.Ethernet)1 Ip4Address (org.onlab.packet.Ip4Address)1 IpAddress (org.onlab.packet.IpAddress)1 MacAddress (org.onlab.packet.MacAddress)1 VlanId (org.onlab.packet.VlanId)1 Tools (org.onlab.util.Tools)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)1