Manikandan K
Committed by Gerrit Code Review

ONOS-4361 OSPF Provider

Change-Id: I8260940baac93b48862aff390a3d8e276461842d
1 +BUNDLES = [
2 + '//protocols/ospf/api:onos-protocols-ospf-api',
3 + '//protocols/ospf/ctl:onos-protocols-ospf-ctl',
4 + '//protocols/ospf/protocol:onos-protocols-ospf-protocol',
5 + '//providers/ospf/cfg:onos-providers-ospf-cfg',
6 + '//providers/ospf/topology:onos-providers-ospf-topology',
7 +]
8 +
9 +onos_app (
10 + title = 'OSPF Provider',
11 + category = 'Provider',
12 + url = 'http://onosproject.org',
13 + description = 'ONOS OSPF protocol adapters.',
14 + included_bundles = BUNDLES,
15 +)
16 +
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.ospf" origin="ON.Lab" version="${project.version}"
18 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
19 + features="${project.artifactId}">
20 + <description>${project.description}</description>
21 + <artifact>mvn:${project.groupId}/onos-ospf-api/${project.version}</artifact>
22 + <artifact>mvn:${project.groupId}/onos-ospf-ctl/${project.version}</artifact>
23 + <artifact>mvn:${project.groupId}/onos-ospf-provider-topology/${project.version}</artifact>
24 + <artifact>mvn:${project.groupId}/onos-ospf-provider-cfg/${project.version}</artifact>
25 + <artifact>mvn:${project.groupId}/onos-ospf-provider-cli/${project.version}</artifact>
26 +</app>
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="${project.artifactId}" version="${project.version}"
19 + description="${project.description}">
20 + <feature>onos-api</feature>
21 + <bundle>mvn:${project.groupId}/onos-ospf-api/${project.version}</bundle>
22 + <bundle>mvn:${project.groupId}/onos-ospf-ctl/${project.version}</bundle>
23 + <bundle>mvn:${project.groupId}/onos-ospf-provider-topology/${project.version}</bundle>
24 + <bundle>mvn:${project.groupId}/onos-ospf-provider-cfg/${project.version}</bundle>
25 + <bundle>mvn:${project.groupId}/onos-ospf-provider-cli/${project.version}</bundle>
26 + </feature>
27 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18 + xmlns="http://maven.apache.org/POM/4.0.0"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-ospf-providers</artifactId>
25 + <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-ospf-app</artifactId>
30 + <packaging>pom</packaging>
31 + <description>OSPF protocol southbound providers</description>
32 +
33 + <dependencies>
34 + <dependency>
35 + <groupId>org.onosproject</groupId>
36 + <artifactId>onos-ospf-api</artifactId>
37 + <version>${project.version}</version>
38 + </dependency>
39 + <dependency>
40 + <groupId>org.onosproject</groupId>
41 + <artifactId>onos-ospf-ctl</artifactId>
42 + <version>${project.version}</version>
43 + </dependency>
44 + <dependency>
45 + <groupId>org.onosproject</groupId>
46 + <artifactId>onos-ospf-provider-topology</artifactId>
47 + <version>${project.version}</version>
48 + </dependency>
49 +
50 + <dependency>
51 + <groupId>org.onosproject</groupId>
52 + <artifactId>onos-ospf-provider-cfg</artifactId>
53 + <version>${project.version}</version>
54 + </dependency>
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
57 + <artifactId>onos-ospf-provider-cli</artifactId>
58 + <version>${project.version}</version>
59 + </dependency>
60 + </dependencies>
61 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +COMPILE_DEPS = [
2 + '//lib:CORE_DEPS',
3 + '//protocols/ospf/api:onos-protocols-ospf-api',
4 +]
5 +
6 +osgi_jar_with_tests (
7 + deps = COMPILE_DEPS,
8 +)
9 +
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-ospf-providers</artifactId>
25 + <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-ospf-provider-cfg</artifactId>
30 + <packaging>bundle</packaging>
31 + <description>ONOS OSPF Providers</description>
32 +
33 + <dependencies>
34 + <dependency>
35 + <groupId>org.osgi</groupId>
36 + <artifactId>org.osgi.compendium</artifactId>
37 + </dependency>
38 + <dependency>
39 + <groupId>org.onosproject</groupId>
40 + <artifactId>onos-ospf-ctl</artifactId>
41 + <version>${project.version}</version>
42 + </dependency>
43 + <dependency>
44 + <groupId>org.onosproject</groupId>
45 + <artifactId>onos-ospf-api</artifactId>
46 + <version>${project.version}</version>
47 + </dependency>
48 + </dependencies>
49 +</project>
1 +/*
2 +* Copyright 2016-present Open Networking Laboratory
3 +*
4 +* Licensed under the Apache License, Version 2.0 (the "License");
5 +* you may not use this file except in compliance with the License.
6 +* You may obtain a copy of the License at
7 +*
8 +* http://www.apache.org/licenses/LICENSE-2.0
9 +*
10 +* Unless required by applicable law or agreed to in writing, software
11 +* distributed under the License is distributed on an "AS IS" BASIS,
12 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 +* See the License for the specific language governing permissions and
14 +* limitations under the License.
15 +*/
16 +
17 +package org.onosproject.provider.ospf.cfg.impl;
18 +
19 +import com.fasterxml.jackson.databind.JsonNode;
20 +import org.apache.felix.scr.annotations.Reference;
21 +import org.apache.felix.scr.annotations.ReferenceCardinality;
22 +import org.onlab.osgi.DefaultServiceDirectory;
23 +import org.onosproject.core.ApplicationId;
24 +import org.onosproject.net.config.Config;
25 +import org.onosproject.ospf.controller.OspfController;
26 +
27 +/**
28 + * Configuration object for OSPF.
29 + */
30 +public class OspfAppConfig extends Config<ApplicationId> {
31 + public static final String METHOD = "method";
32 + public static final String ATTRIBUTE = "attribute";
33 + public static final String PROCESSES = "processes";
34 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
35 + private OspfController ospfController;
36 +
37 + /**
38 + * Returns the configuration method, add, delete etc.
39 + *
40 + * @return the configuration method, add, delete etc
41 + */
42 + public String method() {
43 + return get(METHOD, null);
44 + }
45 +
46 + /**
47 + * Returns the configuration attribute, area, process etc.
48 + *
49 + * @return the configuration attribute, area, process etc
50 + */
51 + public String attribute() {
52 + return get(ATTRIBUTE, null);
53 + }
54 +
55 + /**
56 + * Returns the configured processes.
57 + *
58 + * @return the configured processes
59 + */
60 + public JsonNode processes() {
61 + JsonNode jsonNodes = object.get(PROCESSES);
62 +
63 + return jsonNodes;
64 + }
65 +
66 + @Override
67 + public boolean isValid() {
68 + this.ospfController = DefaultServiceDirectory.getService(OspfController.class);
69 +
70 + return true;
71 + }
72 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.provider.ospf.cfg.impl;
17 +
18 +import com.fasterxml.jackson.databind.JsonNode;
19 +import org.apache.felix.scr.annotations.Activate;
20 +import org.apache.felix.scr.annotations.Component;
21 +import org.apache.felix.scr.annotations.Deactivate;
22 +import org.apache.felix.scr.annotations.Service;
23 +import org.apache.felix.scr.annotations.Reference;
24 +import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.onosproject.core.ApplicationId;
26 +import org.onosproject.core.CoreService;
27 +import org.onosproject.net.config.ConfigFactory;
28 +import org.onosproject.net.config.NetworkConfigEvent;
29 +import org.onosproject.net.config.NetworkConfigListener;
30 +import org.onosproject.net.config.NetworkConfigRegistry;
31 +import org.onosproject.net.config.NetworkConfigService;
32 +import org.onosproject.net.config.basics.SubjectFactories;
33 +import org.onosproject.net.provider.AbstractProvider;
34 +import org.onosproject.net.provider.ProviderId;
35 +import org.onosproject.ospf.controller.OspfController;
36 +import org.slf4j.Logger;
37 +
38 +import static org.slf4j.LoggerFactory.getLogger;
39 +
40 +/**
41 + * Provider which advertises device descriptions to the core.
42 + */
43 +@Component(immediate = true)
44 +@Service
45 +public class OspfCfgProvider extends AbstractProvider {
46 +
47 + static final String PROVIDER_ID = "org.onosproject.provider.ospf.cfg";
48 + private static final Logger log = getLogger(OspfCfgProvider.class);
49 + private final ConfigFactory configFactory =
50 + new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, OspfAppConfig.class, "ospfapp") {
51 + @Override
52 + public OspfAppConfig createConfig() {
53 + return new OspfAppConfig();
54 + }
55 + };
56 + private final NetworkConfigListener configListener = new InternalConfigListener();
57 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 + protected OspfController ospfController;
59 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 + protected CoreService coreService;
61 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 + protected NetworkConfigRegistry configRegistry;
63 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 + protected NetworkConfigService configService;
65 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 + protected OspfController controller;
67 + private ApplicationId appId;
68 +
69 + /**
70 + * Creates an OSPF device provider.
71 + */
72 + public OspfCfgProvider() {
73 + super(new ProviderId("ospf", PROVIDER_ID));
74 + }
75 +
76 + public void setOspfController(OspfController ospfController) {
77 + this.ospfController = ospfController;
78 + }
79 +
80 + @Activate
81 + public void activate() {
82 + appId = coreService.registerApplication(PROVIDER_ID);
83 + configService.addListener(configListener);
84 + configRegistry.registerConfigFactory(configFactory);
85 + log.info("activated...!!!");
86 + }
87 +
88 + @Deactivate
89 + public void deactivate() {
90 + configRegistry.unregisterConfigFactory(configFactory);
91 + configService.removeListener(configListener);
92 + log.info("deactivated...!!!");
93 + }
94 +
95 + private void updateConfig() {
96 + OspfAppConfig ospfAppConfig = configRegistry.getConfig(appId, OspfAppConfig.class);
97 + if ("ADD".equalsIgnoreCase(ospfAppConfig.method())) {
98 + JsonNode jsonNode = ospfAppConfig.processes();
99 + ospfController.updateConfig(jsonNode);
100 + } else {
101 + log.debug("Please signify prop1 and prop2");
102 + }
103 + }
104 +
105 + /**
106 + * OSPF config listener to populate the configuration.
107 + */
108 + private class InternalConfigListener implements NetworkConfigListener {
109 + @Override
110 + public void event(NetworkConfigEvent event) {
111 + log.debug("InternalConfigListener:: event is getting called");
112 + if (!event.configClass().equals(OspfAppConfig.class)) {
113 + return;
114 + }
115 + switch (event.type()) {
116 + case CONFIG_ADDED:
117 + updateConfig();
118 + break;
119 + case CONFIG_UPDATED:
120 + updateConfig();
121 + break;
122 + case CONFIG_REMOVED:
123 + break;
124 + default:
125 + break;
126 + }
127 + }
128 + }
129 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Provider that uses OSPF capability request as a means of infrastructure device discovery.
19 + */
20 +package org.onosproject.provider.ospf.cfg.impl;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18 + xmlns="http://maven.apache.org/POM/4.0.0"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-ospf-providers</artifactId>
25 + <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-ospf-provider-cli</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>OSPF cli implementation</description>
33 +
34 + <dependencies>
35 + <dependency>
36 + <groupId>org.onosproject</groupId>
37 + <artifactId>onos-cli</artifactId>
38 + <version>${project.version}</version>
39 + </dependency>
40 + <dependency>
41 + <groupId>org.onosproject</groupId>
42 + <artifactId>onos-ospf-api</artifactId>
43 + <version>${project.version}</version>
44 + </dependency>
45 + <dependency>
46 + <groupId>org.onosproject</groupId>
47 + <artifactId>onos-ospf-ctl</artifactId>
48 + <version>${project.version}</version>
49 + </dependency>
50 + <dependency>
51 + <groupId>org.onosproject</groupId>
52 + <artifactId>onos-ospf-protocol</artifactId>
53 + <version>${project.version}</version>
54 + </dependency>
55 + <dependency>
56 + <groupId>org.osgi</groupId>
57 + <artifactId>org.osgi.compendium</artifactId>
58 + </dependency>
59 + <dependency>
60 + <groupId>org.apache.karaf.shell</groupId>
61 + <artifactId>org.apache.karaf.shell.console</artifactId>
62 + </dependency>
63 + <dependency>
64 + <groupId>org.apache.felix</groupId>
65 + <artifactId>org.apache.felix.scr.annotations</artifactId>
66 + <scope>provided</scope>
67 + </dependency>
68 + </dependencies>
69 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 +* Copyright 2016-present Open Networking Laboratory
3 +*
4 +* Licensed under the Apache License, Version 2.0 (the "License");
5 +* you may not use this file except in compliance with the License.
6 +* You may obtain a copy of the License at
7 +*
8 +* http://www.apache.org/licenses/LICENSE-2.0
9 +*
10 +* Unless required by applicable law or agreed to in writing, software
11 +* distributed under the License is distributed on an "AS IS" BASIS,
12 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 +* See the License for the specific language governing permissions and
14 +* limitations under the License.
15 +*/
16 +package org.onosproject.ospf.cli;
17 +
18 +import org.apache.felix.scr.annotations.Activate;
19 +import org.apache.felix.scr.annotations.Component;
20 +import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Reference;
22 +import org.apache.felix.scr.annotations.ReferenceCardinality;
23 +import org.apache.karaf.shell.commands.Argument;
24 +import org.apache.karaf.shell.commands.Command;
25 +import org.onosproject.cli.AbstractShellCommand;
26 +import org.onosproject.ospf.controller.OspfArea;
27 +import org.onosproject.ospf.controller.OspfController;
28 +import org.onosproject.ospf.controller.OspfInterface;
29 +import org.onosproject.ospf.controller.OspfLsaType;
30 +import org.onosproject.ospf.controller.OspfNbr;
31 +import org.onosproject.ospf.controller.OspfProcess;
32 +import org.onosproject.ospf.protocol.lsa.LsaHeader;
33 +import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
34 +
35 +import java.util.ArrayList;
36 +import java.util.Iterator;
37 +import java.util.List;
38 +
39 +/**
40 + * Representation of OSPF cli commands.
41 + */
42 +@Component(immediate = true)
43 +@Command(scope = "onos", name = "ospf", description = "list database")
44 +public class ApplicationOspfCommand extends AbstractShellCommand {
45 +
46 + protected static final String FORMAT6 = "%-20s%-20s%-20s%-20s%-20s%-20s\n";
47 + protected static final String FORMAT5 = "%-20s%-20s%-20s%-20s%-20s\n";
48 + protected static final String NETWORK = "NETWORK";
49 + protected static final String SUMMARY = "SUMMARY";
50 + protected static final String ASBR = "ABSR";
51 + protected static final String EXTERNAL = "EXTERNAL";
52 + protected static final String LINKLOOPAQ = "LINKLOCALOPAQUE";
53 + protected static final String AREALOCOPAQ = "AREALOCALOPAQUE";
54 + protected static final String ASOPAQ = "ASOPAQUE";
55 + protected static final String DR = "DR";
56 + protected static final String BACKUP = "BACKUP";
57 + protected static final String DROTHER = "DROther";
58 + static final String DATABASE = "database";
59 + static final String NEIGHBORLIST = "neighbors";
60 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
61 + protected OspfController ospfController;
62 + @Argument(index = 0, name = "name",
63 + description = "database|neighborlist",
64 + required = true, multiValued = false)
65 + private String name = null;
66 + @Argument(index = 1, name = "processid",
67 + description = "processId",
68 + required = true, multiValued = false)
69 + private String process = null;
70 + @Argument(index = 2, name = "areaid",
71 + description = "areaId",
72 + required = false, multiValued = false)
73 + private String area = null;
74 + private List<String> routerLsa = new ArrayList<>();
75 + private List<String> networkLsa = new ArrayList<>();
76 + private List<String> summaryLsa = new ArrayList<>();
77 + private List<String> externalLsa = new ArrayList<>();
78 + private List<String> asbrSumm = new ArrayList<>();
79 + private List<String> areaLocalOpaqLsa = new ArrayList<>();
80 + private List<String> linkLocalOpqLsa = new ArrayList<>();
81 + private List<String> asOpqLsa = new ArrayList<>();
82 + private List<String> undefinedLsa = new ArrayList<>();
83 + private List<OspfArea> areaList = new ArrayList<>();
84 +
85 +
86 + @Activate
87 + public void activate() {
88 + print("OSPF cli activated...!!!");
89 + log.debug("OSPF cli activated...!!!");
90 + }
91 +
92 + @Deactivate
93 + public void deactivate() {
94 + log.debug("OSPF cli deactivated...!!!");
95 + }
96 +
97 + @Override
98 + protected void execute() {
99 + if (DATABASE.equals(name)) {
100 + buildOspfDatabaseInformation();
101 + } else if (NEIGHBORLIST.equals(name)) {
102 + buildNeighborInformation();
103 + } else {
104 + print("Please check the command (database|neighbor)");
105 + }
106 + }
107 +
108 + /**
109 + * Clears all the lists.
110 + */
111 + private void clearLists() {
112 + routerLsa.clear();
113 + networkLsa.clear();
114 + summaryLsa.clear();
115 + externalLsa.clear();
116 + asbrSumm.clear();
117 + areaLocalOpaqLsa.clear();
118 + linkLocalOpqLsa.clear();
119 + asOpqLsa.clear();
120 + undefinedLsa.clear();
121 + areaList.clear();
122 + }
123 +
124 + /**
125 + * Builds OSPF database information.
126 + */
127 + private void buildOspfDatabaseInformation() {
128 + try {
129 + //Builds LSA details
130 + buildLsaLists();
131 + for (OspfArea area : areaList) {
132 + if (routerLsa.size() > 0) {
133 + printRouterFormat(area.areaId().toString(), area.routerId().toString(), process);
134 + for (String str : routerLsa) {
135 + String[] lsaVal = str.split("\\,");
136 + if (area.areaId().toString().equalsIgnoreCase(lsaVal[0])) {
137 + print(FORMAT6, lsaVal[2], lsaVal[3], lsaVal[4], lsaVal[5], lsaVal[6], lsaVal[7]);
138 + }
139 + }
140 + }
141 + if (networkLsa.size() > 0) {
142 + printNetworkFormat(area.areaId().toString(), NETWORK);
143 + printDetails(networkLsa, area.areaId().toString());
144 + }
145 + if (summaryLsa.size() > 0) {
146 + printNetworkFormat(area.areaId().toString(), SUMMARY);
147 + printDetails(summaryLsa, area.areaId().toString());
148 + }
149 + if (externalLsa.size() > 0) {
150 + printNetworkFormat(area.areaId().toString(), EXTERNAL);
151 + printDetails(externalLsa, area.areaId().toString());
152 + }
153 + if (asbrSumm.size() > 0) {
154 + printNetworkFormat(area.areaId().toString(), ASBR);
155 + printDetails(asbrSumm, area.areaId().toString());
156 + }
157 + if (areaLocalOpaqLsa.size() > 0) {
158 + printNetworkFormat(area.areaId().toString(), AREALOCOPAQ);
159 + printDetails(areaLocalOpaqLsa, area.areaId().toString());
160 + }
161 + if (linkLocalOpqLsa.size() > 0) {
162 + printNetworkFormat(area.areaId().toString(), LINKLOOPAQ);
163 + printDetails(linkLocalOpqLsa, area.areaId().toString());
164 + }
165 + if (asOpqLsa.size() > 0) {
166 + printNetworkFormat(area.areaId().toString(), ASOPAQ);
167 + printDetails(asOpqLsa, area.areaId().toString());
168 + }
169 + if (undefinedLsa.size() > 0) {
170 + printRouterFormat(area.areaId().toString(), area.routerId().toString(), process);
171 + printDetails(undefinedLsa, area.areaId().toString());
172 + }
173 + }
174 + clearLists();
175 + } catch (Exception ex) {
176 + clearLists();
177 + print("Error occured while Ospf controller getting called" + ex.getMessage());
178 + }
179 + }
180 +
181 + /**
182 + * Prints LSA details.
183 + *
184 + * @param lsaDetails LSA details
185 + * @param areaId area ID
186 + */
187 + private void printDetails(List<String> lsaDetails, String areaId) {
188 + for (String str : lsaDetails) {
189 + String[] lsaVal = str.split("\\,");
190 + if (areaId.equalsIgnoreCase(lsaVal[0])) {
191 + print(FORMAT5, lsaVal[2], lsaVal[3], lsaVal[4], lsaVal[5], lsaVal[6]);
192 + }
193 + }
194 + }
195 +
196 + /**
197 + * Builds all LSA lists with LSA details.
198 + */
199 + private void buildLsaLists() {
200 + this.ospfController = get(OspfController.class);
201 + List<OspfProcess> listOfProcess = ospfController.getAllConfiguredProcesses();
202 + Iterator<OspfProcess> itrProcess = listOfProcess.iterator();
203 + while (itrProcess.hasNext()) {
204 + OspfProcess ospfProcess = itrProcess.next();
205 + if (process.equalsIgnoreCase(ospfProcess.processId())) {
206 + List<OspfArea> listAreas = ospfProcess.areas();
207 + Iterator<OspfArea> itrArea = listAreas.iterator();
208 + while (itrArea.hasNext()) {
209 + OspfArea area = itrArea.next();
210 + List<LsaHeader> lsas = area.database()
211 + .getAllLsaHeaders(false, area.isOpaqueEnabled());
212 + List<LsaHeader> tmpLsaList = new ArrayList<>(lsas);
213 + log.debug("OSPFController::size of database::" + (lsas != null ? lsas.size() : null));
214 + Iterator<LsaHeader> itrLsaHeader = tmpLsaList.iterator();
215 + areaList.add(area);
216 + if (itrLsaHeader != null) {
217 + while (itrLsaHeader.hasNext()) {
218 + LsaHeader header = itrLsaHeader.next();
219 + populateLsaLists(header, area);
220 + }
221 + }
222 + }
223 + }
224 + }
225 + }
226 +
227 + /**
228 + * Populates the LSA lists based on the input.
229 + *
230 + * @param header LSA header instance
231 + * @param area OSPF area instance
232 + */
233 + private void populateLsaLists(LsaHeader header, OspfArea area) {
234 + String seqNo = Long.toHexString(header.lsSequenceNo());
235 + String checkSum = Long.toHexString(header.lsCheckSum());
236 + if (seqNo.length() == 16) {
237 + seqNo = seqNo.substring(8, seqNo.length());
238 + }
239 + if (checkSum.length() == 16) {
240 + checkSum = checkSum.substring(8, checkSum.length());
241 + }
242 + StringBuffer strBuf = getBuffList(area.areaId().toString(), area.routerId().toString(),
243 + header.linkStateId(),
244 + header.advertisingRouter().toString(),
245 + header.age(), seqNo, checkSum);
246 + if (header.lsType() == OspfLsaType.ROUTER.value()) {
247 + strBuf.append(",");
248 + strBuf.append(((RouterLsa) header).noLink());
249 + routerLsa.add(strBuf.toString());
250 + } else if (header.lsType() == OspfLsaType.NETWORK.value()) {
251 + strBuf.append(",");
252 + strBuf.append("0");
253 + networkLsa.add(strBuf.toString());
254 + } else if (header.lsType() == OspfLsaType.SUMMARY.value()) {
255 + strBuf.append(",");
256 + strBuf.append("0");
257 + summaryLsa.add(strBuf.toString());
258 + } else if (header.lsType() == OspfLsaType.EXTERNAL_LSA.value()) {
259 + strBuf.append(",");
260 + strBuf.append("0");
261 + externalLsa.add(strBuf.toString());
262 + } else if (header.lsType() == OspfLsaType.ASBR_SUMMARY.value()) {
263 + strBuf.append(",");
264 + strBuf.append("0");
265 + asbrSumm.add(strBuf.toString());
266 + } else if (header.lsType() == OspfLsaType.AREA_LOCAL_OPAQUE_LSA.value()) {
267 + strBuf.append(",");
268 + strBuf.append("0");
269 + areaLocalOpaqLsa.add(strBuf.toString());
270 + } else if (header.lsType() == OspfLsaType.LINK_LOCAL_OPAQUE_LSA.value()) {
271 + strBuf.append(",");
272 + strBuf.append("0");
273 + linkLocalOpqLsa.add(strBuf.toString());
274 + } else if (header.lsType() == OspfLsaType.AS_OPAQUE_LSA.value()) {
275 + strBuf.append(",");
276 + strBuf.append("0");
277 + asOpqLsa.add(strBuf.toString());
278 + } else {
279 + strBuf.append(",");
280 + strBuf.append("0");
281 + undefinedLsa.add(strBuf.toString());
282 + }
283 + }
284 +
285 + /**
286 + * Builds OSPF neighbor information.
287 + */
288 + private void buildNeighborInformation() {
289 + try {
290 + this.ospfController = get(OspfController.class);
291 + List<OspfProcess> listOfProcess = ospfController.getAllConfiguredProcesses();
292 + boolean flag = false;
293 + printNeighborsFormat();
294 + Iterator<OspfProcess> itrProcess = listOfProcess.iterator();
295 + while (itrProcess.hasNext()) {
296 + OspfProcess process = itrProcess.next();
297 + List<OspfArea> listAreas = process.areas();
298 + Iterator<OspfArea> itrArea = listAreas.iterator();
299 + while (itrArea.hasNext()) {
300 + OspfArea area = itrArea.next();
301 + List<OspfInterface> itrefaceList = area.ospfInterfaceList();
302 + for (OspfInterface interfc : itrefaceList) {
303 + List<OspfNbr> nghbrList = new ArrayList<>(interfc.listOfNeighbors().values());
304 + for (OspfNbr neigbor : nghbrList) {
305 + print("%-20s%-20s%-20s%-20s%-20s\n", neigbor.neighborId(), neigbor.routerPriority(),
306 + neigbor.getState() + "/" + checkDrBdrOther(neigbor.neighborIpAddr().toString(),
307 + neigbor.neighborDr().toString(),
308 + neigbor.neighborBdr().toString()),
309 + neigbor.neighborIpAddr().toString(), interfc.ipAddress());
310 + }
311 + }
312 + }
313 + }
314 + } catch (Exception ex) {
315 + print("Error occured while Ospf controller getting called" + ex.getMessage());
316 + }
317 + }
318 +
319 + /**
320 + * Prints input after formatting.
321 + *
322 + * @param areaId area ID
323 + * @param routerId router ID
324 + * @param processId process ID
325 + */
326 + private void printRouterFormat(String areaId, String routerId, String processId) {
327 + print("%s (%s) %s %s\n", "OSPF Router with ID", routerId, "Process Id", processId);
328 + print("%s ( Area %s)\n", "Router Link States", areaId);
329 + print("%-20s%-20s%-20s%-20s%-20s%-20s\n", "Link Id", "ADV Router", "Age", "Seq#",
330 + "CkSum", "Link Count");
331 + }
332 +
333 + /**
334 + * Prints input after formatting.
335 + *
336 + * @param areaId area ID
337 + * @param type network type
338 + */
339 + private void printNetworkFormat(String areaId, String type) {
340 + print("%s %s ( Area %s)\n", type, "Link States", areaId);
341 + print("%-20s%-20s%-20s%-20s%-20s\n", "Link Id", "ADV Router", "Age", "Seq#", "CkSum");
342 + }
343 +
344 + /**
345 + * Prints input after formatting.
346 + */
347 + private void printNeighborsFormat() {
348 + print("%-20s%-20s%-20s%-20s%-20s\n", "Neighbor Id", "Pri", "State",
349 + "Address", "Interface");
350 + }
351 +
352 + /**
353 + * Checks whether the neighbor is DR or BDR.
354 + *
355 + * @param ip IP address to check
356 + * @param drIP DRs IP address
357 + * @param bdrIp BDRs IP address
358 + * @return 1- neighbor is DR, 2- neighbor is BDR, 3- DROTHER
359 + */
360 + public String checkDrBdrOther(String ip, String drIP, String bdrIp) {
361 +
362 + if (ip.equalsIgnoreCase(drIP)) {
363 + return DR;
364 + } else if (ip.equalsIgnoreCase(bdrIp)) {
365 + return BACKUP;
366 + } else {
367 + return DROTHER;
368 + }
369 + }
370 +
371 + /**
372 + * Returns inputs as formatted string.
373 + *
374 + * @param areaId area id
375 + * @param routerId router id
376 + * @param linkStateId link state id
377 + * @param advertisingRouter advertising router
378 + * @param age age
379 + * @param seqNo sequence number
380 + * @param checkSum checksum
381 + * @return formatted string
382 + */
383 + private StringBuffer getBuffList(String areaId, String routerId, String linkStateId,
384 + String advertisingRouter, int age, String seqNo, String checkSum) {
385 + StringBuffer strBuf = new StringBuffer();
386 + strBuf.append(areaId);
387 + strBuf.append(",");
388 + strBuf.append(routerId);
389 + strBuf.append(",");
390 + strBuf.append(linkStateId);
391 + strBuf.append(",");
392 + strBuf.append(advertisingRouter);
393 + strBuf.append(",");
394 + strBuf.append(age);
395 + strBuf.append(",");
396 + strBuf.append(seqNo);
397 + strBuf.append(",");
398 + strBuf.append(checkSum);
399 + return strBuf;
400 + }
401 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * ISIS cli implementation.
19 + */
20 +package org.onosproject.ospf.cli;
1 +<!--
2 + ~ Copyright 2016-present Open Networking Laboratory
3 + ~
4 + ~ Licensed under the Apache License, Version 2.0 (the "License");
5 + ~ you may not use this file except in compliance with the License.
6 + ~ You may obtain a copy of the License at
7 + ~
8 + ~ http://www.apache.org/licenses/LICENSE-2.0
9 + ~
10 + ~ Unless required by applicable law or agreed to in writing, software
11 + ~ distributed under the License is distributed on an "AS IS" BASIS,
12 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + ~ See the License for the specific language governing permissions and
14 + ~ limitations under the License.
15 + -->
16 +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
17 +
18 + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
19 + <command>
20 + <action class="org.onosproject.ospf.cli.ApplicationOspfCommand"/>
21 + </command>
22 + </command-bundle>
23 +
24 +</blueprint>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-providers</artifactId>
25 + <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-ospf-providers</artifactId>
30 + <packaging>pom</packaging>
31 +
32 + <description>ONOS OSPF protocol adapters</description>
33 +
34 + <modules>
35 + <module>app</module>
36 + <module>cfg</module>
37 + <module>cli</module>
38 + <module>topology</module>
39 + </modules>
40 +
41 + <dependencies>
42 + <dependency>
43 + <groupId>org.onosproject</groupId>
44 + <artifactId>onos-ospf-api</artifactId>
45 + <version>${project.version}</version>
46 + </dependency>
47 + <dependency>
48 + <groupId>org.onosproject</groupId>
49 + <artifactId>onos-api</artifactId>
50 + <classifier>tests</classifier>
51 + <scope>test</scope>
52 + </dependency>
53 + </dependencies>
54 +
55 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +COMPILE_DEPS = [
2 + '//lib:CORE_DEPS',
3 + '//protocols/ospf/api:onos-protocols-ospf-api',
4 +]
5 +
6 +osgi_jar_with_tests (
7 + deps = COMPILE_DEPS,
8 +)
9 +
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016-present Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-ospf-providers</artifactId>
25 + <version>1.6.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-ospf-provider-topology</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>ONOS OSPF Topology Providers</description>
33 + <dependencies>
34 + <dependency>
35 + <groupId>org.osgi</groupId>
36 + <artifactId>org.osgi.compendium</artifactId>
37 + </dependency>
38 + </dependencies>
39 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.provider.ospf.topology.impl;
17 +
18 +import org.apache.felix.scr.annotations.Activate;
19 +import org.apache.felix.scr.annotations.Component;
20 +import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Reference;
22 +import org.apache.felix.scr.annotations.ReferenceCardinality;
23 +import org.onlab.packet.ChassisId;
24 +import org.onlab.packet.Ip4Address;
25 +import org.onosproject.net.AnnotationKeys;
26 +import org.onosproject.net.ConnectPoint;
27 +import org.onosproject.net.DefaultAnnotations;
28 +import org.onosproject.net.Device;
29 +import org.onosproject.net.DeviceId;
30 +import org.onosproject.net.Link;
31 +import org.onosproject.net.MastershipRole;
32 +import org.onosproject.net.PortNumber;
33 +import org.onosproject.net.device.DefaultDeviceDescription;
34 +import org.onosproject.net.device.DefaultPortDescription;
35 +import org.onosproject.net.device.DeviceDescription;
36 +import org.onosproject.net.device.DeviceProvider;
37 +import org.onosproject.net.device.DeviceProviderRegistry;
38 +import org.onosproject.net.device.DeviceProviderService;
39 +import org.onosproject.net.device.PortDescription;
40 +import org.onosproject.net.link.DefaultLinkDescription;
41 +import org.onosproject.net.link.LinkDescription;
42 +import org.onosproject.net.link.LinkProvider;
43 +import org.onosproject.net.link.LinkProviderRegistry;
44 +import org.onosproject.net.link.LinkProviderService;
45 +import org.onosproject.net.provider.AbstractProvider;
46 +import org.onosproject.net.provider.ProviderId;
47 +import org.onosproject.ospf.controller.OspfController;
48 +import org.onosproject.ospf.controller.OspfLinkTed;
49 +import org.onosproject.ospf.controller.OspfRouter;
50 +import org.onosproject.ospf.controller.OspfRouterId;
51 +import org.onosproject.ospf.controller.OspfRouterListener;
52 +import org.onosproject.ospf.controller.OspfLinkListener;
53 +import org.slf4j.Logger;
54 +
55 +import java.util.LinkedList;
56 +import java.util.List;
57 +
58 +import static org.slf4j.LoggerFactory.getLogger;
59 +
60 +/**
61 + * Provider which advertises device descriptions to the core.
62 + */
63 +@Component(immediate = true)
64 +public class OspfTopologyProvider extends AbstractProvider implements DeviceProvider, LinkProvider {
65 +
66 + public static final long PSEUDO_PORT = 0xffffffff;
67 + private static final Logger log = getLogger(OspfTopologyProvider.class);
68 + // Default values for tunable parameters
69 + private static final String UNKNOWN = "unknown";
70 + final InternalTopologyProvider listener = new InternalTopologyProvider();
71 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
72 + protected DeviceProviderRegistry deviceProviderRegistry;
73 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 + protected LinkProviderRegistry linkProviderRegistry;
75 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
76 + protected OspfController controller;
77 + //This Interface that defines how this provider can interact with the core.
78 + private LinkProviderService linkProviderService;
79 + // The interface that defines how this Provider can interact with the core
80 + private DeviceProviderService deviceProviderService;
81 +
82 + /**
83 + * Creates an OSPF device provider.
84 + */
85 + public OspfTopologyProvider() {
86 + super(new ProviderId("l3", "org.onosproject.provider.ospf"));
87 + }
88 +
89 + @Activate
90 + public void activate() {
91 + deviceProviderService = deviceProviderRegistry.register(this);
92 + linkProviderService = linkProviderRegistry.register(this);
93 + controller.addRouterListener(listener);
94 + controller.addLinkListener(listener);
95 + log.debug("IsisDeviceProvider::activate...!!!!");
96 + }
97 +
98 + @Deactivate
99 + public void deactivate() {
100 + log.debug("IsisDeviceProvider::deactivate...!!!!");
101 + deviceProviderRegistry.unregister(this);
102 + deviceProviderService = null;
103 + linkProviderRegistry.unregister(this);
104 + linkProviderService = null;
105 + controller.removeRouterListener(listener);
106 + controller.removeLinkListener(listener);
107 + log.info("deactivated...!!!");
108 + }
109 +
110 + @Override
111 + public boolean isReachable(DeviceId deviceId) {
112 + return true;
113 + }
114 +
115 + @Override
116 + public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
117 + log.info("changePortState on device {}", deviceId);
118 + }
119 +
120 + @Override
121 + public void triggerProbe(DeviceId deviceId) {
122 + log.info("Triggering probe on device {}", deviceId);
123 + }
124 +
125 + @Override
126 + public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
127 + log.info("Accepting mastership role change for device {}", deviceId);
128 + }
129 +
130 + /**
131 + * Builds link description.
132 + *
133 + * @param ospfRouter OSPF router instance
134 + * @param ospfLinkTed OSPF link TED instance
135 + * @return link description instance
136 + */
137 + private LinkDescription buildLinkDes(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
138 + long srcAddress = 0;
139 + long dstAddress = 0;
140 + boolean localPseduo = false;
141 + //Changing of port numbers
142 + srcAddress = Ip4Address.valueOf(ospfRouter.routerIp().toString()).toInt();
143 + dstAddress = Ip4Address.valueOf(ospfRouter.neighborRouterId().toString()).toInt();
144 + DeviceId srcId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
145 + DeviceId dstId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.neighborRouterId()));
146 + if (ospfRouter.isDr()) {
147 + localPseduo = true;
148 + }
149 + if (localPseduo && srcAddress == 0) {
150 + srcAddress = PSEUDO_PORT;
151 + }
152 +
153 + ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress));
154 + ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress));
155 +
156 + return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false);
157 + }
158 +
159 + /**
160 + * Internal topology Provider implementation.
161 + */
162 + protected class InternalTopologyProvider implements OspfRouterListener, OspfLinkListener {
163 +
164 + @Override
165 + public void routerAdded(OspfRouter ospfRouter) {
166 + String routerId = ospfRouter.routerIp().toString();
167 + log.info("Added device {}", routerId);
168 + DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
169 + Device.Type deviceType = Device.Type.ROUTER;
170 + //If our routerType is Dr or Bdr type is PSEUDO
171 + if (ospfRouter.isDr()) {
172 + deviceType = Device.Type.ROUTER;
173 + } else {
174 + deviceType = Device.Type.VIRTUAL;
175 + }
176 + //deviceId = DeviceId.deviceId(routerDetails);
177 + ChassisId cId = new ChassisId();
178 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
179 +
180 + newBuilder.set(AnnotationKeys.TYPE, "L3");
181 + newBuilder.set("routerId", routerId);
182 + DeviceDescription description =
183 + new DefaultDeviceDescription(OspfRouterId.uri(ospfRouter.routerIp()),
184 + deviceType, UNKNOWN, UNKNOWN, UNKNOWN,
185 + UNKNOWN, cId, newBuilder.build());
186 + deviceProviderService.deviceConnected(deviceId, description);
187 + }
188 +
189 + @Override
190 + public void routerRemoved(OspfRouter ospfRouter) {
191 + String routerId = ospfRouter.routerIp().toString();
192 + log.info("Delete device {}", routerId);
193 + DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp()));
194 + if (deviceProviderService == null) {
195 + return;
196 + }
197 + deviceProviderService.deviceDisconnected(deviceId);
198 + log.info("delete device {}", routerId);
199 + }
200 +
201 + @Override
202 + public void addLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
203 + log.debug("Addlink {}", ospfRouter.routerIp());
204 + if (linkProviderService == null) {
205 + return;
206 + }
207 + LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed);
208 + //Updating ports of the link
209 + List<PortDescription> srcPortDescriptions = new LinkedList<>();
210 + srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true));
211 + deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions);
212 +
213 + List<PortDescription> dstPortDescriptions = new LinkedList<>();
214 + dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true));
215 + deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions);
216 + linkProviderService.linkDetected(linkDes);
217 + }
218 +
219 + @Override
220 + public void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
221 + log.debug("Delete link {}", ospfRouter.routerIp().toString());
222 + if (linkProviderService == null) {
223 + return;
224 + }
225 + LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed);
226 + //Updating ports of the link
227 + List<PortDescription> srcPortDescriptions = new LinkedList<>();
228 + srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true));
229 + deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions);
230 +
231 + List<PortDescription> dstPortDescriptions = new LinkedList<>();
232 + dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true));
233 + deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions);
234 + linkProviderService.linkVanished(linkDes);
235 + }
236 +
237 + @Override
238 + public void routerChanged(OspfRouter ospfRouter) {
239 + log.info("Router changed is not supported currently");
240 + }
241 + }
242 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Provider that uses OSPF as a means of topology discovery.
19 + */
20 +package org.onosproject.provider.ospf.topology.impl;
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
47 <module>netcfglinks</module> 47 <module>netcfglinks</module>
48 <module>bmv2</module> 48 <module>bmv2</module>
49 <module>isis</module> 49 <module>isis</module>
50 + <module>ospf</module>
50 </modules> 51 </modules>
51 52
52 <dependencies> 53 <dependencies>
......