Search in sources :

Example 61 with CoreService

use of org.onosproject.core.CoreService in project onos by opennetworkinglab.

the class OpenstackConfigStatefulSnatCommand method purgeRules.

private void purgeRules() {
    FlowRuleService flowRuleService = get(FlowRuleService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(Constants.OPENSTACK_NETWORKING_APP_ID);
    if (appId == null) {
        error("Failed to purge OpenStack networking flow rules.");
        return;
    }
    flowRuleService.removeFlowRulesById(appId);
}
Also used : CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId)

Example 62 with CoreService

use of org.onosproject.core.CoreService in project onos by opennetworkinglab.

the class OFAgentManagerTest method setUp.

@Before
public void setUp() throws Exception {
    ofAgentStore = new DistributedOFAgentStore();
    TestUtils.setField(ofAgentStore, "coreService", createMock(CoreService.class));
    TestUtils.setField(ofAgentStore, "storageService", new TestStorageService());
    TestUtils.setField(ofAgentStore, "eventExecutor", MoreExecutors.newDirectExecutorService());
    ofAgentStore.activate();
    expect(mockCoreService.registerApplication(anyObject())).andReturn(APP_ID).anyTimes();
    replay(mockCoreService);
    expect(mockClusterService.getLocalNode()).andReturn(LOCAL_NODE).anyTimes();
    replay(mockClusterService);
    expect(mockLeadershipService.runForLeadership(anyObject())).andReturn(null).anyTimes();
    mockLeadershipService.addListener(anyObject());
    mockLeadershipService.removeListener(anyObject());
    mockLeadershipService.withdraw(anyObject());
    replay(mockLeadershipService);
    target = new OFAgentManager();
    target.coreService = mockCoreService;
    target.leadershipService = mockLeadershipService;
    target.virtualNetService = mockVirtualNetService;
    target.clusterService = mockClusterService;
    target.ofAgentStore = ofAgentStore;
    target.addListener(testListener);
    target.activate();
}
Also used : TestStorageService(org.onosproject.store.service.TestStorageService) CoreService(org.onosproject.core.CoreService) Before(org.junit.Before)

Example 63 with CoreService

use of org.onosproject.core.CoreService in project onos by opennetworkinglab.

the class OpenstackPurgeRulesCommand method doExecute.

@Override
protected void doExecute() {
    FlowRuleService flowRuleService = get(FlowRuleService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(Constants.OPENSTACK_NETWORKING_APP_ID);
    if (appId == null) {
        error("Failed to purge OpenStack networking flow rules.");
        return;
    }
    flowRuleService.removeFlowRulesById(appId);
    print("Successfully purged flow rules installed by OpenStack networking app.");
    boolean result = true;
    long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
    // we make sure all flow rules are removed from the store
    while (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() > 0) {
        long waitMs = timeoutExpiredMs - System.currentTimeMillis();
        try {
            sleep(SLEEP_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during rule purging...");
        }
        if (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() == 0) {
            break;
        } else {
            flowRuleService.removeFlowRulesById(appId);
            print("Failed to purging flow rules, retrying rule purging...");
        }
        if (waitMs <= 0) {
            result = false;
            break;
        }
    }
    if (result) {
        print("Successfully purged flow rules!");
    } else {
        error("Failed to purge flow rules.");
    }
}
Also used : CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId)

Example 64 with CoreService

use of org.onosproject.core.CoreService 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 65 with CoreService

use of org.onosproject.core.CoreService in project onos by opennetworkinglab.

the class OpticalCircuitIntentCompilerTest method setUp.

@Before
public void setUp() {
    sut = new OpticalCircuitIntentCompiler();
    coreService = createMock(CoreService.class);
    expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
    sut.coreService = coreService;
    sut.deviceService = new MockDeviceService();
    sut.resourceService = new MockResourceService();
    sut.intentService = new TestIntentService();
    sut.intentSetMultimap = new MockIntentSetMultimap();
    super.setUp();
    intentExtensionService = createMock(IntentExtensionService.class);
    intentExtensionService.registerCompiler(OpticalCircuitIntent.class, sut);
    intentExtensionService.unregisterCompiler(OpticalCircuitIntent.class);
    sut.intentManager = intentExtensionService;
    replay(coreService, intentExtensionService);
    // mocking ComponentConfigService
    ComponentConfigService mockConfigService = EasyMock.createMock(ComponentConfigService.class);
    expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
    mockConfigService.registerProperties(sut.getClass());
    expectLastCall();
    mockConfigService.unregisterProperties(sut.getClass(), false);
    expectLastCall();
    expect(mockConfigService.getProperties(anyObject())).andReturn(ImmutableSet.of());
    sut.cfgService = mockConfigService;
    replay(mockConfigService);
}
Also used : ComponentConfigService(org.onosproject.cfg.ComponentConfigService) MockResourceService(org.onosproject.net.resource.MockResourceService) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) CoreService(org.onosproject.core.CoreService) Before(org.junit.Before)

Aggregations

CoreService (org.onosproject.core.CoreService)71 Before (org.junit.Before)31 ApplicationId (org.onosproject.core.ApplicationId)30 FlowRuleService (org.onosproject.net.flow.FlowRuleService)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)12 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)12 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 DeviceId (org.onosproject.net.DeviceId)10 IntentExtensionService (org.onosproject.net.intent.IntentExtensionService)10 TestServiceDirectory (org.onlab.osgi.TestServiceDirectory)9 MockResourceService (org.onosproject.net.resource.MockResourceService)9 TestEventDispatcher (org.onosproject.common.event.impl.TestEventDispatcher)8 DistributedVirtualNetworkStore (org.onosproject.incubator.net.virtual.store.impl.DistributedVirtualNetworkStore)8 DeviceService (org.onosproject.net.device.DeviceService)8 TestStorageService (org.onosproject.store.service.TestStorageService)8 ArrayList (java.util.ArrayList)7 DomainService (org.onosproject.net.domain.DomainService)6