Search in sources :

Example 16 with InstancePort

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

the class OpenstackFlowTraceCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNodeAdminService osNodeService = get(OpenstackNodeAdminService.class);
    InstancePortAdminService instancePortService = get(InstancePortAdminService.class);
    OpenstackNetworkAdminService osNetService = get(OpenstackNetworkAdminService.class);
    Optional<InstancePort> srcInstance = instancePortService.instancePorts().stream().filter(port -> port.ipAddress().toString().equals(srcIp)).findAny();
    if (!srcInstance.isPresent()) {
        print(NO_ELEMENT);
        return;
    }
    OpenstackNode srcNode = osNodeService.node(srcInstance.get().deviceId());
    if (srcNode == null || srcNode.sshAuthInfo() == null) {
        log.error("Openstack node {} is null or has no SSH authentication information.\n" + " Please refers to the sample network-cfg.json in " + "OpenstackNode app to push SSH authentication information", srcNode == null ? "" : srcNode.hostname());
        return;
    }
    if (dstIp.equals(osNetService.gatewayIp(srcInstance.get().portId()))) {
        dstIp = srcIp;
    }
    // print uplink flow trace result
    String requestStringUplink = traceRequestString(srcIp, dstIp, srcInstance.get(), osNetService, true);
    print(FLOW_TRACE_REQUEST_STRING_UPLINK + requestStringUplink);
    String requestStringDownlink = traceRequestString(srcIp, dstIp, srcInstance.get(), osNetService, false);
    print(FLOW_TRACE_REQUEST_STRING_DOWNLINK + requestStringDownlink);
    String traceResult = sendTraceRequestToNode(requestStringUplink + '\n' + requestStringDownlink, srcNode);
    print(traceResult);
}
Also used : OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Argument(org.apache.karaf.shell.api.action.Argument) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) AbstractShellCommand.get(org.onosproject.cli.AbstractShellCommand.get) Command(org.apache.karaf.shell.api.action.Command) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Completion(org.apache.karaf.shell.api.action.Completion) OpenstackNetworkingUtil.traceRequestString(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.traceRequestString) OpenstackNetworkingUtil.sendTraceRequestToNode(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.sendTraceRequestToNode) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) OpenstackNetworkingUtil.traceRequestString(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.traceRequestString) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)

Example 17 with InstancePort

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

the class OpenstackRoutingSnatHandler method processSnatPacket.

private void processSnatPacket(PacketContext context, Ethernet eth) {
    if (getStatefulSnatFlag()) {
        return;
    }
    IPv4 iPacket = (IPv4) eth.getPayload();
    InboundPacket packetIn = context.inPacket();
    int patPort = getPortNum();
    InstancePort srcInstPort = instancePortService.instancePort(eth.getSourceMAC());
    if (srcInstPort == null) {
        log.error(ERR_PACKET_IN + "source host(MAC:{}) does not exist", eth.getSourceMAC());
        return;
    }
    IpAddress srcIp = IpAddress.valueOf(iPacket.getSourceAddress());
    Subnet srcSubnet = getSourceSubnet(srcInstPort, srcIp);
    Router osRouter = getRouterFromSubnet(srcSubnet, osRouterService);
    if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
        // this router does not have external connectivity
        log.warn("No router is associated with the given subnet {}", srcSubnet);
        return;
    }
    IpAddress externalGatewayIp = externalGatewayIpSnatEnabled(osRouter, osNetworkAdminService);
    if (externalGatewayIp == null) {
        return;
    }
    ExternalPeerRouter externalPeerRouter = externalPeerRouterFromSubnet(srcSubnet, osRouterService, osNetworkService);
    if (externalPeerRouter == null) {
        return;
    }
    populateSnatFlowRules(context.inPacket(), srcInstPort, TpPort.tpPort(patPort), externalGatewayIp, externalPeerRouter);
    packetOut(eth.duplicate(), packetIn.receivedFrom().deviceId(), patPort, externalGatewayIp, externalPeerRouter);
}
Also used : ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) IPv4(org.onlab.packet.IPv4) InboundPacket(org.onosproject.net.packet.InboundPacket) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) Router(org.openstack4j.model.network.Router) 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)

Example 18 with InstancePort

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

the class OpenstackRoutingSnatHandler method getSourceSubnet.

private Subnet getSourceSubnet(InstancePort instance, IpAddress srcIp) {
    Port osPort = osNetworkService.port(instance.portId());
    IP fixedIp = osPort.getFixedIps().stream().filter(ip -> IpAddress.valueOf(ip.getIpAddress()).equals(srcIp)).findAny().orElse(null);
    if (fixedIp == null) {
        return null;
    }
    return osNetworkService.subnet(fixedIp.getSubnetId());
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.openstack4j.model.network.Port) TpPort(org.onlab.packet.TpPort) IP(org.openstack4j.model.network.IP)

