Search in sources :

Example 1 with InstancePortAdminService

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

the class PreCommitPortManagerTest method testUnsubscribePreCommit.

/**
 * Tests unsubscribe pre-commit method.
 */
@Test
public void testUnsubscribePreCommit() {
    sampleSubscribe();
    InstancePortAdminService service = new TestInstancePortAdminService();
    target.unsubscribePreCommit(PORT_ID_1, OPENSTACK_PORT_PRE_REMOVE, service, CLASS_NAME_1);
    target.unsubscribePreCommit(PORT_ID_2, OPENSTACK_PORT_PRE_REMOVE, service, CLASS_NAME_2);
    assertEquals(0, target.subscriberCountByEventType(PORT_ID_1, OPENSTACK_PORT_PRE_REMOVE));
    assertEquals(1, target.subscriberCountByEventType(PORT_ID_2, OPENSTACK_PORT_PRE_REMOVE));
    assertEquals(0, target.subscriberCount(PORT_ID_1));
    assertEquals(2, target.subscriberCount(PORT_ID_2));
}
Also used : InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) Test(org.junit.Test)

Example 2 with InstancePortAdminService

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

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

the class OpenstackResetPortsCommand method doExecute.

@Override
protected void doExecute() {
    InstancePortAdminService service = get(InstancePortAdminService.class);
    if ((!isAll && !isInactive && portIds == null) || (isAll && isInactive) || (isInactive && portIds != null) || (portIds != null && isAll)) {
        print("Please specify one of portIds, --all, and --inactive options.");
        return;
    }
    if (isAll) {
        portIds = service.instancePorts().stream().map(InstancePort::portId).toArray(String[]::new);
    } else if (isInactive) {
        portIds = service.instancePorts().stream().filter(p -> p.state() == INACTIVE).map(InstancePort::portId).toArray(String[]::new);
    }
    for (String portId : portIds) {
        resetPort(service, portId);
        print("Successfully requested re-installing flow rules for port %s!", portId);
    }
    print("Done.");
}
Also used : InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Example 4 with InstancePortAdminService

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

the class PurgeInstancePortsCommand method doExecute.

@Override
protected void doExecute() {
    InstancePortAdminService service = get(InstancePortAdminService.class);
    if ((!isAll && !isInactive && !isPending && portIds == null) || (isAll && isInactive && isPending) || (isInactive && isPending && portIds != null) || (portIds != null && isAll && isPending) || (isAll && isInactive && portIds != null)) {
        print("Please specify one of portIds, --all or --inactive or --pending options.");
        return;
    }
    if (isAll) {
        portIds = service.instancePorts().stream().map(InstancePort::portId).toArray(String[]::new);
    } else if (isInactive) {
        portIds = service.instancePorts().stream().filter(p -> p.state() == INACTIVE).map(InstancePort::portId).toArray(String[]::new);
    } else if (isPending) {
        portIds = service.instancePorts().stream().filter(p -> p.state() == REMOVE_PENDING).map(InstancePort::portId).toArray(String[]::new);
    }
    for (String portId : portIds) {
        service.removeInstancePort(portId);
        print("Instance port %s has been removed!", portId);
    }
    print("Done.");
}
Also used : AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) REMOVE_PENDING(org.onosproject.openstacknetworking.api.InstancePort.State.REMOVE_PENDING) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Service(org.apache.karaf.shell.api.action.lifecycle.Service) INACTIVE(org.onosproject.openstacknetworking.api.InstancePort.State.INACTIVE) Argument(org.apache.karaf.shell.api.action.Argument) Completion(org.apache.karaf.shell.api.action.Completion) Option(org.apache.karaf.shell.api.action.Option) Command(org.apache.karaf.shell.api.action.Command) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Aggregations

InstancePortAdminService (org.onosproject.openstacknetworking.api.InstancePortAdminService)4 InstancePort (org.onosproject.openstacknetworking.api.InstancePort)3 Argument (org.apache.karaf.shell.api.action.Argument)2 Command (org.apache.karaf.shell.api.action.Command)2 Completion (org.apache.karaf.shell.api.action.Completion)2 Service (org.apache.karaf.shell.api.action.lifecycle.Service)2 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)2 Optional (java.util.Optional)1 Option (org.apache.karaf.shell.api.action.Option)1 Test (org.junit.Test)1 AbstractShellCommand.get (org.onosproject.cli.AbstractShellCommand.get)1 INACTIVE (org.onosproject.openstacknetworking.api.InstancePort.State.INACTIVE)1 REMOVE_PENDING (org.onosproject.openstacknetworking.api.InstancePort.State.REMOVE_PENDING)1 OpenstackNetworkAdminService (org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService)1 OpenstackNetworkingUtil.sendTraceRequestToNode (org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.sendTraceRequestToNode)1 OpenstackNetworkingUtil.traceRequestString (org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.traceRequestString)1 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)1 OpenstackNodeAdminService (org.onosproject.openstacknode.api.OpenstackNodeAdminService)1