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);
}
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);
}
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);
}
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.");
}
}
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();
}
Aggregations