Search in sources :

Example 21 with InstancePort

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

the class OpenstackK8sIntegrationManager method setNodePortEgressRules.

private void setNodePortEgressRules(IpAddress k8sNodeIp, String osK8sExtPortName, boolean install) {
    InstancePort instPort = instPortByNodeIp(k8sNodeIp);
    if (instPort == null) {
        return;
    }
    OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
    if (osNode == null) {
        return;
    }
    PortNumber osK8sExtPortNum = portNumberByNodeIpAndPortName(k8sNodeIp, osK8sExtPortName);
    Port phyPort = phyPortByInstPort(instPort);
    if (phyPort == null) {
        log.warn("No phys interface found for instance port {}", instPort);
        return;
    }
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(osK8sExtPortNum).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthSrc(instPort.macAddress()).setOutput(phyPort.number()).build();
    osFlowRuleService.setRule(appId, osNode.intgBridge(), selector, treatment, PRIORITY_CNI_PT_NODE_PORT_IP_RULE, PRE_FLAT_TABLE, install);
    setJumpRules(osK8sExtPortNum, osNode, install);
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.onosproject.net.Port) TpPort(org.onlab.packet.TpPort) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 22 with InstancePort

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

the class OpenstackRoutingArpHandler method processArpPacket.

private void processArpPacket(PacketContext context, Ethernet ethernet) {
    ARP arp = (ARP) ethernet.getPayload();
    if (arp.getOpCode() == ARP.OP_REQUEST && ARP_PROXY_MODE.equals(getArpMode())) {
        if (log.isTraceEnabled()) {
            log.trace("ARP request received from {} for {}", Ip4Address.valueOf(arp.getSenderProtocolAddress()).toString(), Ip4Address.valueOf(arp.getTargetProtocolAddress()).toString());
        }
        IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress());
        MacAddress targetMac = null;
        NetFloatingIP floatingIP = osRouterAdminService.floatingIps().stream().filter(ip -> ip.getFloatingIpAddress().equals(targetIp.toString())).findAny().orElse(null);
        // In case target ip is for associated floating ip, sets target mac to vm's.
        if (floatingIP != null && floatingIP.getPortId() != null) {
            InstancePort instPort = instancePortService.instancePort(floatingIP.getPortId());
            if (instPort == null) {
                log.trace("Unknown target ARP request for {}, ignore it", targetIp);
                return;
            } else {
                targetMac = instPort.macAddress();
            }
            OpenstackNode gw = getGwByInstancePort(osNodeService.completeNodes(GATEWAY), instPort);
            if (gw == null) {
                return;
            }
            // if the ARP packet_in received from non-relevant GWs, we simply ignore it
            if (!Objects.equals(gw.intgBridge(), context.inPacket().receivedFrom().deviceId())) {
                return;
            }
        }
        if (isExternalGatewaySourceIp(targetIp)) {
            targetMac = Constants.DEFAULT_GATEWAY_MAC;
        }
        if (targetMac == null) {
            log.trace("Unknown target ARP request for {}, ignore it", targetIp);
            return;
        }
        Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), targetMac, ethernet);
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(context.inPacket().receivedFrom().port()).build();
        packetService.emit(new DefaultOutboundPacket(context.inPacket().receivedFrom().deviceId(), treatment, ByteBuffer.wrap(ethReply.serialize())));
        context.block();
    }
    if (arp.getOpCode() == ARP.OP_REPLY) {
        ConnectPoint cp = context.inPacket().receivedFrom();
        PortNumber receivedPortNum = cp.port();
        IpAddress spa = Ip4Address.valueOf(arp.getSenderProtocolAddress());
        MacAddress sha = MacAddress.valueOf(arp.getSenderHardwareAddress());
        log.debug("ARP reply ip: {}, mac: {}", spa, sha);
        try {
            Set<String> extRouterIps = osNetworkService.externalPeerRouters().stream().map(r -> r.ipAddress().toString()).collect(Collectors.toSet());
            // if SPA is NOT contained in existing external router IP set, we ignore it
            if (!extRouterIps.contains(spa.toString())) {
                return;
            }
            OpenstackNode node = osNodeService.node(cp.deviceId());
            if (node == null) {
                return;
            }
            // we only handles the ARP-Reply message received by gateway node
            if (node.type() != GATEWAY) {
                return;
            }
            if (receivedPortNum.equals(node.uplinkPortNum())) {
                osNetworkAdminService.updateExternalPeerRouterMac(spa, sha);
            }
        } catch (Exception e) {
            log.error("Exception occurred because of {}", e);
        }
    }
}
Also used : OpenstackNetworkingUtil.getGwByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByInstancePort) OpenstackNetworkingUtil.processGarpPacketForFloatingIp(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.processGarpPacketForFloatingIp) CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) OpenstackRouterAdminService(org.onosproject.openstacknetworking.api.OpenstackRouterAdminService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ARP(org.onlab.packet.ARP) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.externalGatewayIp(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalGatewayIp) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) 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) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) 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) 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) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) InboundPacket(org.onosproject.net.packet.InboundPacket) NetFloatingIP(org.openstack4j.model.network.NetFloatingIP) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) OpenstackNetworkingUtil.getGwByComputeDevId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByComputeDevId) PacketContext(org.onosproject.net.packet.PacketContext) ClusterService(org.onosproject.cluster.ClusterService) ARP_MODE_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE_DEFAULT) OpenstackNetworkingUtil.floatingIpByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.floatingIpByInstancePort) DeviceId(org.onosproject.net.DeviceId) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) 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.buildMoveArpSpaToTpaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpSpaToTpaExtension) OpenstackRouterEvent(org.onosproject.openstacknetworking.api.OpenstackRouterEvent) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) 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) 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) OpenstackNetworkingUtil.externalPeerRouterForNetwork(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterForNetwork) 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) Port(org.openstack4j.model.network.Port) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) PRIORITY_ARP_GATEWAY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GATEWAY_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackRouterListener(org.onosproject.openstacknetworking.api.OpenstackRouterListener) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) ConfigProperty(org.onosproject.cfg.ConfigProperty) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) 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) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) OpenstackNetworkingUtil.getGwByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByInstancePort) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) OpenstackNetworkingUtil.floatingIpByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.floatingIpByInstancePort) NetFloatingIP(org.openstack4j.model.network.NetFloatingIP) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) PortNumber(org.onosproject.net.PortNumber) ARP(org.onlab.packet.ARP)

