Search in sources :

Example 6 with InstancePortService

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

the class OpenstackAddAclCommand 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;
    IpAddress dstIpAddress;
    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, true);
}
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 7 with InstancePortService

use of org.onosproject.openstacknetworking.api.InstancePortService 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 8 with InstancePortService

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

the class InstanceIpAddressCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    InstancePortService instancePortService = AbstractShellCommand.get(InstancePortService.class);
    Set<IpAddress> set = instancePortService.instancePorts().stream().map(InstancePort::ipAddress).collect(Collectors.toSet());
    set.add(IpAddress.valueOf(EXTERNAL_IP));
    SortedSet<String> strings = delegate.getStrings();
    Iterator<IpAddress> it = set.iterator();
    while (it.hasNext()) {
        strings.add(it.next().toString());
    }
    return delegate.complete(session, commandLine, candidates);
}
Also used : InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) IpAddress(org.onlab.packet.IpAddress)

Example 9 with InstancePortService

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

the class InstancePortListCommand method doExecute.

@Override
protected void doExecute() {
    InstancePortService service = get(InstancePortService.class);
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    List<InstancePort> instancePorts = Lists.newArrayList(service.instancePorts());
    instancePorts.sort(Comparator.comparing(InstancePort::portId));
    if (outputJson()) {
        print("%s", json(this, instancePorts));
    } else {
        print(FORMAT, "Port ID", "VM Device ID", "State", "Device ID", "Port Number", "Fixed IP");
        for (InstancePort port : instancePorts) {
            Port neutronPort = osNetService.port(port.portId());
            String vmId = "N/A";
            if (neutronPort != null) {
                vmId = neutronPort.getDeviceId();
            }
            print(FORMAT, port.portId(), vmId, port.state(), port.deviceId().toString(), port.portNumber().toLong(), port.ipAddress().toString());
        }
    }
}
Also used : InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.openstack4j.model.network.Port)

Example 10 with InstancePortService

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

the class OpenstackVmStatsCommand method doExecute.

@Override
protected void doExecute() {
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    InstancePortService osInstanceService = get(InstancePortService.class);
    DeviceService deviceService = get(DeviceService.class);
    Set<Port> ports = osNetService.ports().stream().filter(port -> port.getDeviceId().equals(vmDeviceId)).collect(Collectors.toSet());
    if (ports.isEmpty()) {
        print(NO_PORTS);
        return;
    }
    Set<InstancePort> instancePorts = getInstancePortFromNeutronPortList(ports, osInstanceService);
    if (instancePorts.isEmpty()) {
        print(NO_INSTANCE_PORTS);
        return;
    }
    Set<PortNumber> portNumbers = instancePorts.stream().map(InstancePort::portNumber).collect(Collectors.toSet());
    instancePorts.stream().findAny().ifPresent(instancePort -> {
        DeviceId deviceId = instancePort.deviceId();
        if (delta) {
            printPortStatsDelta(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
            if (table) {
                printPortStatsDeltaTable(vmDeviceId, deviceService.getPortDeltaStatistics(deviceId), portNumbers);
            }
        } else {
            printPortStats(vmDeviceId, deviceService.getPortStatistics(deviceId), portNumbers);
        }
    });
}
Also used : PortStatistics(org.onosproject.net.device.PortStatistics) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Command(org.apache.karaf.shell.api.action.Command) TimeUnit(java.util.concurrent.TimeUnit) 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) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) DeviceId(org.onosproject.net.DeviceId) Comparator(java.util.Comparator) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) Port(org.openstack4j.model.network.Port) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) DeviceId(org.onosproject.net.DeviceId) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.openstack4j.model.network.Port) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) DeviceService(org.onosproject.net.device.DeviceService) PortNumber(org.onosproject.net.PortNumber)

Aggregations

InstancePortService (org.onosproject.openstacknetworking.api.InstancePortService)10 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)8 Service (org.apache.karaf.shell.api.action.lifecycle.Service)7 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)7 Set (java.util.Set)5 Argument (org.apache.karaf.shell.api.action.Argument)5 Command (org.apache.karaf.shell.api.action.Command)5 Collectors (java.util.stream.Collectors)4 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)4 IpAddress (org.onlab.packet.IpAddress)4 Sets (com.google.common.collect.Sets)3 List (java.util.List)3 Optional (java.util.Optional)3 Completion (org.apache.karaf.shell.api.action.Completion)3 Option (org.apache.karaf.shell.api.action.Option)3 SortedSet (java.util.SortedSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2 CommandLine (org.apache.karaf.shell.api.console.CommandLine)2 Completer (org.apache.karaf.shell.api.console.Completer)2