Example 19 with InstancePort

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

the class OpenstackSwitchingArpHandler method processPacketIn.

/**
 * Processes ARP request packets.
 * It checks if the target IP is owned by a known host first and then ask to
 * OpenStack if it's not. This ARP proxy does not support overlapping IP.
 *
 * @param context   packet context
 * @param ethPacket ethernet packet
 */
private void processPacketIn(PacketContext context, Ethernet ethPacket) {
    // if the ARP mode is configured as broadcast mode, we simply ignore ARP packet_in
    if (ARP_BROADCAST_MODE.equals(getArpMode())) {
        return;
    }
    ARP arpPacket = (ARP) ethPacket.getPayload();
    if (arpPacket.getOpCode() != ARP.OP_REQUEST) {
        return;
    }
    InstancePort srcInstPort = instancePortService.instancePort(ethPacket.getSourceMAC());
    if (srcInstPort == null) {
        log.trace("Failed to find source instance port(MAC:{})", ethPacket.getSourceMAC());
        return;
    }
    IpAddress targetIp = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress());
    MacAddress replyMac = isGatewayIp(targetIp) ? MacAddress.valueOf(gatewayMac) : getMacFromHostOpenstack(targetIp, srcInstPort.networkId());
    if (replyMac == MacAddress.NONE) {
        log.trace("Failed to find MAC address for {}", targetIp);
        return;
    }
    Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), replyMac, ethPacket);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(context.inPacket().receivedFrom().port()).build();
    packetService.emit(new DefaultOutboundPacket(context.inPacket().receivedFrom().deviceId(), treatment, ByteBuffer.wrap(ethReply.serialize())));
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ARP(org.onlab.packet.ARP)

Example 20 with InstancePort

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

the class OpenstackSwitchingHandler method setForwardingRulesForTunnel.

/**
 * Configures the flow rules which are used for L2 packet switching.
 * Note that these rules will be inserted in switching table (table 5).
 *
 * @param instPort instance port object
 * @param install install flag, add the rule if true, remove it otherwise
 */
private void setForwardingRulesForTunnel(InstancePort instPort, boolean install) {
    // switching rules for the instPorts in the same node
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(instPort.ipAddress().toIpPrefix()).matchTunnelId(getVni(instPort)).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthDst(instPort.macAddress()).setOutput(instPort.portNumber()).build();
    osFlowRuleService.setRule(appId, instPort.deviceId(), selector, treatment, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
    // switching rules for the instPorts in the remote node
    OpenstackNode localNode = osNodeService.node(instPort.deviceId());
    if (localNode == null) {
        final String error = String.format("Cannot find openstack node for %s", instPort.deviceId());
        throw new IllegalStateException(error);
    }
    osNodeService.completeNodes(COMPUTE).stream().filter(remoteNode -> !remoteNode.intgBridge().equals(localNode.intgBridge())).forEach(remoteNode -> {
        PortNumber portNum = tunnelPortNumByNetId(instPort.networkId(), osNetworkService, remoteNode);
        TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, remoteNode.intgBridge(), localNode.dataIp().getIp4Address()), remoteNode.intgBridge()).setOutput(portNum).build();
        osFlowRuleService.setRule(appId, remoteNode.intgBridge(), selector, treatmentToRemote, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
    });
}
Also used : CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) InstancePortEvent(org.onosproject.openstacknetworking.api.InstancePortEvent) OPENSTACK_INSTANCE_MIGRATION_STARTED(org.onosproject.openstacknetworking.api.InstancePortEvent.Type.OPENSTACK_INSTANCE_MIGRATION_STARTED) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) PRIORITY_TUNNEL_TAG_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_TUNNEL_TAG_RULE) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) ACL_EGRESS_TABLE(org.onosproject.openstacknetworking.api.Constants.ACL_EGRESS_TABLE) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) PRIORITY_ADMIN_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ADMIN_RULE) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) InstancePortListener(org.onosproject.openstacknetworking.api.InstancePortListener) Objects(java.util.Objects) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) OpenstackNetworkingUtil.swapStaleLocation(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.swapStaleLocation) ClusterService(org.onosproject.cluster.ClusterService) OpenstackNetworkingUtil.tunnelPortNumByNetId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetId) PRE_FLAT_TABLE(org.onosproject.openstacknetworking.api.Constants.PRE_FLAT_TABLE) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) ARP_TABLE(org.onosproject.openstacknetworking.api.Constants.ARP_TABLE) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) Port(org.openstack4j.model.network.Port) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FORWARDING_TABLE(org.onosproject.openstacknetworking.api.Constants.FORWARDING_TABLE) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) PRIORITY_SWITCHING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) ConfigProperty(org.onosproject.cfg.ConfigProperty) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) VTAG_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAG_TABLE) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

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