Example 23 with InstancePort

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

the class OpenstackRoutingFloatingIpHandler method associateFloatingIp.

private void associateFloatingIp(NetFloatingIP osFip) {
    InstancePort instPort = instancePortService.instancePort(osFip.getPortId());
    if (instPort == null) {
        log.warn("Failed to insert floating IP rule for {} due to missing of port info.", osFip.getFloatingIpAddress());
        return;
    }
    // set floating IP rules only if the port is associated to a VM
    if (!Strings.isNullOrEmpty(instPort.deviceId().toString())) {
        setFloatingIpRules(osFip, instPort, null, null, true);
        processGratuitousArpPacket(osFip, instPort);
    }
}
Also used : OpenstackNetworkingUtil.getGwByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByInstancePort) InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Example 24 with InstancePort

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

the class OpenstackRemoveAclCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackFlowRuleService flowRuleService = get(OpenstackFlowRuleService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(OPENSTACK_NETWORKING_APP_ID);
    InstancePortService instancePortService = get(InstancePortService.class);
    IpAddress srcIpAddress = null;
    IpAddress dstIpAddress = null;
    try {
        srcIpAddress = IpAddress.valueOf(srcIpStr);
        dstIpAddress = IpAddress.valueOf(dstIpStr);
    } catch (IllegalArgumentException e) {
        log.error("IllegalArgumentException occurred because of {}", e);
        return;
    }
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpAddress.toIpPrefix()).matchIPDst(dstIpAddress.toIpPrefix());
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop().build();
    if (srcPort != 0 || dstPort != 0) {
        sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP);
        if (srcPort != 0) {
            sBuilder.matchTcpSrc(TpPort.tpPort(srcPort));
        }
        if (dstPort != 0) {
            sBuilder.matchTcpDst(TpPort.tpPort(dstPort));
        }
    }
    log.info("Deny the packet from srcIp: {}, dstPort: {} to dstIp: {}, dstPort: {}", srcIpAddress.toString(), srcPort, dstIpAddress.toString(), dstPort);
    Optional<InstancePort> instancePort = instancePortService.instancePorts().stream().filter(port -> port.ipAddress().toString().equals(dstIpStr)).findAny();
    if (!instancePort.isPresent()) {
        log.info("Instance port that matches with the given dst ip address isn't present {}");
        return;
    }
    flowRuleService.setRule(appId, instancePort.get().deviceId(), sBuilder.build(), treatment, PRIORITY_FORCED_ACL_RULE, DHCP_TABLE, false);
}
Also used : TpPort(org.onlab.packet.TpPort) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PRIORITY_FORCED_ACL_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_FORCED_ACL_RULE) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) DHCP_TABLE(org.onosproject.openstacknetworking.api.Constants.DHCP_TABLE) CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Argument(org.apache.karaf.shell.api.action.Argument) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Command(org.apache.karaf.shell.api.action.Command) Ethernet(org.onlab.packet.Ethernet) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) IPv4(org.onlab.packet.IPv4) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) Service(org.apache.karaf.shell.api.action.lifecycle.Service) ApplicationId(org.onosproject.core.ApplicationId) Optional(java.util.Optional) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) CoreService(org.onosproject.core.CoreService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) ApplicationId(org.onosproject.core.ApplicationId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment)

Example 25 with InstancePort

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

the class OpenstackResetPortsCommand method resetPort.

private void resetPort(InstancePortAdminService service, String portId) {
    InstancePort instancePort = service.instancePort(portId);
    service.removeInstancePort(portId);
    try {
        sleep(SLEEP_MS);
    } catch (InterruptedException e) {
        log.error("Exception caused during port synchronization...");
    }
    service.createInstancePort(instancePort);
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Aggregations

InstancePort (org.onosproject.openstacknetworking.api.InstancePort)36 Test (org.junit.Test)13 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)10 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 InstancePortService (org.onosproject.openstacknetworking.api.InstancePortService)9 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)9 Set (java.util.Set)7 Argument (org.apache.karaf.shell.api.action.Argument)7 Command (org.apache.karaf.shell.api.action.Command)7 Service (org.apache.karaf.shell.api.action.lifecycle.Service)7 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)7 PortNumber (org.onosproject.net.PortNumber)7 Port (org.openstack4j.model.network.Port)7 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 OpenstackNetworkService (org.onosproject.openstacknetworking.api.OpenstackNetworkService)6 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)6