Manikandan K
Committed by Gerrit Code Review

ONOS-4361 OSPF Provider

Change-Id: I8260940baac93b48862aff390a3d8e276461842d
BUNDLES = [
'//protocols/ospf/api:onos-protocols-ospf-api',
'//protocols/ospf/ctl:onos-protocols-ospf-ctl',
'//protocols/ospf/protocol:onos-protocols-ospf-protocol',
'//providers/ospf/cfg:onos-providers-ospf-cfg',
'//providers/ospf/topology:onos-providers-ospf-topology',
]
onos_app (
title = 'OSPF Provider',
category = 'Provider',
url = 'http://onosproject.org',
description = 'ONOS OSPF protocol adapters.',
included_bundles = BUNDLES,
)
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<app name="org.onosproject.ospf" origin="ON.Lab" version="${project.version}"
featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
features="${project.artifactId}">
<description>${project.description}</description>
<artifact>mvn:${project.groupId}/onos-ospf-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-ospf-ctl/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-ospf-provider-topology/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-ospf-provider-cfg/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-ospf-provider-cli/${project.version}</artifact>
</app>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
<feature name="${project.artifactId}" version="${project.version}"
description="${project.description}">
<feature>onos-api</feature>
<bundle>mvn:${project.groupId}/onos-ospf-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-ospf-ctl/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-ospf-provider-topology/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-ospf-provider-cfg/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-ospf-provider-cli/${project.version}</bundle>
</feature>
</features>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-providers</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-ospf-app</artifactId>
<packaging>pom</packaging>
<description>OSPF protocol southbound providers</description>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-ctl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-provider-topology</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-provider-cfg</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-provider-cli</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//protocols/ospf/api:onos-protocols-ospf-api',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
)
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-providers</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-ospf-provider-cfg</artifactId>
<packaging>bundle</packaging>
<description>ONOS OSPF Providers</description>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-ctl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.ospf.cfg.impl;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.osgi.DefaultServiceDirectory;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.Config;
import org.onosproject.ospf.controller.OspfController;
/**
* Configuration object for OSPF.
*/
public class OspfAppConfig extends Config<ApplicationId> {
public static final String METHOD = "method";
public static final String ATTRIBUTE = "attribute";
public static final String PROCESSES = "processes";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private OspfController ospfController;
/**
* Returns the configuration method, add, delete etc.
*
* @return the configuration method, add, delete etc
*/
public String method() {
return get(METHOD, null);
}
/**
* Returns the configuration attribute, area, process etc.
*
* @return the configuration attribute, area, process etc
*/
public String attribute() {
return get(ATTRIBUTE, null);
}
/**
* Returns the configured processes.
*
* @return the configured processes
*/
public JsonNode processes() {
JsonNode jsonNodes = object.get(PROCESSES);
return jsonNodes;
}
@Override
public boolean isValid() {
this.ospfController = DefaultServiceDirectory.getService(OspfController.class);
return true;
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.ospf.cfg.impl;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.config.basics.SubjectFactories;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.ospf.controller.OspfController;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which advertises device descriptions to the core.
*/
@Component(immediate = true)
@Service
public class OspfCfgProvider extends AbstractProvider {
static final String PROVIDER_ID = "org.onosproject.provider.ospf.cfg";
private static final Logger log = getLogger(OspfCfgProvider.class);
private final ConfigFactory configFactory =
new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, OspfAppConfig.class, "ospfapp") {
@Override
public OspfAppConfig createConfig() {
return new OspfAppConfig();
}
};
private final NetworkConfigListener configListener = new InternalConfigListener();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OspfController ospfController;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigRegistry configRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigService configService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OspfController controller;
private ApplicationId appId;
/**
* Creates an OSPF device provider.
*/
public OspfCfgProvider() {
super(new ProviderId("ospf", PROVIDER_ID));
}
public void setOspfController(OspfController ospfController) {
this.ospfController = ospfController;
}
@Activate
public void activate() {
appId = coreService.registerApplication(PROVIDER_ID);
configService.addListener(configListener);
configRegistry.registerConfigFactory(configFactory);
log.info("activated...!!!");
}
@Deactivate
public void deactivate() {
configRegistry.unregisterConfigFactory(configFactory);
configService.removeListener(configListener);
log.info("deactivated...!!!");
}
private void updateConfig() {
OspfAppConfig ospfAppConfig = configRegistry.getConfig(appId, OspfAppConfig.class);
if ("ADD".equalsIgnoreCase(ospfAppConfig.method())) {
JsonNode jsonNode = ospfAppConfig.processes();
ospfController.updateConfig(jsonNode);
} else {
log.debug("Please signify prop1 and prop2");
}
}
/**
* OSPF config listener to populate the configuration.
*/
private class InternalConfigListener implements NetworkConfigListener {
@Override
public void event(NetworkConfigEvent event) {
log.debug("InternalConfigListener:: event is getting called");
if (!event.configClass().equals(OspfAppConfig.class)) {
return;
}
switch (event.type()) {
case CONFIG_ADDED:
updateConfig();
break;
case CONFIG_UPDATED:
updateConfig();
break;
case CONFIG_REMOVED:
break;
default:
break;
}
}
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provider that uses OSPF capability request as a means of infrastructure device discovery.
*/
package org.onosproject.provider.ospf.cfg.impl;
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-providers</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-ospf-provider-cli</artifactId>
<packaging>bundle</packaging>
<description>OSPF cli implementation</description>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-cli</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-ctl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-protocol</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.apache.karaf.shell</groupId>
<artifactId>org.apache.karaf.shell.console</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.cli;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.ospf.controller.OspfArea;
import org.onosproject.ospf.controller.OspfController;
import org.onosproject.ospf.controller.OspfInterface;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.controller.OspfNbr;
import org.onosproject.ospf.controller.OspfProcess;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Representation of OSPF cli commands.
*/
@Component(immediate = true)
@Command(scope = "onos", name = "ospf", description = "list database")
public class ApplicationOspfCommand extends AbstractShellCommand {
protected static final String FORMAT6 = "%-20s%-20s%-20s%-20s%-20s%-20s\n";
protected static final String FORMAT5 = "%-20s%-20s%-20s%-20s%-20s\n";
protected static final String NETWORK = "NETWORK";
protected static final String SUMMARY = "SUMMARY";
protected static final String ASBR = "ABSR";
protected static final String EXTERNAL = "EXTERNAL";
protected static final String LINKLOOPAQ = "LINKLOCALOPAQUE";
protected static final String AREALOCOPAQ = "AREALOCALOPAQUE";
protected static final String ASOPAQ = "ASOPAQUE";
protected static final String DR = "DR";
protected static final String BACKUP = "BACKUP";
protected static final String DROTHER = "DROther";
static final String DATABASE = "database";
static final String NEIGHBORLIST = "neighbors";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OspfController ospfController;
@Argument(index = 0, name = "name",
description = "database|neighborlist",
required = true, multiValued = false)
private String name = null;
@Argument(index = 1, name = "processid",
description = "processId",
required = true, multiValued = false)
private String process = null;
@Argument(index = 2, name = "areaid",
description = "areaId",
required = false, multiValued = false)
private String area = null;
private List<String> routerLsa = new ArrayList<>();
private List<String> networkLsa = new ArrayList<>();
private List<String> summaryLsa = new ArrayList<>();
private List<String> externalLsa = new ArrayList<>();
private List<String> asbrSumm = new ArrayList<>();
private List<String> areaLocalOpaqLsa = new ArrayList<>();
private List<String> linkLocalOpqLsa = new ArrayList<>();
private List<String> asOpqLsa = new ArrayList<>();
private List<String> undefinedLsa = new ArrayList<>();
private List<OspfArea> areaList = new ArrayList<>();
@Activate
public void activate() {
print("OSPF cli activated...!!!");
log.debug("OSPF cli activated...!!!");
}
@Deactivate
public void deactivate() {
log.debug("OSPF cli deactivated...!!!");
}
@Override
protected void execute() {
if (DATABASE.equals(name)) {
buildOspfDatabaseInformation();
} else if (NEIGHBORLIST.equals(name)) {
buildNeighborInformation();
} else {
print("Please check the command (database|neighbor)");
}
}
/**
* Clears all the lists.
*/
private void clearLists() {
routerLsa.clear();
networkLsa.clear();
summaryLsa.clear();
externalLsa.clear();
asbrSumm.clear();
areaLocalOpaqLsa.clear();
linkLocalOpqLsa.clear();
asOpqLsa.clear();
undefinedLsa.clear();
areaList.clear();
}
/**
* Builds OSPF database information.
*/
private void buildOspfDatabaseInformation() {
try {
//Builds LSA details
buildLsaLists();
for (OspfArea area : areaList) {
if (routerLsa.size() > 0) {
printRouterFormat(area.areaId().toString(), area.routerId().toString(), process);
for (String str : routerLsa) {
String[] lsaVal = str.split("\\,");
if (area.areaId().toString().equalsIgnoreCase(lsaVal[0])) {
print(FORMAT6, lsaVal[2], lsaVal[3], lsaVal[4], lsaVal[5], lsaVal[6], lsaVal[7]);
}
}
}
if (networkLsa.size() > 0) {
printNetworkFormat(area.areaId().toString(), NETWORK);
printDetails(networkLsa, area.areaId().toString());
}
if (summaryLsa.size() > 0) {
printNetworkFormat(area.areaId().toString(), SUMMARY);
printDetails(summaryLsa, area.areaId().toString());
}
if (externalLsa.size() > 0) {
printNetworkFormat(area.areaId().toString(), EXTERNAL);
printDetails(externalLsa, area.areaId().toString());
}
if (asbrSumm.size() > 0) {
printNetworkFormat(area.areaId().toString(), ASBR);
printDetails(asbrSumm, area.areaId().toString());
}
if (areaLocalOpaqLsa.size() > 0) {
printNetworkFormat(area.areaId().toString(), AREALOCOPAQ);
printDetails(areaLocalOpaqLsa, area.areaId().toString());
}
if (linkLocalOpqLsa.size() > 0) {
printNetworkFormat(area.areaId().toString(), LINKLOOPAQ);
printDetails(linkLocalOpqLsa, area.areaId().toString());
}
if (asOpqLsa.size() > 0) {
printNetworkFormat(area.areaId().toString(), ASOPAQ);
printDetails(asOpqLsa, area.areaId().toString());
}
if (undefinedLsa.size() > 0) {
printRouterFormat(area.areaId().toString(), area.routerId().toString(), process);
printDetails(undefinedLsa, area.areaId().toString());
}
}
clearLists();
} catch (Exception ex) {
clearLists();
print("Error occured while Ospf controller getting called" + ex.getMessage());
}
}
/**
* Prints LSA details.
*
* @param lsaDetails LSA details
* @param areaId area ID
*/
private void printDetails(List<String> lsaDetails, String areaId) {
for (String str : lsaDetails) {
String[] lsaVal = str.split("\\,");
if (areaId.equalsIgnoreCase(lsaVal[0])) {
print(FORMAT5, lsaVal[2], lsaVal[3], lsaVal[4], lsaVal[5], lsaVal[6]);
}
}
}
/**
* Builds all LSA lists with LSA details.
*/
private void buildLsaLists() {
this.ospfController = get(OspfController.class);
List<OspfProcess> listOfProcess = ospfController.getAllConfiguredProcesses();
Iterator<OspfProcess> itrProcess = listOfProcess.iterator();
while (itrProcess.hasNext()) {
OspfProcess ospfProcess = itrProcess.next();
if (process.equalsIgnoreCase(ospfProcess.processId())) {
List<OspfArea> listAreas = ospfProcess.areas();
Iterator<OspfArea> itrArea = listAreas.iterator();
while (itrArea.hasNext()) {
OspfArea area = itrArea.next();
List<LsaHeader> lsas = area.database()
.getAllLsaHeaders(false, area.isOpaqueEnabled());
List<LsaHeader> tmpLsaList = new ArrayList<>(lsas);
log.debug("OSPFController::size of database::" + (lsas != null ? lsas.size() : null));
Iterator<LsaHeader> itrLsaHeader = tmpLsaList.iterator();
areaList.add(area);
if (itrLsaHeader != null) {
while (itrLsaHeader.hasNext()) {
LsaHeader header = itrLsaHeader.next();
populateLsaLists(header, area);
}
}
}
}
}
}
/**
* Populates the LSA lists based on the input.
*
* @param header LSA header instance
* @param area OSPF area instance
*/
private void populateLsaLists(LsaHeader header, OspfArea area) {
String seqNo = Long.toHexString(header.lsSequenceNo());
String checkSum = Long.toHexString(header.lsCheckSum());
if (seqNo.length() == 16) {
seqNo = seqNo.substring(8, seqNo.length());
}
if (checkSum.length() == 16) {
checkSum = checkSum.substring(8, checkSum.length());
}
StringBuffer strBuf = getBuffList(area.areaId().toString(), area.routerId().toString(),
header.linkStateId(),
header.advertisingRouter().toString(),
header.age(), seqNo, checkSum);
if (header.lsType() == OspfLsaType.ROUTER.value()) {
strBuf.append(",");
strBuf.append(((RouterLsa) header).noLink());
routerLsa.add(strBuf.toString());
} else if (header.lsType() == OspfLsaType.NETWORK.value()) {
strBuf.append(",");
strBuf.append("0");
networkLsa.add(strBuf.toString());
} else if (header.lsType() == OspfLsaType.SUMMARY.value()) {
strBuf.append(",");
strBuf.append("0");
summaryLsa.add(strBuf.toString());
} else if (header.lsType() == OspfLsaType.EXTERNAL_LSA.value()) {
strBuf.append(",");
strBuf.append("0");
externalLsa.add(strBuf.toString());
} else if (header.lsType() == OspfLsaType.ASBR_SUMMARY.value()) {
strBuf.append(",");
strBuf.append("0");
asbrSumm.add(strBuf.toString());
} else if (header.lsType() == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) {
strBuf.append(",");
strBuf.append("0");
areaLocalOpaqLsa.add(strBuf.toString());
} else if (header.lsType() == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) {
strBuf.append(",");
strBuf.append("0");
linkLocalOpqLsa.add(strBuf.toString());
} else if (header.lsType() == OspfLsaType.AS_OPAQUE_LSA.value()) {
strBuf.append(",");
strBuf.append("0");
asOpqLsa.add(strBuf.toString());
} else {
strBuf.append(",");
strBuf.append("0");
undefinedLsa.add(strBuf.toString());
}
}
/**
* Builds OSPF neighbor information.
*/
private void buildNeighborInformation() {
try {
this.ospfController = get(OspfController.class);
List<OspfProcess> listOfProcess = ospfController.getAllConfiguredProcesses();
boolean flag = false;
printNeighborsFormat();
Iterator<OspfProcess> itrProcess = listOfProcess.iterator();
while (itrProcess.hasNext()) {
OspfProcess process = itrProcess.next();
List<OspfArea> listAreas = process.areas();
Iterator<OspfArea> itrArea = listAreas.iterator();
while (itrArea.hasNext()) {
OspfArea area = itrArea.next();
List<OspfInterface> itrefaceList = area.ospfInterfaceList();
for (OspfInterface interfc : itrefaceList) {
List<OspfNbr> nghbrList = new ArrayList<>(interfc.listOfNeighbors().values());
for (OspfNbr neigbor : nghbrList) {
print("%-20s%-20s%-20s%-20s%-20s\n", neigbor.neighborId(), neigbor.routerPriority(),
neigbor.getState() + "/" + checkDrBdrOther(neigbor.neighborIpAddr().toString(),
neigbor.neighborDr().toString(),
neigbor.neighborBdr().toString()),
neigbor.neighborIpAddr().toString(), interfc.ipAddress());
}
}
}
}
} catch (Exception ex) {
print("Error occured while Ospf controller getting called" + ex.getMessage());
}
}
/**
* Prints input after formatting.
*
* @param areaId area ID
* @param routerId router ID
* @param processId process ID
*/
private void printRouterFormat(String areaId, String routerId, String processId) {
print("%s (%s) %s %s\n", "OSPF Router with ID", routerId, "Process Id", processId);
print("%s ( Area %s)\n", "Router Link States", areaId);
print("%-20s%-20s%-20s%-20s%-20s%-20s\n", "Link Id", "ADV Router", "Age", "Seq#",
"CkSum", "Link Count");
}
/**
* Prints input after formatting.
*
* @param areaId area ID
* @param type network type
*/
private void printNetworkFormat(String areaId, String type) {
print("%s %s ( Area %s)\n", type, "Link States", areaId);
print("%-20s%-20s%-20s%-20s%-20s\n", "Link Id", "ADV Router", "Age", "Seq#", "CkSum");
}
/**
* Prints input after formatting.
*/
private void printNeighborsFormat() {
print("%-20s%-20s%-20s%-20s%-20s\n", "Neighbor Id", "Pri", "State",
"Address", "Interface");
}
/**
* Checks whether the neighbor is DR or BDR.
*
* @param ip IP address to check
* @param drIP DRs IP address
* @param bdrIp BDRs IP address
* @return 1- neighbor is DR, 2- neighbor is BDR, 3- DROTHER
*/
public String checkDrBdrOther(String ip, String drIP, String bdrIp) {
if (ip.equalsIgnoreCase(drIP)) {
return DR;
} else if (ip.equalsIgnoreCase(bdrIp)) {
return BACKUP;
} else {
return DROTHER;
}
}
/**
* Returns inputs as formatted string.
*
* @param areaId area id
* @param routerId router id
* @param linkStateId link state id
* @param advertisingRouter advertising router
* @param age age
* @param seqNo sequence number
* @param checkSum checksum
* @return formatted string
*/
private StringBuffer getBuffList(String areaId, String routerId, String linkStateId,
String advertisingRouter, int age, String seqNo, String checkSum) {
StringBuffer strBuf = new StringBuffer();
strBuf.append(areaId);
strBuf.append(",");
strBuf.append(routerId);
strBuf.append(",");
strBuf.append(linkStateId);
strBuf.append(",");
strBuf.append(advertisingRouter);
strBuf.append(",");
strBuf.append(age);
strBuf.append(",");
strBuf.append(seqNo);
strBuf.append(",");
strBuf.append(checkSum);
return strBuf;
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* ISIS cli implementation.
*/
package org.onosproject.ospf.cli;
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="org.onosproject.ospf.cli.ApplicationOspfCommand"/>
</command>
</command-bundle>
</blueprint>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-providers</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-ospf-providers</artifactId>
<packaging>pom</packaging>
<description>ONOS OSPF protocol adapters</description>
<modules>
<module>app</module>
<module>cfg</module>
<module>cli</module>
<module>topology</module>
</modules>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
COMPILE_DEPS = [
'//lib:CORE_DEPS',
'//protocols/ospf/api:onos-protocols-ospf-api',
]
osgi_jar_with_tests (
deps = COMPILE_DEPS,
)
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2016-present Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-providers</artifactId>
<version>1.6.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-ospf-provider-topology</artifactId>
<packaging>bundle</packaging>
<description>ONOS OSPF Topology Providers</description>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.provider.ospf.topology.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.ChassisId;
import org.onlab.packet.Ip4Address;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.link.LinkDescription;
import org.onosproject.net.link.LinkProvider;
import org.onosproject.net.link.LinkProviderRegistry;
import org.onosproject.net.link.LinkProviderService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.ospf.controller.OspfController;
import org.onosproject.ospf.controller.OspfLinkTed;
import org.onosproject.ospf.controller.OspfRouter;
import org.onosproject.ospf.controller.OspfRouterId;
import org.onosproject.ospf.controller.OspfRouterListener;
import org.onosproject.ospf.controller.OspfLinkListener;
import org.slf4j.Logger;
import java.util.LinkedList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which advertises device descriptions to the core.
*/
@Component(immediate = true)
public class OspfTopologyProvider extends AbstractProvider implements DeviceProvider, LinkProvider {
public static final long PSEUDO_PORT = 0xffffffff;
private static final Logger log = getLogger(OspfTopologyProvider.class);
// Default values for tunable parameters
private static final String UNKNOWN = "unknown";
final InternalTopologyProvider listener = new InternalTopologyProvider();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry deviceProviderRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkProviderRegistry linkProviderRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OspfController controller;
//This Interface that defines how this provider can interact with the core.
private LinkProviderService linkProviderService;
// The interface that defines how this Provider can interact with the core
private DeviceProviderService deviceProviderService;
/**
* Creates an OSPF device provider.
*/
public OspfTopologyProvider() {
super(new ProviderId("l3", "org.onosproject.provider.ospf"));
}
@Activate
public void activate() {
deviceProviderService = deviceProviderRegistry.register(this);
linkProviderService = linkProviderRegistry.register(this);
controller.addRouterListener(listener);
controller.addLinkListener(listener);
log.debug("IsisDeviceProvider::activate...!!!!");
}
@Deactivate
public void deactivate() {
log.debug("IsisDeviceProvider::deactivate...!!!!");
deviceProviderRegistry.unregister(this);
deviceProviderService = null;
linkProviderRegistry.unregister(this);
linkProviderService = null;
controller.removeRouterListener(listener);
controller.removeLinkListener(listener);
log.info("deactivated...!!!");
}
@Override
public boolean isReachable(DeviceId deviceId) {
return true;
}
@Override
public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
log.info("changePortState on device {}", deviceId);
}
@Override
public void triggerProbe(DeviceId deviceId) {
log.info("Triggering probe on device {}", deviceId);
}
@Override
public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
log.info("Accepting mastership role change for device {}", deviceId);
}
/**
* Builds link description.
*
* @param ospfRouter OSPF router instance
* @param ospfLinkTed OSPF link TED instance
* @return link description instance
*/
private LinkDescription buildLinkDes(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
long srcAddress = 0;
long dstAddress = 0;
boolean localPseduo = false;
//Changing of port numbers
srcAddress = Ip4Address.valueOf(ospfRouter.routerIp().toString()).toInt();
dstAddress = Ip4Address.valueOf(ospfRouter.neighborRouterId().toString()).toInt();
DeviceId srcId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
DeviceId dstId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.neighborRouterId()));
if (ospfRouter.isDr()) {
localPseduo = true;
}
if (localPseduo && srcAddress == 0) {
srcAddress = PSEUDO_PORT;
}
ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress));
ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress));
return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false);
}
/**
* Internal topology Provider implementation.
*/
protected class InternalTopologyProvider implements OspfRouterListener, OspfLinkListener {
@Override
public void routerAdded(OspfRouter ospfRouter) {
String routerId = ospfRouter.routerIp().toString();
log.info("Added device {}", routerId);
DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
Device.Type deviceType = Device.Type.ROUTER;
//If our routerType is Dr or Bdr type is PSEUDO
if (ospfRouter.isDr()) {
deviceType = Device.Type.ROUTER;
} else {
deviceType = Device.Type.VIRTUAL;
}
//deviceId = DeviceId.deviceId(routerDetails);
ChassisId cId = new ChassisId();
DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
newBuilder.set(AnnotationKeys.TYPE, "L3");
newBuilder.set("routerId", routerId);
DeviceDescription description =
new DefaultDeviceDescription(OspfRouterId.uri(ospfRouter.routerIp()),
deviceType, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, cId, newBuilder.build());
deviceProviderService.deviceConnected(deviceId, description);
}
@Override
public void routerRemoved(OspfRouter ospfRouter) {
String routerId = ospfRouter.routerIp().toString();
log.info("Delete device {}", routerId);
DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
if (deviceProviderService == null) {
return;
}
deviceProviderService.deviceDisconnected(deviceId);
log.info("delete device {}", routerId);
}
@Override
public void addLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
log.debug("Addlink {}", ospfRouter.routerIp());
if (linkProviderService == null) {
return;
}
LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed);
//Updating ports of the link
List<PortDescription> srcPortDescriptions = new LinkedList<>();
srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true));
deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions);
List<PortDescription> dstPortDescriptions = new LinkedList<>();
dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true));
deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions);
linkProviderService.linkDetected(linkDes);
}
@Override
public void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
log.debug("Delete link {}", ospfRouter.routerIp().toString());
if (linkProviderService == null) {
return;
}
LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed);
//Updating ports of the link
List<PortDescription> srcPortDescriptions = new LinkedList<>();
srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true));
deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions);
List<PortDescription> dstPortDescriptions = new LinkedList<>();
dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true));
deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions);
linkProviderService.linkVanished(linkDes);
}
@Override
public void routerChanged(OspfRouter ospfRouter) {
log.info("Router changed is not supported currently");
}
}
}
\ No newline at end of file
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provider that uses OSPF as a means of topology discovery.
*/
package org.onosproject.provider.ospf.topology.impl;
......@@ -47,6 +47,7 @@
<module>netcfglinks</module>
<module>bmv2</module>
<module>isis</module>
<module>ospf</module>
</modules>
<dependencies>
......