Search in sources :

Example 66 with CoreService

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

the class OpticalIntentsWebResource method decode.

private Intent decode(ObjectNode json) {
    JsonNode ingressJson = json.get(INGRESS_POINT);
    if (!ingressJson.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }
    ConnectPoint ingress = codec(ConnectPoint.class).decode((ObjectNode) ingressJson, this);
    JsonNode egressJson = json.get(EGRESS_POINT);
    if (!egressJson.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }
    ConnectPoint egress = codec(ConnectPoint.class).decode((ObjectNode) egressJson, this);
    JsonNode bidirectionalJson = json.get(BIDIRECTIONAL);
    boolean bidirectional = bidirectionalJson != null ? bidirectionalJson.asBoolean() : false;
    JsonNode signalJson = json.get(SIGNAL);
    OchSignal signal = null;
    if (signalJson != null) {
        if (!signalJson.isObject()) {
            throw new IllegalArgumentException(JSON_INVALID);
        } else {
            signal = OchSignalCodec.decode((ObjectNode) signalJson);
        }
    }
    String appIdString = nullIsIllegal(json.get(APP_ID), APP_ID + MISSING_MEMBER_MESSAGE).asText();
    CoreService service = getService(CoreService.class);
    ApplicationId appId = nullIsNotFound(service.getAppId(appIdString), E_APP_ID_NOT_FOUND);
    Key key = null;
    DeviceService deviceService = get(DeviceService.class);
    JsonNode suggestedPathJson = json.get(SUGGESTEDPATH);
    DefaultPath suggestedPath = null;
    LinkService linkService = get(LinkService.class);
    if (suggestedPathJson != null) {
        if (!suggestedPathJson.isObject()) {
            throw new IllegalArgumentException(JSON_INVALID);
        } else {
            ArrayNode linksJson = nullIsIllegal((ArrayNode) suggestedPathJson.get("links"), "Suggested path specified without links");
            List<Link> listLinks = new ArrayList<>();
            for (JsonNode node : linksJson) {
                String srcString = node.get("src").asText();
                String dstString = node.get("dst").asText();
                ConnectPoint srcConnectPoint = ConnectPoint.fromString(srcString);
                ConnectPoint dstConnectPoint = ConnectPoint.fromString(dstString);
                Link link = linkService.getLink(srcConnectPoint, dstConnectPoint);
                if (link == null) {
                    throw new IllegalArgumentException("Not existing link in the suggested path");
                }
                listLinks.add(link);
            }
            if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId())) || (!listLinks.get(0).src().port().equals(ingress.port())) || (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId())) || (!listLinks.get(listLinks.size() - 1).dst().port().equals(egress.port()))) {
                throw new IllegalArgumentException("Suggested path not compatible with ingress or egress connect points");
            }
            if (!isPathContiguous(listLinks)) {
                throw new IllegalArgumentException("Links specified in the suggested path are not contiguous");
            }
            suggestedPath = new DefaultPath(PROVIDER_ID, listLinks, new ScalarWeight(1));
            log.debug("OpticalIntent along suggestedPath {}", suggestedPath);
        }
    }
    return createExplicitOpticalIntent(ingress, egress, deviceService, key, appId, bidirectional, signal, suggestedPath);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) OchSignal(org.onosproject.net.OchSignal) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint) ScalarWeight(org.onlab.graph.ScalarWeight) DefaultPath(org.onosproject.net.DefaultPath) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ApplicationId(org.onosproject.core.ApplicationId) LinkService(org.onosproject.net.link.LinkService) Key(org.onosproject.net.intent.Key) Link(org.onosproject.net.Link)

Example 67 with CoreService

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

the class AddPeerCommand method doExecute.

