Search in sources :

Example 6 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project onos by opennetworkinglab.

the class BgpSpeakersListCommand method doExecute.

@Override
protected void doExecute() {
    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) {
        print("No speakers configured");
        return;
    }
    List<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Lists.newArrayList(config.bgpSpeakers());
    Collections.sort(bgpSpeakers, SPEAKERS_COMPARATOR);
    if (config.bgpSpeakers().isEmpty()) {
        print("No speakers configured");
    } else {
        bgpSpeakers.forEach(s -> {
            if (s.name().isPresent()) {
                print(NAME_FORMAT, s.name().get(), s.connectPoint().deviceId(), s.connectPoint().port(), s.vlan(), s.peers());
            } else {
                print(FORMAT, s.connectPoint().deviceId(), s.connectPoint().port(), s.vlan(), s.peers());
            }
        });
    }
}
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 7 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project onos by opennetworkinglab.

the class RemoveSpeakerCommand method doExecute.

@Override
protected void doExecute() {
    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.peers().isEmpty()) {
            // Removal not allowed when peer connections exist.
            print(PEERS_EXIST, name);
            return;
        }
    }
    removeSpeakerFromConf(config);
    configService.applyConfig(appId, BgpConfig.class, config.node());
    print(SPEAKER_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 8 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project onos by opennetworkinglab.

the class AnnotateDeviceCommand method doExecute.

@Override
protected void doExecute() {
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    DeviceId deviceId = DeviceId.deviceId(uri);
    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    DeviceAnnotationConfig cfg = netcfgService.getConfig(deviceId, DeviceAnnotationConfig.class);
    if (cfg == null) {
        cfg = new DeviceAnnotationConfig(deviceId);
    }
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    netcfgService.applyConfig(deviceId, DeviceAnnotationConfig.class, cfg.node());
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceId(org.onosproject.net.DeviceId) DeviceAnnotationConfig(org.onosproject.net.config.basics.DeviceAnnotationConfig)

Example 9 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project onos by opennetworkinglab.

the class AnnotatePortCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netcfgService = get(NetworkConfigService.class);
    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(port);
    if (deviceService.getPort(connectPoint) == null) {
        print("Port %s does not exist.", port);
        return;
    }
    if (removeCfg && key == null) {
        // remove whole port annotation config
        netcfgService.removeConfig(connectPoint, PortAnnotationConfig.class);
        print("Annotation Config about %s removed", connectPoint);
        return;
    }
    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }
    PortAnnotationConfig cfg = netcfgService.addConfig(connectPoint, PortAnnotationConfig.class);
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    cfg.apply();
}
Also used : PortAnnotationConfig(org.onosproject.net.config.basics.PortAnnotationConfig) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 10 with NetworkConfigService

use of org.onosproject.net.config.NetworkConfigService in project onos by opennetworkinglab.

the class ConfigureLinkCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netCfgService = get(NetworkConfigService.class);
    ConnectPoint srcCp = ConnectPoint.deviceConnectPoint(src);
    if (deviceService.getPort(srcCp) == null) {
        print("[ERROR] %s does not exist", srcCp);
        return;
    }
    ConnectPoint dstCp = ConnectPoint.deviceConnectPoint(dst);
    if (deviceService.getPort(dstCp) == null) {
        print("[ERROR] %s does not exist", dstCp);
        return;
    }
    LinkKey link = linkKey(srcCp, dstCp);
    if (remove) {
        netCfgService.removeConfig(link, BasicLinkConfig.class);
        return;
    }
    Long bw = Optional.ofNullable(bandwidth).map(Long::valueOf).orElse(null);
    Link.Type linkType = Link.Type.valueOf(type);
    BasicLinkConfig cfg = netCfgService.addConfig(link, BasicLinkConfig.class);
    cfg.isAllowed(!disallow);
    cfg.isBidirectional(!isUniDi);
    cfg.type(linkType);
    if (bw != null) {
        cfg.bandwidth(bw);
    }
    cfg.apply();
}
Also used : LinkKey(org.onosproject.net.LinkKey) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig)

Aggregations

NetworkConfigService (org.onosproject.net.config.NetworkConfigService)34 CoreService (org.onosproject.core.CoreService)10 DeviceId (org.onosproject.net.DeviceId)9 ApplicationId (org.onosproject.core.ApplicationId)7 ConnectPoint (org.onosproject.net.ConnectPoint)6 DeviceService (org.onosproject.net.device.DeviceService)6 BgpConfig (org.onosproject.routing.config.BgpConfig)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayList (java.util.ArrayList)3 Path (javax.ws.rs.Path)3 Before (org.junit.Before)3 NetworkConfigListener (org.onosproject.net.config.NetworkConfigListener)3 SubjectFactory (org.onosproject.net.config.SubjectFactory)3 BasicDeviceConfig (org.onosproject.net.config.basics.BasicDeviceConfig)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 GET (javax.ws.rs.GET)2