Java Code Examples for org.onosproject.net.config.NetworkConfigService#getConfig()
The following examples show how to use
org.onosproject.net.config.NetworkConfigService#getConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotateDeviceCommand.java From onos with Apache License 2.0 | 6 votes |
@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()); }
Example 2
Source File: AnnotateHostCommand.java From onos with Apache License 2.0 | 6 votes |
@Override protected void doExecute() { NetworkConfigService netcfgService = get(NetworkConfigService.class); HostId hostId = HostId.hostId(uri); if (key == null) { print("[ERROR] Annotation key not specified."); return; } HostAnnotationConfig cfg = netcfgService.getConfig(hostId, HostAnnotationConfig.class); if (cfg == null) { cfg = new HostAnnotationConfig(hostId); } if (removeCfg) { // remove config about entry cfg.annotation(key); } else { // add request config cfg.annotation(key, value); } netcfgService.applyConfig(hostId, HostAnnotationConfig.class, cfg.node()); }
Example 3
Source File: CostConstraint.java From onos with Apache License 2.0 | 6 votes |
/** * Validates the link based on cost type specified. * * @param link to validate cost type constraint * @param netCfgService instance of netCfgService * @return true if link satisfies cost constraint otherwise false */ public double isValidLink(Link link, NetworkConfigService netCfgService) { if (netCfgService == null) { return -1; } TeLinkConfig cfg = netCfgService.getConfig(LinkKey.linkKey(link.src(), link.dst()), TeLinkConfig.class); if (cfg == null) { //If cost configuration absent return -1[It is not L3 device] return -1; } switch (type) { case COST: //If IGP cost is zero then IGP cost is not assigned for that link return cfg.igpCost() == 0 ? -1 : cfg.igpCost(); case TE_COST: //If TE cost is zero then TE cost is not assigned for that link return cfg.teCost() == 0 ? -1 : cfg.teCost(); default: return -1; } }
Example 4
Source File: RoutingConfiguration.java From onos with Apache License 2.0 | 6 votes |
/** * Retrieves the router configurations. * * @param configService network config service * @param routingAppId routing app ID * @return set of router configurations */ public static Set<RoutersConfig.Router> getRouterConfigurations( NetworkConfigService configService, ApplicationId routingAppId) { RouterConfig config = configService.getConfig( routingAppId, RoutingService.ROUTER_CONFIG_CLASS); RoutersConfig multiConfig = configService.getConfig(routingAppId, RoutersConfig.class); if (config != null) { log.warn(WARNING); log.warn(WARNING2); return Collections.singleton( new RoutersConfig.Router(config.getControlPlaneConnectPoint(), config.getOspfEnabled(), Sets.newHashSet(config.getInterfaces()))); } else if (multiConfig != null) { return multiConfig.getRouters(); } else { return Collections.emptySet(); } }
Example 5
Source File: ConfigLambdaQuery.java From onos with Apache License 2.0 | 5 votes |
@Override public Set<OchSignal> queryLambdas(PortNumber port) { NetworkConfigService netcfg = handler().get(NetworkConfigService.class); ConnectPoint cp = new ConnectPoint(data().deviceId(), port); LambdaConfig cfg = netcfg.getConfig(cp, LambdaConfig.class); if (cfg == null) { return ImmutableSet.of(); } GridType type = cfg.gridType(); Optional<ChannelSpacing> dwdmSpacing = cfg.dwdmSpacing(); int start = cfg.slotStart(); int step = cfg.slotStep(); int end = cfg.slotEnd(); Set<OchSignal> lambdas = new LinkedHashSet<>(); for (int i = start; i <= end; i += step) { switch (type) { case DWDM: lambdas.add(OchSignal.newDwdmSlot(dwdmSpacing.get(), i)); break; case FLEX: lambdas.add(OchSignal.newFlexGridSlot(i)); break; case CWDM: default: log.warn("Unsupported grid type: {}", type); break; } } return lambdas; }
Example 6
Source File: RegionAddPeerLocCommand.java From onos with Apache License 2.0 | 5 votes |
@Override protected void doExecute() { RegionId regionId = RegionId.regionId(id); NetworkConfigService cfgService = get(NetworkConfigService.class); BasicRegionConfig cfg = cfgService.getConfig(regionId, BasicRegionConfig.class); cfg.addPeerLocMapping(peerId, locType, latOrY, longOrX) .apply(); }
Example 7
Source File: AddPeerCommand.java From onos with Apache License 2.0 | 5 votes |
@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)) { return; // Peering already exists. } } 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); }
Example 8
Source File: RemovePeerCommand.java From onos with Apache License 2.0 | 5 votes |
@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); }
Example 9
Source File: BgpSpeakersListCommand.java From onos with Apache License 2.0 | 5 votes |
@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()); } }); } }
Example 10
Source File: RemoveSpeakerCommand.java From onos with Apache License 2.0 | 5 votes |
@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); }
Example 11
Source File: CapabilityConstraint.java From onos with Apache License 2.0 | 5 votes |
/** * Validates the link based on capability constraint. * * @param link to validate source and destination based on capability constraint * @param deviceService instance of DeviceService * @param netCfgService instance of NetworkConfigService * @return true if link satisfies capability constraint otherwise false */ public boolean isValidLink(Link link, DeviceService deviceService, NetworkConfigService netCfgService) { if (deviceService == null || netCfgService == null) { return false; } Device srcDevice = deviceService.getDevice(link.src().deviceId()); Device dstDevice = deviceService.getDevice(link.dst().deviceId()); //TODO: Usage of annotations are for transient solution. In future will be replaced with the // network config service / Projection model. // L3 device if (srcDevice == null || dstDevice == null) { return false; } String srcLsrId = srcDevice.annotations().value(LSRID); String dstLsrId = dstDevice.annotations().value(LSRID); DeviceCapability srcDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(srcLsrId), DeviceCapability.class); DeviceCapability dstDeviceConfig = netCfgService.getConfig(DeviceId.deviceId(dstLsrId), DeviceCapability.class); switch (capabilityType) { case WITH_SIGNALLING: return true; case WITHOUT_SIGNALLING_AND_WITHOUT_SR: return srcDeviceConfig != null && dstDeviceConfig != null && srcDeviceConfig.localLabelCap() && dstDeviceConfig.localLabelCap(); case SR_WITHOUT_SIGNALLING: return srcDeviceConfig != null && dstDeviceConfig != null && srcDeviceConfig.srCap() && dstDeviceConfig.srCap() && srcDeviceConfig.labelStackCap() && dstDeviceConfig.labelStackCap(); default: return false; } }
Example 12
Source File: BlackHoleCommand.java From onos with Apache License 2.0 | 5 votes |
@Override protected void doExecute() { SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class); NetworkConfigService netcfgService = AbstractShellCommand.get(NetworkConfigService.class); SegmentRoutingAppConfig appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class); if (appConfig == null) { JsonNode jsonNode = new ObjectMapper().createObjectNode(); netcfgService.applyConfig(srService.appId(), SegmentRoutingAppConfig.class, jsonNode); appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class); } Set<IpPrefix> blackHoleIps; switch (op) { case "list": appConfig.blackholeIPs().forEach(prefix -> print(prefix.toString())); break; case "add": blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs()); blackHoleIps.add(IpPrefix.valueOf(prefix)); appConfig.setBalckholeIps(blackHoleIps); break; case "remove": blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs()); blackHoleIps.remove(IpPrefix.valueOf(prefix)); appConfig.setBalckholeIps(blackHoleIps); break; default: throw new UnsupportedOperationException("Unknown operation " + op); } }