@Override
protected void doExecute() {
    peerAddress = IpAddress.valueOf(ip);
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }
    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name);
    if (speaker == null) {
        print(SPEAKER_NOT_FOUND, name);
        return;
    } else {
        if (speaker.isConnectedToPeer(peerAddress)) {
            // Peering already exists.
            return;
        }
    }
    InterfaceService interfaceService = get(InterfaceService.class);
    if (interfaceService.getMatchingInterface(peerAddress) == null) {
        print(NO_INTERFACE, ip);
        return;
    }
    addPeerToSpeakerConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());
    print(PEER_ADD_SUCCESS);
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) InterfaceService(org.onosproject.net.intf.InterfaceService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 68 with CoreService

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

the class RemovePeerCommand method doExecute.

@Override
protected void doExecute() {
    peerAddress = IpAddress.valueOf(ip);
    NetworkConfigService configService = get(NetworkConfigService.class);
    CoreService coreService = get(CoreService.class);
    ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
    BgpConfig config = configService.getConfig(appId, BgpConfig.class);
    if (config == null || config.bgpSpeakers().isEmpty()) {
        print(NO_CONFIGURATION);
        return;
    }
    peerAddress = IpAddress.valueOf(ip);
    BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerFromPeer(peerAddress);
    if (speaker == null) {
        print(PEER_NOT_FOUND, ip);
        return;
    }
    removePeerFromSpeakerConf(speaker, config);
    configService.applyConfig(appId, BgpConfig.class, config.node());
    print(PEER_REMOVE_SUCCESS);
}
Also used : BgpConfig(org.onosproject.routing.config.BgpConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) CoreService(org.onosproject.core.CoreService) ApplicationId(org.onosproject.core.ApplicationId)

Example 69 with CoreService

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

the class K8sPurgeRulesCommand method doExecute.

@Override
protected void doExecute() {
    FlowRuleService flowRuleService = get(FlowRuleService.class);
    GroupService groupService = get(GroupService.class);
    CoreService coreService = get(CoreService.class);
    K8sNodeService k8sNodeService = get(K8sNodeService.class);
    ApplicationId appId = coreService.getAppId(K8S_NETWORKING_APP_ID);
    if (appId == null) {
        error("Failed to purge kubernetes networking flow rules.");
        return;
    }
    flowRuleService.removeFlowRulesById(appId);
    print("Successfully purged flow rules installed by kubernetes 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;
        }
    }
    for (K8sNode node : k8sNodeService.completeNodes()) {
        for (Group group : groupService.getGroups(node.intgBridge(), appId)) {
            groupService.removeGroup(node.intgBridge(), group.appCookie(), appId);
        }
    }
    if (result) {
        print("Successfully purged flow rules!");
    } else {
        error("Failed to purge flow rules.");
    }
}
Also used : Group(org.onosproject.net.group.Group) K8sNode(org.onosproject.k8snode.api.K8sNode) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) GroupService(org.onosproject.net.group.GroupService)

Example 70 with CoreService

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

the class TestCodecService method setup.

@Before
public void setup() throws IOException {
    storageService = new TestStorageService();
    mastershipService = createNiceMock(MastershipService.class);
    coreService = createNiceMock(CoreService.class);
    hostService = createNiceMock(HostService.class);
    deviceService = createNiceMock(DeviceService.class);
    expect(deviceService.getDevices()).andReturn(ImmutableList.of()).anyTimes();
    networkConfigRegistry = createNiceMock(NetworkConfigRegistry.class);
    networkConfigService = createNiceMock(NetworkConfigService.class);
    manager = new SimpleIntManager();
    manager.coreService = coreService;
    manager.deviceService = deviceService;
    manager.storageService = storageService;
    manager.mastershipService = mastershipService;
    manager.hostService = hostService;
    manager.netcfgService = networkConfigService;
    manager.netcfgRegistry = networkConfigRegistry;
    manager.eventExecutor = MoreExecutors.newDirectExecutorService();
    manager.codecService = codecService;
    expect(coreService.registerApplication(APP_NAME)).andReturn(APP_ID).anyTimes();
    networkConfigRegistry.registerConfigFactory(anyObject());
    expectLastCall().once();
    Capture<NetworkConfigListener> capture = newCapture();
    networkConfigService.addListener(EasyMock.capture(capture));
    expectLastCall().once();
    IntReportConfig config = getIntReportConfig("/report-config.json");
    expect(networkConfigService.getConfig(APP_ID, IntReportConfig.class)).andReturn(config).anyTimes();
    replay(mastershipService, deviceService, coreService, hostService, networkConfigRegistry, networkConfigService);
    manager.activate();
    networkConfigListener = capture.getValue();
}
Also used : HostService(org.onosproject.net.host.HostService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) TestStorageService(org.onosproject.store.service.TestStorageService) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) MastershipService(org.onosproject.mastership.MastershipService) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) 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