Dhruv Dhody
Committed by Gerrit Code Review

ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation

Change-Id: I86db4dd46d29f636e33494a2a4d0c3be4f373f89
1 +<!--
2 + ~ Copyright 2016 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 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17 + xmlns="http://maven.apache.org/POM/4.0.0"
18 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19 + <modelVersion>4.0.0</modelVersion>
20 +
21 + <parent>
22 + <groupId>org.onosproject</groupId>
23 + <artifactId>onos-ospf</artifactId>
24 + <version>1.4.0-SNAPSHOT</version>
25 + <relativePath>../pom.xml</relativePath>
26 + </parent>
27 +
28 + <artifactId>onos-ospf-ctl</artifactId>
29 + <packaging>bundle</packaging>
30 +
31 + <description>ONOS Ospf controller subsystem API</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-protocol</artifactId>
42 + <version>${project.version}</version>
43 + </dependency>
44 +
45 + <dependency>
46 + <groupId>io.netty</groupId>
47 + <artifactId>netty</artifactId>
48 + </dependency>
49 + <dependency>
50 + <groupId>com.fasterxml.jackson.core</groupId>
51 + <artifactId>jackson-databind</artifactId>
52 + </dependency>
53 + <dependency>
54 + <groupId>com.fasterxml.jackson.core</groupId>
55 + <artifactId>jackson-annotations</artifactId>
56 + </dependency>
57 + <dependency>
58 + <groupId>org.apache.felix</groupId>
59 + <artifactId>org.apache.felix.scr.annotations</artifactId>
60 + </dependency>
61 + <dependency>
62 + <groupId>org.osgi</groupId>
63 + <artifactId>org.osgi.compendium</artifactId>
64 + </dependency>
65 + <dependency>
66 + <groupId>org.easymock</groupId>
67 + <artifactId>easymock</artifactId>
68 + <version>3.2</version>
69 + <scope>test</scope>
70 + </dependency>
71 + </dependencies>
72 +
73 + <build>
74 + <plugins>
75 + <plugin>
76 + <groupId>org.apache.felix</groupId>
77 + <artifactId>maven-scr-plugin</artifactId>
78 + </plugin>
79 + </plugins>
80 + </build>
81 +
82 +</project>
1 +/*
2 + * Copyright 2016 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.controller.impl;
17 +
18 +import org.onlab.packet.Ip4Address;
19 +import org.onosproject.ospf.controller.DeviceInformation;
20 +
21 +import java.util.ArrayList;
22 +import java.util.List;
23 +
24 +/**
25 + * Representation of an OSPF device information.
26 + */
27 +public class DeviceInformationImpl implements DeviceInformation {
28 +
29 + Ip4Address deviceId;
30 + Ip4Address routerId;
31 + List<Ip4Address> interfaceId = new ArrayList<>();
32 + Ip4Address areaId;
33 + boolean alreadyCreated;
34 + boolean isDr;
35 +
36 + Ip4Address neighborId;
37 +
38 + /**
39 + * Gets router id.
40 + *
41 + * @return router id
42 + */
43 + public Ip4Address routerId() {
44 + return routerId;
45 + }
46 +
47 + /**
48 + * Sets router id.
49 + *
50 + * @param routerId router id
51 + */
52 + public void setRouterId(Ip4Address routerId) {
53 + this.routerId = routerId;
54 + }
55 +
56 + /**
57 + * Gets device id.
58 + *
59 + * @return device id
60 + */
61 + public Ip4Address deviceId() {
62 + return deviceId;
63 + }
64 +
65 + /**
66 + * Sets device id.
67 + *
68 + * @param deviceId device id
69 + */
70 + public void setDeviceId(Ip4Address deviceId) {
71 + this.deviceId = deviceId;
72 + }
73 +
74 + /**
75 + * Gets interface id list.
76 + *
77 + * @return interface id list
78 + */
79 + public List<Ip4Address> interfaceId() {
80 + return this.interfaceId;
81 + }
82 +
83 + /**
84 + * Adds interface id to list.
85 + *
86 + * @param interfaceId interface id
87 + */
88 + public void addInterfaceId(Ip4Address interfaceId) {
89 + this.interfaceId.add(interfaceId);
90 + }
91 +
92 + /**
93 + * Gets area id.
94 + *
95 + * @return area id
96 + */
97 + public Ip4Address areaId() {
98 + return areaId;
99 + }
100 +
101 + /**
102 + * Sets area id.
103 + *
104 + * @param areaId area id
105 + */
106 + public void setAreaId(Ip4Address areaId) {
107 + this.areaId = areaId;
108 + }
109 +
110 + /**
111 + * Gets is already created or not.
112 + *
113 + * @return true if already created else false
114 + */
115 + public boolean isAlreadyCreated() {
116 + return alreadyCreated;
117 + }
118 +
119 + /**
120 + * Sets is already created or not.
121 + *
122 + * @param alreadyCreated true or false
123 + */
124 + public void setAlreadyCreated(boolean alreadyCreated) {
125 + this.alreadyCreated = alreadyCreated;
126 + }
127 +
128 + /**
129 + * Gets is DR or not.
130 + *
131 + * @return true if DR else false
132 + */
133 + public boolean isDr() {
134 + return isDr;
135 + }
136 +
137 + /**
138 + * Stes DR or not.
139 + *
140 + * @param dr true or false
141 + */
142 + public void setDr(boolean dr) {
143 + this.isDr = dr;
144 + }
145 +
146 + /**
147 + * Gets neighbor id.
148 + *
149 + * @return neighbor id
150 + */
151 + public Ip4Address neighborId() {
152 + return neighborId;
153 + }
154 +
155 + /**
156 + * Sets neighbor id.
157 + *
158 + * @param neighborId neighbor id
159 + */
160 + public void setNeighborId(Ip4Address neighborId) {
161 + this.neighborId = neighborId;
162 + }
163 +}
1 +/*
2 + * Copyright 2016 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.controller.impl;
17 +
18 +import org.onlab.packet.Ip4Address;
19 +import org.onosproject.ospf.controller.LinkInformation;
20 +
21 +/**
22 + * Representation of an OSPF link information..
23 + */
24 +public class LinkInformationImpl implements LinkInformation {
25 +
26 + String linkId;
27 + Ip4Address linkSourceId;
28 + Ip4Address linkDestinationId;
29 + Ip4Address interfaceIp;
30 + boolean linkSrcIdNotRouterId;
31 + boolean alreadyCreated;
32 + Ip4Address linkSourceIpAddress;
33 + Ip4Address linkDestinationIpAddress;
34 +
35 + /**
36 + * Gets link id.
37 + *
38 + * @return link id
39 + */
40 + public String linkId() {
41 + return linkId;
42 + }
43 +
44 + /**
45 + * Sets link id.
46 + *
47 + * @param linkId link id
48 + */
49 + public void setLinkId(String linkId) {
50 + this.linkId = linkId;
51 + }
52 +
53 + /**
54 + * Gets is already created or not.
55 + *
56 + * @return true if already created else false
57 + */
58 + public boolean isAlreadyCreated() {
59 + return alreadyCreated;
60 + }
61 +
62 + /**
63 + * Sets is already created or not.
64 + *
65 + * @param alreadyCreated true or false
66 + */
67 + public void setAlreadyCreated(boolean alreadyCreated) {
68 + this.alreadyCreated = alreadyCreated;
69 + }
70 +
71 + /**
72 + * Gets is link source id is not router id.
73 + *
74 + * @return true if link source id is router id else false
75 + */
76 + public boolean isLinkSrcIdNotRouterId() {
77 + return linkSrcIdNotRouterId;
78 + }
79 +
80 + /**
81 + * Sets is link source id is not router id.
82 + *
83 + * @param linkSrcIdNotRouterId true or false
84 + */
85 + public void setLinkSrcIdNotRouterId(boolean linkSrcIdNotRouterId) {
86 + this.linkSrcIdNotRouterId = linkSrcIdNotRouterId;
87 + }
88 +
89 + /**
90 + * Gets link destination id.
91 + *
92 + * @return link destination id
93 + */
94 + public Ip4Address linkDestinationId() {
95 + return linkDestinationId;
96 + }
97 +
98 + /**
99 + * Sets link destination id.
100 + *
101 + * @param linkDestinationId link destination id
102 + */
103 + public void setLinkDestinationId(Ip4Address linkDestinationId) {
104 + this.linkDestinationId = linkDestinationId;
105 + }
106 +
107 + /**
108 + * Gets link source id.
109 + *
110 + * @return link source id
111 + */
112 + public Ip4Address linkSourceId() {
113 + return linkSourceId;
114 + }
115 +
116 + /**
117 + * Sets link source id.
118 + *
119 + * @param linkSourceId link source id
120 + */
121 + public void setLinkSourceId(Ip4Address linkSourceId) {
122 + this.linkSourceId = linkSourceId;
123 + }
124 +
125 + /**
126 + * Gets interface IP address.
127 + *
128 + * @return interface IP address
129 + */
130 + public Ip4Address interfaceIp() {
131 + return interfaceIp;
132 + }
133 +
134 + /**
135 + * Sets interface IP address.
136 + *
137 + * @param interfaceIp interface IP address
138 + */
139 + public void setInterfaceIp(Ip4Address interfaceIp) {
140 + this.interfaceIp = interfaceIp;
141 + }
142 +
143 + /**
144 + * Gets link source IP address.
145 + *
146 + * @return link source IP address
147 + */
148 + public Ip4Address linkSourceIpAddress() {
149 + return linkSourceIpAddress;
150 + }
151 +
152 + /**
153 + * Sets link source IP address.
154 + *
155 + * @param linkSourceIpAddress link source IP address
156 + */
157 + public void setLinkSourceIpAddress(Ip4Address linkSourceIpAddress) {
158 + this.linkSourceIpAddress = linkSourceIpAddress;
159 + }
160 +
161 + /**
162 + * Gets link destination IP address.
163 + *
164 + * @return link destination IP address
165 + */
166 + public Ip4Address linkDestinationIpAddress() {
167 + return linkDestinationIpAddress;
168 + }
169 +
170 + /**
171 + * Sets link destination IP address.
172 + *
173 + * @param linkDestinationIpAddress link destination IP address
174 + */
175 + public void setLinkDestinationIpAddress(Ip4Address linkDestinationIpAddress) {
176 + this.linkDestinationIpAddress = linkDestinationIpAddress;
177 + }
178 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.controller.impl;
18 +
19 +import com.google.common.collect.Sets;
20 +import org.apache.felix.scr.annotations.Activate;
21 +import org.apache.felix.scr.annotations.Component;
22 +import org.apache.felix.scr.annotations.Deactivate;
23 +import org.apache.felix.scr.annotations.Reference;
24 +import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.apache.felix.scr.annotations.Service;
26 +import org.onosproject.net.driver.DriverService;
27 +import org.onosproject.ospf.controller.OspfAgent;
28 +import org.onosproject.ospf.controller.OspfController;
29 +import org.onosproject.ospf.controller.OspfLinkListener;
30 +import org.onosproject.ospf.controller.OspfLinkTed;
31 +import org.onosproject.ospf.controller.OspfProcess;
32 +import org.onosproject.ospf.controller.OspfRouter;
33 +import org.onosproject.ospf.controller.OspfRouterListener;
34 +import org.slf4j.Logger;
35 +import org.slf4j.LoggerFactory;
36 +
37 +import java.util.ArrayList;
38 +import java.util.HashSet;
39 +import java.util.List;
40 +import java.util.Set;
41 +
42 +/**
43 + * Representation of an OSPF controller implementation.
44 + * Serves as a one stop shop for obtaining OSPF devices and (un)register listeners on OSPF events
45 + */
46 +@Component(immediate = true)
47 +@Service
48 +public class OspfControllerImpl implements OspfController {
49 +
50 + protected static final Logger log = LoggerFactory.getLogger(OspfControllerImpl.class);
51 + private final Controller ctrl = new Controller();
52 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
53 + protected DriverService driverService;
54 + protected Set<OspfRouterListener> ospfRouterListener = new HashSet<>();
55 + protected Set<OspfLinkListener> ospfLinkListener = Sets.newHashSet();
56 + protected OspfAgent agent = new InternalDeviceConfig();
57 +
58 + @Activate
59 + public void activate() {
60 + log.info("OSPFControllerImpl activate...!!!");
61 + ctrl.start(agent, driverService);
62 + log.info("Started");
63 + }
64 +
65 + @Deactivate
66 + public void deactivate() {
67 + ctrl.stop();
68 + log.info("Stopped");
69 + }
70 +
71 +
72 + @Override
73 + public void addRouterListener(OspfRouterListener listener) {
74 + if (!ospfRouterListener.contains(listener)) {
75 + this.ospfRouterListener.add(listener);
76 + }
77 + }
78 +
79 + @Override
80 + public void removeRouterListener(OspfRouterListener listener) {
81 + this.ospfRouterListener.remove(listener);
82 + }
83 +
84 + @Override
85 + public void addLinkListener(OspfLinkListener listener) {
86 + ospfLinkListener.add(listener);
87 +
88 + }
89 +
90 + @Override
91 + public void removeLinkListener(OspfLinkListener listener) {
92 + ospfLinkListener.remove(listener);
93 +
94 + }
95 +
96 + @Override
97 + public Set<OspfRouterListener> listener() {
98 + return ospfRouterListener;
99 + }
100 +
101 + @Override
102 + public Set<OspfLinkListener> linkListener() {
103 + return ospfLinkListener;
104 + }
105 +
106 +
107 + @Override
108 + public List<OspfProcess> getAllConfiguredProcesses() {
109 + List<OspfProcess> processes = ctrl.getAllConfiguredProcesses();
110 + return processes;
111 + }
112 +
113 + @Override
114 + public void updateConfig(List processes) {
115 + List<OspfProcess> ospfProcesses = new ArrayList<>();
116 + if (processes != null) {
117 + for (Object process : processes) {
118 + ospfProcesses.add((OspfProcess) process);
119 + }
120 + }
121 + log.debug("updateConfig::OspfList::processes::{}", ospfProcesses);
122 + ctrl.updateConfig(ospfProcesses);
123 + }
124 +
125 + @Override
126 + public void deleteConfig(List<OspfProcess> processes, String attribute) {
127 + List<OspfProcess> ospfProcesses = new ArrayList<>();
128 + if (processes != null) {
129 + for (Object process : processes) {
130 + ospfProcesses.add((OspfProcess) process);
131 + }
132 + }
133 + log.debug("deleteConfig::OspfList::processes::{}", ospfProcesses);
134 + ctrl.deleteConfig(ospfProcesses, attribute);
135 + }
136 +
137 + /**
138 + * Notifier for internal OSPF device and link changes.
139 + */
140 + private class InternalDeviceConfig implements OspfAgent {
141 +
142 + @Override
143 + public boolean addConnectedRouter(OspfRouter ospfRouter) {
144 + for (OspfRouterListener l : listener()) {
145 + l.routerAdded(ospfRouter);
146 + }
147 + return true;
148 + }
149 +
150 + @Override
151 + public void removeConnectedRouter(OspfRouter ospfRouter) {
152 + for (OspfRouterListener l : listener()) {
153 + l.routerRemoved(ospfRouter);
154 + }
155 + }
156 +
157 + @Override
158 + public void addLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
159 + for (OspfLinkListener l : linkListener()) {
160 + l.addLink(ospfRouter, ospfLinkTed);
161 + }
162 +
163 + }
164 +
165 + @Override
166 + public void deleteLink(OspfRouter ospfRouter) {
167 + for (OspfLinkListener l : linkListener()) {
168 + l.deleteLink(ospfRouter);
169 + }
170 + }
171 + }
172 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.controller.impl;
17 +
18 +import org.onlab.packet.Ip4Address;
19 +import org.onlab.packet.Ip6Address;
20 +import org.onosproject.ospf.controller.OspfDeviceTed;
21 +
22 +import java.util.List;
23 +
24 +/**
25 + * Representation of an OSPF device Traffic Engineering details.
26 + */
27 +public class OspfDeviceTedImpl implements OspfDeviceTed {
28 +
29 + List<Ip4Address> ipv4RouterIds;
30 + List<Ip6Address> ipv6RouterIds;
31 + List<Short> topologyIds;
32 + Boolean asbr;
33 + Boolean abr;
34 +
35 + /**
36 + * Gets list of IPv4 router id.
37 + *
38 + * @return list of IPv4 router id
39 + */
40 + public List<Ip4Address> ipv4RouterIds() {
41 + return ipv4RouterIds;
42 + }
43 +
44 + @Override
45 + public void setIpv4RouterIds(List<Ip4Address> ipv4RouterIds) {
46 + this.ipv4RouterIds = ipv4RouterIds;
47 + }
48 +
49 + /**
50 + * Gets if router is area border router or not.
51 + *
52 + * @return true if it is area border router else false
53 + */
54 + public Boolean abr() {
55 + return abr;
56 + }
57 +
58 + @Override
59 + public void setAbr(Boolean abr) {
60 + this.abr = abr;
61 + }
62 +
63 + /**
64 + * Gets if router is autonomous system border router or not.
65 + *
66 + * @return true or false
67 + */
68 + public Boolean asbr() {
69 + return asbr;
70 + }
71 +
72 + @Override
73 + public void setAsbr(Boolean asbr) {
74 + this.asbr = asbr;
75 + }
76 +
77 + /**
78 + * Gets list of topology id's.
79 + *
80 + * @return list of topology id's
81 + */
82 + public List<Short> topologyIds() {
83 + return topologyIds;
84 + }
85 +
86 + @Override
87 + public void setTopologyIds(List<Short> topologyIds) {
88 + this.topologyIds = topologyIds;
89 + }
90 +
91 + /**
92 + * Gets list of ipv6 router id's.
93 + *
94 + * @return list of ipv6 router id's
95 + */
96 + public List<Ip6Address> ipv6RouterIds() {
97 + return ipv6RouterIds;
98 + }
99 +
100 + @Override
101 + public void setIpv6RouterIds(List<Ip6Address> ipv6RouterIds) {
102 + this.ipv6RouterIds = ipv6RouterIds;
103 + }
104 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.controller.impl;
17 +
18 +import org.onlab.packet.Ip4Address;
19 +import org.onlab.packet.Ip6Address;
20 +import org.onlab.util.Bandwidth;
21 +import org.onosproject.ospf.controller.OspfLinkTed;
22 +
23 +import java.util.ArrayList;
24 +import java.util.List;
25 +
26 +/**
27 + * Implements OSPF Link Traffic engineering details.
28 + */
29 +public class OspfLinkTedImpl implements OspfLinkTed {
30 +
31 +
32 + Bandwidth maximumLink;
33 + List<Bandwidth> maxUnResBandwidth = new ArrayList<>();
34 + Bandwidth maxReserved;
35 + Integer teMetric;
36 + List<Ip4Address> ipv4LocRouterId = new ArrayList<>();
37 + List<Ip6Address> ipv6LocRouterId = new ArrayList<>();
38 + List<Ip4Address> ipv4RemRouterId = new ArrayList<>();
39 + List<Ip6Address> ipv6RemRouterId = new ArrayList<>();
40 +
41 +
42 + /**
43 + * Gets maximum link.
44 + *
45 + * @return maximum link
46 + */
47 + public Bandwidth maximumLink() {
48 + return maximumLink;
49 + }
50 +
51 + /**
52 + * Sets maximum link.
53 + *
54 + * @param maximumLink maximum link
55 + */
56 + public void setMaximumLink(Bandwidth maximumLink) {
57 + this.maximumLink = maximumLink;
58 + }
59 +
60 + /**
61 + * Gets list of IPv6 remote router id.
62 + *
63 + * @return list of IPv6 remote router id
64 + */
65 + public List<Ip6Address> ipv6RemRouterId() {
66 + return ipv6RemRouterId;
67 + }
68 +
69 +
70 + /**
71 + * Sets list of IPv6 remote router id.
72 + *
73 + * @param ipv6RemRouterId IPv6 remote router id
74 + */
75 + public void setIpv6RemRouterId(List<Ip6Address> ipv6RemRouterId) {
76 + this.ipv6RemRouterId = ipv6RemRouterId;
77 + }
78 +
79 + /**
80 + * Gets list of IPv4 remote router id.
81 + *
82 + * @return list of IPv4 remote router id
83 + */
84 + public List<Ip4Address> ipv4RemRouterId() {
85 + return ipv4RemRouterId;
86 + }
87 +
88 + /**
89 + * Sets IPv4 remote router id.
90 + *
91 + * @param ipv4RemRouterId IPv4 remote router id
92 + */
93 + public void setIpv4RemRouterId(List<Ip4Address> ipv4RemRouterId) {
94 + this.ipv4RemRouterId = ipv4RemRouterId;
95 + }
96 +
97 + /**
98 + * Gets list of IPv6 local router id.
99 + *
100 + * @return list of IPv6 local router id
101 + */
102 + public List<Ip6Address> ipv6LocRouterId() {
103 + return ipv6LocRouterId;
104 + }
105 +
106 + /**
107 + * Sets list of IPv6 local router id.
108 + *
109 + * @param ipv6LocRouterId IPv6 local router id
110 + */
111 + public void setIpv6LocRouterId(List<Ip6Address> ipv6LocRouterId) {
112 + this.ipv6LocRouterId = ipv6LocRouterId;
113 + }
114 +
115 + /**
116 + * Gets list of IPv4 local router id.
117 + *
118 + * @return list of IPv4 local router id
119 + */
120 + public List<Ip4Address> ipv4LocRouterId() {
121 + return ipv4LocRouterId;
122 + }
123 +
124 + /**
125 + * Sets list of IPv4 local router id.
126 + *
127 + * @param ipv4LocRouterId IPv4 local router id
128 + */
129 + public void setIpv4LocRouterId(List<Ip4Address> ipv4LocRouterId) {
130 + this.ipv4LocRouterId = ipv4LocRouterId;
131 + }
132 +
133 + /**
134 + * Gets traffic engineering metric.
135 + *
136 + * @return traffic engineering metric
137 + */
138 + public Integer teMetric() {
139 + return teMetric;
140 + }
141 +
142 + /**
143 + * Sets traffic engineering metric.
144 + *
145 + * @param teMetric Traffic engineering metric
146 + */
147 + public void setTeMetric(Integer teMetric) {
148 + this.teMetric = teMetric;
149 + }
150 +
151 + /**
152 + * Gets maximum bandwidth reserved.
153 + *
154 + * @return maximum bandwidth reserved
155 + */
156 + public Bandwidth maxReserved() {
157 + return maxReserved;
158 + }
159 +
160 + /**
161 + * Sets maximum bandwidth reserved.
162 + *
163 + * @param maxReserved maximum bandwidth reserved
164 + */
165 + public void setMaxReserved(Bandwidth maxReserved) {
166 + this.maxReserved = maxReserved;
167 + }
168 +
169 + /**
170 + * Gets list of maximum unreserved bandwidth.
171 + *
172 + * @return list of maximum unreserved bandwidth
173 + */
174 + public List<Bandwidth> maxUnResBandwidth() {
175 + return maxUnResBandwidth;
176 + }
177 +
178 + /**
179 + * Sets ist of maximum unreserved bandwidth.
180 + *
181 + * @param bandwidth maximum unreserved bandwidth
182 + */
183 + public void setMaxUnResBandwidth(Bandwidth bandwidth) {
184 + this.maxUnResBandwidth.add(bandwidth);
185 + }
186 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.controller.impl;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.channel.Channel;
20 +import org.jboss.netty.channel.ChannelHandlerContext;
21 +import org.jboss.netty.handler.codec.frame.FrameDecoder;
22 +import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
23 +import org.onosproject.ospf.protocol.ospfpacket.OspfMessageReader;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import java.util.LinkedList;
28 +import java.util.List;
29 +
30 +/**
31 + * Decodes an OSPF message from a Channel, for use in a netty pipeline.
32 + */
33 +public class OspfMessageDecoder extends FrameDecoder {
34 +
35 + private static final Logger log = LoggerFactory.getLogger(OspfMessageDecoder.class);
36 +
37 + @Override
38 + protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer channelBuffer) throws Exception {
39 + log.debug("OspfMessageDecoder::Message received <:> length {}", channelBuffer.readableBytes());
40 + log.debug("channelBuffer.readableBytes - decode {}", channelBuffer.readableBytes());
41 + if (!channel.isConnected()) {
42 + log.info("Channel is not connected.");
43 + return null;
44 + }
45 +
46 + OspfMessageReader messageReader = new OspfMessageReader();
47 + List<OspfMessage> ospfMessageList = new LinkedList<>();
48 +
49 + while (channelBuffer.readableBytes() > 0) {
50 + OspfMessage message = messageReader.readFromBuffer(channelBuffer);
51 + if (message != null) {
52 + ospfMessageList.add(message);
53 + }
54 + }
55 +
56 + return ospfMessageList;
57 + }
58 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.ospf.controller.impl;
18 +
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.jboss.netty.channel.Channel;
21 +import org.jboss.netty.channel.ChannelHandlerContext;
22 +import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
23 +import org.onosproject.ospf.controller.OspfInterface;
24 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
25 +import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
26 +import org.onosproject.ospf.protocol.ospfpacket.OspfMessageWriter;
27 +import org.onosproject.ospf.protocol.util.OspfInterfaceState;
28 +import org.onosproject.ospf.protocol.util.OspfUtil;
29 +import org.slf4j.Logger;
30 +import org.slf4j.LoggerFactory;
31 +
32 +/**
33 + * Encodes an OSPF message for output into a ChannelBuffer, for use in a netty pipeline.
34 + */
35 +public class OspfMessageEncoder extends OneToOneEncoder {
36 +
37 + private static final Logger log = LoggerFactory.getLogger(OspfMessageEncoder.class);
38 + private OspfInterface ospfInterface;
39 +
40 +
41 + /**
42 + * Constructor.
43 + */
44 + OspfMessageEncoder() {
45 + }
46 +
47 + /**
48 + * Constructor to initialize instance.
49 + */
50 + OspfMessageEncoder(OspfInterface ospfInterface) {
51 + this.ospfInterface = ospfInterface;
52 + }
53 +
54 + @Override
55 + protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
56 +
57 + log.debug("Encoding ospfMessage...!!!");
58 + if (!(msg instanceof OspfMessage)) {
59 + log.debug("Invalid msg.");
60 + return msg;
61 + }
62 +
63 + OspfMessage ospfMessage = (OspfMessage) msg;
64 + OspfMessageWriter messageWriter = new OspfMessageWriter();
65 + if (((OspfInterfaceImpl) ospfInterface).state().equals(OspfInterfaceState.POINT2POINT)) {
66 + ospfMessage.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
67 + }
68 + ChannelBuffer buf = messageWriter.writeToBuffer(ospfMessage,
69 + ((OspfInterfaceImpl) ospfInterface).state().value(),
70 + ospfInterface.interfaceType());
71 + log.info("OspfMessageEncoder sending packet of lenght {}", buf.readableBytes());
72 + log.debug("OspfMessageEncoder sending packet of lenght {}", buf.readableBytes());
73 + log.debug("Sending {} Message to {}, Length :: {}, <=> {}", ospfMessage.ospfMessageType(),
74 + ospfMessage.destinationIp(), buf.readableBytes(), buf.array());
75 +
76 + return buf;
77 + }
78 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 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.controller.impl;
17 +
18 +import org.jboss.netty.channel.ChannelPipeline;
19 +import org.jboss.netty.channel.ChannelPipelineFactory;
20 +import org.jboss.netty.channel.Channels;
21 +import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
22 +import org.jboss.netty.util.ExternalResourceReleasable;
23 +import org.jboss.netty.util.HashedWheelTimer;
24 +import org.jboss.netty.util.Timer;
25 +import org.onosproject.ospf.controller.OspfArea;
26 +import org.onosproject.ospf.controller.OspfInterface;
27 +
28 +/**
29 + * Creates a ChannelPipeline for a server-side OSPF channel.
30 + */
31 +public class OspfPipelineFactory implements ChannelPipelineFactory, ExternalResourceReleasable {
32 +
33 + private static final Timer TIMER = new HashedWheelTimer();
34 + private Controller controller;
35 + private ReadTimeoutHandler readTimeoutHandler;
36 + private OspfArea ospfArea;
37 + private OspfInterface ospfInterface;
38 + private int holdTime = 120 * 1000;
39 +
40 + /**
41 + * Creates an instance of OSPF pipeline factory.
42 + *
43 + * @param controller controller instance.
44 + * @param ospfArea OSPF area instance.
45 + * @param ospfInterface OSPF interface instance.
46 + */
47 + public OspfPipelineFactory(Controller controller, OspfArea ospfArea, OspfInterface ospfInterface) {
48 + super();
49 + this.controller = controller;
50 + this.ospfArea = ospfArea;
51 + this.ospfInterface = ospfInterface;
52 + readTimeoutHandler = new ReadTimeoutHandler(TIMER, holdTime);
53 + }
54 +
55 + @Override
56 + public ChannelPipeline getPipeline() throws Exception {
57 + OspfInterfaceChannelHandler interfaceHandler = new OspfInterfaceChannelHandler(
58 + controller, ospfArea, ospfInterface);
59 +
60 + ChannelPipeline pipeline = Channels.pipeline();
61 + pipeline.addLast("encoder", new OspfMessageEncoder(ospfInterface));
62 + pipeline.addLast("decoder", new OspfMessageDecoder());
63 + pipeline.addLast("holdTime", readTimeoutHandler);
64 + pipeline.addLast("interfacehandler", interfaceHandler);
65 +
66 + return pipeline;
67 + }
68 +
69 + @Override
70 + public void releaseExternalResources() {
71 + TIMER.stop();
72 + }
73 +
74 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 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.ospf.controller.impl;
18 +
19 +import org.onlab.packet.Ip4Address;
20 +import org.onosproject.ospf.controller.OspfDeviceTed;
21 +import org.onosproject.ospf.controller.OspfRouter;
22 +
23 +/**
24 + * Representation of an OSPF Router.
25 + */
26 +public class OspfRouterImpl implements OspfRouter {
27 +
28 + private Ip4Address routerIp;
29 + private Ip4Address areaIdOfInterface;
30 + private Ip4Address neighborRouterId;
31 + private Ip4Address interfaceId;
32 + private OspfDeviceTed deviceTed;
33 + private boolean isOpaque;
34 + private boolean isDr;
35 +
36 + /**
37 + * Gets IP address of the Router.
38 + *
39 + * @return IP address router
40 + */
41 + public Ip4Address routerIp() {
42 + return routerIp;
43 + }
44 +
45 + /**
46 + * Sets IP address of the Router.
47 + */
48 + public void setRouterIp(Ip4Address routerIp) {
49 + this.routerIp = routerIp;
50 + }
51 +
52 + /**
53 + * Gets the area id of this device.
54 + *
55 + * @return the area id od this device
56 + */
57 + public Ip4Address areaIdOfInterface() {
58 + return areaIdOfInterface;
59 + }
60 +
61 + /**
62 + * Sets the area id for this device.
63 + */
64 + public void setAreaIdOfInterface(Ip4Address areaIdOfInterface) {
65 + this.areaIdOfInterface = areaIdOfInterface;
66 + }
67 +
68 + /**
69 + * Gets IP address of the interface.
70 + *
71 + * @return IP address of the interface
72 + */
73 + public Ip4Address interfaceId() {
74 + return interfaceId;
75 + }
76 +
77 + /**
78 + * Gets IP address of the interface.
79 + *
80 + * @param interfaceId IP address of the interface
81 + */
82 + public void setInterfaceId(Ip4Address interfaceId) {
83 + this.interfaceId = interfaceId;
84 + }
85 +
86 + /**
87 + * Gets List of the device ted.
88 + *
89 + * @return List of the device ted.
90 + */
91 + public OspfDeviceTed deviceTed() {
92 + return deviceTed;
93 + }
94 +
95 + /**
96 + * Sets List of the device TED.
97 + *
98 + * @param deviceTed of the device TED.
99 + */
100 + public void setDeviceTed(OspfDeviceTed deviceTed) {
101 + this.deviceTed = deviceTed;
102 + }
103 +
104 + /**
105 + * Gets boolean value.
106 + *
107 + * @return boolean value.
108 + */
109 + public boolean isOpaque() {
110 + return isOpaque;
111 + }
112 +
113 + /**
114 + * Sets boolean value.
115 + *
116 + * @param opaque true if opaque else false
117 + */
118 + public void setOpaque(boolean opaque) {
119 + isOpaque = opaque;
120 + }
121 +
122 + /**
123 + * Gets neighbor's Router id.
124 + *
125 + * @return neighbor's Router id
126 + */
127 + public Ip4Address neighborRouterId() {
128 + return neighborRouterId;
129 + }
130 +
131 + /**
132 + * Sets neighbor's Router id.
133 + *
134 + * @param advertisingRouterId neighbor's Router id
135 + */
136 + public void setNeighborRouterId(Ip4Address advertisingRouterId) {
137 + this.neighborRouterId = advertisingRouterId;
138 + }
139 +
140 + /**
141 + * Gets if DR or not.
142 + *
143 + * @return true if DR else false
144 + */
145 + public boolean isDr() {
146 + return isDr;
147 + }
148 +
149 + /**
150 + * Sets dr or not.
151 + *
152 + * @param dr true if DR else false
153 + */
154 + public void setDr(boolean dr) {
155 + isDr = dr;
156 + }
157 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 +* Copyright 2016 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.controller.impl;
17 +
18 +import org.onlab.packet.Ip4Address;
19 +import org.onlab.util.Bandwidth;
20 +import org.onosproject.ospf.controller.DeviceInformation;
21 +import org.onosproject.ospf.controller.LinkInformation;
22 +import org.onosproject.ospf.controller.OspfArea;
23 +import org.onosproject.ospf.controller.OspfInterface;
24 +import org.onosproject.ospf.controller.OspfLinkTed;
25 +import org.onosproject.ospf.controller.OspfLsa;
26 +import org.onosproject.ospf.controller.OspfLsaType;
27 +import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
28 +import org.onosproject.ospf.protocol.lsa.linksubtype.LinkSubType;
29 +import org.onosproject.ospf.protocol.lsa.linksubtype.LocalInterfaceIpAddress;
30 +import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumBandwidth;
31 +import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumReservableBandwidth;
32 +import org.onosproject.ospf.protocol.lsa.linksubtype.RemoteInterfaceIpAddress;
33 +import org.onosproject.ospf.protocol.lsa.linksubtype.TrafficEngineeringMetric;
34 +import org.onosproject.ospf.protocol.lsa.linksubtype.UnreservedBandwidth;
35 +import org.onosproject.ospf.protocol.lsa.subtypes.OspfLsaLink;
36 +import org.onosproject.ospf.protocol.lsa.tlvtypes.LinkTlv;
37 +import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
38 +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
39 +import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
40 +import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
41 +import org.slf4j.Logger;
42 +import org.slf4j.LoggerFactory;
43 +
44 +import java.util.ArrayList;
45 +import java.util.HashMap;
46 +import java.util.HashSet;
47 +import java.util.Iterator;
48 +import java.util.LinkedHashMap;
49 +import java.util.List;
50 +import java.util.Map;
51 +import java.util.Set;
52 +
53 +/**
54 + * Represents device and link topology information.
55 + */
56 +public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
57 +
58 + private static final Logger log = LoggerFactory.getLogger(TopologyForDeviceAndLinkImpl.class);
59 + private Map<String, DeviceInformation> deviceInformationMap = new LinkedHashMap();
60 + private Map<String, DeviceInformation> deviceInformationMapToDelete = new LinkedHashMap();
61 + private HashMap<String, Set<OspfLsaLink>> deviceAndLinkInformation = new HashMap();
62 + private HashMap<String, OspfLinkTed> ospfLinkTedHashMap = new LinkedHashMap();
63 + private Ip4Address drRouter = Ip4Address.valueOf("0.0.0.0");
64 + private Ip4Address drRouterOld = Ip4Address.valueOf("0.0.0.0");
65 + private Ip4Address adRouterId = Ip4Address.valueOf("0.0.0.0");
66 + private Map<String, LinkInformation> linkInformationMap = new LinkedHashMap();
67 + private List<String> toRemove = new ArrayList<>();
68 +
69 + /**
70 + * Gets device information.
71 + *
72 + * @return device information
73 + */
74 + public Map<String, DeviceInformation> deviceInformationMap() {
75 + return deviceInformationMap;
76 + }
77 +
78 + /**
79 + * Sets device information.
80 + *
81 + * @param key key used to add in map
82 + * @param deviceInformationMap device information instance
83 + */
84 + public void setDeviceInformationMap(String key, DeviceInformation deviceInformationMap) {
85 + if (deviceInformationMap != null) {
86 + this.deviceInformationMap.put(key, deviceInformationMap);
87 + }
88 +
89 + }
90 +
91 + /**
92 + * Gets device information.
93 + *
94 + * @return device information to delete from core
95 + */
96 + public Map<String, DeviceInformation> deviceInformationMapToDelete() {
97 + return deviceInformationMapToDelete;
98 + }
99 +
100 + /**
101 + * Sets device information for removal.
102 + *
103 + * @param key ket used to add in map
104 + * @param deviceInformationMapToDelete map from device information to remove
105 + */
106 + public void setDeviceInformationMapToDelete(String key,
107 + DeviceInformation deviceInformationMapToDelete) {
108 + if (deviceInformationMapToDelete != null) {
109 + this.deviceInformationMapToDelete.put(key, deviceInformationMapToDelete);
110 + }
111 + }
112 +
113 + /**
114 + * Removes Device Information.
115 + *
116 + * @param key ket used to remove from map
117 + */
118 + public void removeDeviceInformationMapFromDeleteMap(String key) {
119 + removeDeviceInformationMap(key);
120 + if (this.deviceInformationMapToDelete.containsKey(key)) {
121 + this.deviceInformationMapToDelete.remove(key);
122 + }
123 + }
124 +
125 + /**
126 + * Gets Device Information.
127 + *
128 + * @param key key to store in map
129 + * @return Device Information
130 + */
131 + public DeviceInformation deviceInformation(String key) {
132 + DeviceInformation deviceInformation = this.deviceInformationMap.get(key);
133 + return deviceInformation;
134 + }
135 +
136 + /**
137 + * Removes Device Information from map.
138 + *
139 + * @param key key used to remove from map
140 + */
141 + public void removeDeviceInformationMap(String key) {
142 + if (this.deviceInformationMap.containsKey(key)) {
143 + this.deviceInformationMap.remove(key);
144 + }
145 + }
146 +
147 + /**
148 + * Gets link information as map.
149 + *
150 + * @return link information as map
151 + */
152 + public Map<String, LinkInformation> linkInformationMap() {
153 + return linkInformationMap;
154 + }
155 +
156 + /**
157 + * Sets link information in map.
158 + *
159 + * @param key key used to add in map
160 + * @param linkInformationMap link information instance
161 + */
162 + public void setLinkInformationMap(String key, LinkInformation linkInformationMap) {
163 + if (!this.linkInformationMap.containsKey(key)) {
164 + this.linkInformationMap.put(key, linkInformationMap);
165 + }
166 + }
167 +
168 + /**
169 + * Removes Link Information from map.
170 + *
171 + * @param key key used to remove from map
172 + */
173 + public void removeLinkInformationMap(String key) {
174 + if (this.linkInformationMap.containsKey(key)) {
175 + this.linkInformationMap.remove(key);
176 + }
177 + }
178 +
179 +
180 + /**
181 + * Gets OSPF Link TED details from the map.
182 + *
183 + * @param key key used to retreive from map
184 + * @return OSPF link ted instance
185 + */
186 + public OspfLinkTed getOspfLinkTedHashMap(String key) {
187 + OspfLinkTed ospfLinkTed = ospfLinkTedHashMap.get(key);
188 + return ospfLinkTed;
189 + }
190 +
191 + /**
192 + * Adds device information to map.
193 + *
194 + * @param ospfLsa OSPF LSA instance
195 + * @param ospfInterface OSPF interface instance
196 + * @param ospfArea OSPF area instance
197 + */
198 + public void addLocalDevice(OspfLsa ospfLsa, OspfInterface ospfInterface, OspfArea ospfArea) {
199 + if (ospfLsa.getOspfLsaType().equals(OspfLsaType.ROUTER)) {
200 + createDeviceAndLinkFromRouterLsa(ospfLsa, ospfArea);
201 + } else if (ospfLsa.getOspfLsaType().equals(OspfLsaType.NETWORK)) {
202 + createDeviceAndLinkFromNetworkLsa(ospfLsa, ospfArea);
203 + } else if (ospfLsa.getOspfLsaType().equals(OspfLsaType.AREA_LOCAL_OPAQUE_LSA)) {
204 + createDeviceAndLinkFromOpaqueLsa(ospfLsa, ospfArea);
205 + }
206 + }
207 +
208 + /**
209 + * Creates device object from parameters.
210 + *
211 + * @param alreadyCreated device already created or not
212 + * @param deviceId device id
213 + * @param neighborId neighbor's id
214 + * @param routerId router's id
215 + * @param interfaceId interface id
216 + * @param areaId area id
217 + * @param isDr true if router is DR else false
218 + */
219 + private DeviceInformation createDeviceInformation(boolean alreadyCreated, Ip4Address deviceId,
220 + Ip4Address neighborId, Ip4Address routerId,
221 + Ip4Address interfaceId, Ip4Address areaId,
222 + boolean isDr) {
223 + DeviceInformation deviceInformation = new DeviceInformationImpl();
224 + deviceInformation.setAlreadyCreated(alreadyCreated);
225 + deviceInformation.setDeviceId(deviceId);
226 + deviceInformation.setNeighborId(neighborId);
227 + deviceInformation.setRouterId(routerId);
228 + deviceInformation.addInterfaceId(interfaceId);
229 + deviceInformation.setAreaId(areaId);
230 + deviceInformation.setDr(isDr);
231 + return deviceInformation;
232 + }
233 +
234 + /**
235 + * Creates Device and Link instance from the RouterLsa parameters.
236 + *
237 + * @param ospfLsa OSPF LSA instance
238 + * @param ospfArea OSPF area
239 + */
240 + private void createDeviceAndLinkFromRouterLsa(OspfLsa ospfLsa, OspfArea ospfArea) {
241 + RouterLsa routerLsa = (RouterLsa) ospfLsa;
242 + List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink();
243 + Iterator iterator = ospfLsaLinkList.iterator();
244 + Ip4Address advertisingRouterId = routerLsa.advertisingRouter();
245 + adRouterId = advertisingRouterId;
246 + while (iterator.hasNext()) {
247 + OspfLsaLink ospfLsaLink = (OspfLsaLink) iterator.next();
248 + Ip4Address linkId = Ip4Address.valueOf(ospfLsaLink.linkId());
249 + Ip4Address linkData = Ip4Address.valueOf(ospfLsaLink.linkData());
250 + if (ospfLsaLink.linkType() == 1) {
251 + if ((advertisingRouterId.equals(ospfArea.routerId())) || (linkId.equals(ospfArea.routerId()))) {
252 + System.out.println("OspfInterface information will not display in web ");
253 + } else {
254 + removeDevice(advertisingRouterId);
255 + removeLinks(advertisingRouterId);
256 + DeviceInformation deviceInformationPointToPoint =
257 + createDeviceInformation(false, linkId, linkId, advertisingRouterId, linkData,
258 + ospfArea.areaId(), false);
259 + String key = "device:" + advertisingRouterId;
260 + setDeviceInformationMap(key, deviceInformationPointToPoint);
261 + String linkIdKey = "linkId:" + advertisingRouterId + "-" + linkId;
262 + addLocalLink(linkIdKey, linkData, advertisingRouterId, linkId, true, false);
263 + }
264 + } else if (ospfLsaLink.linkType() == 2) {
265 +
266 + if ((advertisingRouterId.equals(ospfArea.routerId())) || (linkId.equals(ospfArea.routerId()))) {
267 + log.debug("OspfInterface information will not display in web ");
268 + } else {
269 + if (linkId.equals(linkData)) {
270 + if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
271 + log.debug("drRouter not elected {} ", drRouter.toString());
272 + } else {
273 + if (drRouterOld.equals(linkId)) {
274 + log.debug("drRouterOld same as link id {} ", drRouterOld.toString());
275 + } else {
276 + String key = "device:" + drRouterOld;
277 + DeviceInformation deviceInformation1 = deviceInformation(key);
278 + if (deviceInformation1 != null) {
279 + deviceInformation1.setAlreadyCreated(true);
280 + setDeviceInformationMapToDelete(key, deviceInformation1);
281 + String linkIdKey = "linkId:" + linkId + "-" + deviceInformation1.neighborId();
282 + addLocalLink(linkIdKey, linkData, linkId, deviceInformation1.neighborId(),
283 + true, false);
284 + String linkIdKey1 = "linkId:" + linkId + "-" + advertisingRouterId;
285 + addLocalLink(linkIdKey1, linkData, linkId, advertisingRouterId, true, false);
286 + } else {
287 + DeviceInformation deviceInformationToDelete =
288 + createDeviceInformation(true, drRouterOld, drRouterOld,
289 + drRouterOld, drRouterOld,
290 + drRouterOld, true);
291 + setDeviceInformationMapToDelete(key, deviceInformationToDelete);
292 + String linkIdKey1 = "linkId:" + linkId + "-" + advertisingRouterId;
293 + addLocalLink(linkIdKey1, linkData, linkId, advertisingRouterId, true, false);
294 + }
295 + }
296 + }
297 + drRouter = linkId;
298 + drRouterOld = linkId;
299 + DeviceInformation deviceInformationForDr =
300 + createDeviceInformation(false, linkId, advertisingRouterId, linkId, linkData,
301 + ospfArea.areaId(), true);
302 + String key = "device:" + linkId;
303 + setDeviceInformationMap(key, deviceInformationForDr);
304 + DeviceInformation deviceInformationForAdvertisingRouter =
305 + createDeviceInformation(false, linkId, advertisingRouterId, advertisingRouterId,
306 + linkData, ospfArea.areaId(), false);
307 + String key1 = "device:" + advertisingRouterId;
308 + setDeviceInformationMap(key1, deviceInformationForAdvertisingRouter);
309 + if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
310 + System.out.println("Link will not get create since dr is not valid");
311 + //Need to analysis since this place will not get Dr information
312 + String linkIdKey = "linkId:" + linkId + "-" + advertisingRouterId;
313 + addLocalLink(linkIdKey, linkData, linkId, advertisingRouterId, true, false);
314 + } else {
315 + String linkIdKey = "linkId:" + drRouter + "-" + advertisingRouterId;
316 + addLocalLink(linkIdKey, linkData, drRouter, advertisingRouterId, true, false);
317 + }
318 + } else {
319 + DeviceInformation deviceInformationDrOther =
320 + createDeviceInformation(false, linkId, linkId, advertisingRouterId,
321 + linkData, ospfArea.areaId(), false);
322 + String key = "device:" + advertisingRouterId;
323 + setDeviceInformationMap(key, deviceInformationDrOther);
324 + if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
325 + String linkIdKey = "linkId:" + linkId + "-" + advertisingRouterId;
326 + addLocalLink(linkIdKey, linkData, linkId, advertisingRouterId, true, false);
327 + } else {
328 + String linkIdKey = "linkId:" + drRouter + "-" + advertisingRouterId;
329 + addLocalLink(linkIdKey, linkData, drRouter, advertisingRouterId, true, false);
330 + }
331 + }
332 + }
333 + }
334 + }
335 + }
336 +
337 + /**
338 + * Creates Device and Link instance from the NetworkLsa parameters.
339 + *
340 + * @param ospfLsa OSPF LSA instance
341 + * @param ospfArea OSPF area instance
342 + */
343 + private void createDeviceAndLinkFromNetworkLsa(OspfLsa ospfLsa, OspfArea ospfArea) {
344 + NetworkLsa networkLsa = (NetworkLsa) ospfLsa;
345 + Ip4Address advertisingRouterId = networkLsa.networkMask();
346 + System.out.println("AdvertisingRouterId is : " + advertisingRouterId);
347 + }
348 +
349 + /**
350 + * Creates Device and Link instance from the OpaqueLsa parameters.
351 + *
352 + * @param ospfLsa OSPF LSA instance
353 + * @param ospfArea OSPF area instance
354 + */
355 + private void createDeviceAndLinkFromOpaqueLsa(OspfLsa ospfLsa, OspfArea ospfArea) {
356 + OspfLinkTed ospfLinkTed = new OspfLinkTedImpl();
357 + OpaqueLsa10 opaqueLsa10 = (OpaqueLsa10) ospfLsa;
358 + List<TopLevelTlv> topLevelTlvList = opaqueLsa10.topLevelValues();
359 + for (TopLevelTlv topLevelTlv : topLevelTlvList) {
360 + if (topLevelTlv instanceof LinkTlv) {
361 + LinkTlv linkTlv = (LinkTlv) topLevelTlv;
362 + List<LinkSubType> subTypes = linkTlv.subTlvList();
363 + for (LinkSubType type : subTypes) {
364 + if (type instanceof UnreservedBandwidth) {
365 + UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) type;
366 + List<Float> bandwidthFloatValues = unreservedBandwidth.getUnReservedBandwidthValue();
367 + List<Bandwidth> bandwidthList = new ArrayList<>();
368 + for (Float value : bandwidthFloatValues) {
369 + Bandwidth bandwidth = Bandwidth.bps((double) value);
370 + ospfLinkTed.setMaxUnResBandwidth(bandwidth);
371 + bandwidthList.add(bandwidth);
372 + }
373 + }
374 + if (type instanceof MaximumBandwidth) {
375 + MaximumBandwidth maximumBandwidth = (MaximumBandwidth) type;
376 + float maxBandValue = maximumBandwidth.getMaximumBandwidthValue();
377 + Bandwidth bandwidth = Bandwidth.bps((double) maxBandValue);
378 + ospfLinkTed.setMaximumLink(bandwidth);
379 + }
380 + if (type instanceof MaximumReservableBandwidth) {
381 + MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) type;
382 + float maxResBandValue = maximumReservableBandwidth.getMaximumBandwidthValue();
383 + Bandwidth bandwidth = Bandwidth.bps((double) maxResBandValue);
384 + ospfLinkTed.setMaxReserved(bandwidth);
385 + }
386 + if (type instanceof TrafficEngineeringMetric) {
387 + TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) type;
388 + long teMetric = trafficEngineeringMetric.getTrafficEngineeringMetricValue();
389 + ospfLinkTed.setTeMetric((Integer) (int) teMetric);
390 + }
391 + if (type instanceof LocalInterfaceIpAddress) {
392 + LocalInterfaceIpAddress localInterfaceIpAddress = (LocalInterfaceIpAddress) type;
393 + List<String> stringValue = localInterfaceIpAddress.getLocalInterfaceIPAddress();
394 + List<Ip4Address> localIp4Address = new ArrayList<>();
395 + for (String value : stringValue) {
396 + Ip4Address ip4Address = Ip4Address.valueOf(value);
397 + localIp4Address.add(ip4Address);
398 + }
399 + ospfLinkTed.setIpv4LocRouterId(localIp4Address);
400 + }
401 + if (type instanceof RemoteInterfaceIpAddress) {
402 + RemoteInterfaceIpAddress remoteInterfaceIpAddress = (RemoteInterfaceIpAddress) type;
403 + List<String> stringValue = remoteInterfaceIpAddress.getRemoteInterfaceAddress();
404 + List<Ip4Address> remoteIp4Address = new ArrayList<>();
405 + for (String value : stringValue) {
406 + Ip4Address ip4Address = Ip4Address.valueOf(value);
407 + remoteIp4Address.add(ip4Address);
408 + }
409 + ospfLinkTed.setIpv4RemRouterId(remoteIp4Address);
410 + }
411 + }
412 + }
413 +
414 + }
415 + ospfLinkTedHashMap.put(adRouterId.toString(), ospfLinkTed);
416 + }
417 +
418 +
419 + /**
420 + * Adds link information to LinkInformationMap.
421 + *
422 + * @param advertisingRouter advertising router
423 + * @param linkData link data address
424 + * @param linkSrc link source address
425 + * @param linkDest link destination address
426 + * @param opaqueEnabled opaque enabled or not
427 + * @param linkSrcIdNotRouterId link source id or not
428 + */
429 + public void addLocalLink(String advertisingRouter, Ip4Address linkData, Ip4Address linkSrc, Ip4Address linkDest,
430 + boolean opaqueEnabled, boolean linkSrcIdNotRouterId) {
431 + String linkKey = "link:";
432 + LinkInformation linkInformation = new LinkInformationImpl();
433 + linkInformation.setLinkId(advertisingRouter);
434 + linkInformation.setLinkSourceId(linkSrc);
435 + linkInformation.setLinkDestinationId(linkDest);
436 + linkInformation.setAlreadyCreated(false);
437 + linkInformation.setLinkSrcIdNotRouterId(linkSrcIdNotRouterId);
438 + linkInformation.setInterfaceIp(linkData);
439 + if (linkDest != null) {
440 + linkInformation.setLinkSrcIdNotRouterId(false);
441 + }
442 + linkKey = linkKey + "-" + linkSrc + "-" + linkDest;
443 + setLinkInformationMap(linkKey, linkInformation);
444 + }
445 +
446 + /**
447 + * Removes links from LinkInformationMap.
448 + *
449 + * @param routerId router id
450 + */
451 + public void removeLinks(Ip4Address routerId) {
452 + Map<String, LinkInformation> linkInformationMaplocal = linkInformationMap;
453 + if (linkInformationMaplocal != null) {
454 + for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) {
455 + String key = entry.getKey();
456 + boolean check = key.contains(routerId.toString());
457 + LinkInformation linkInformation = linkInformationMap.get(key);
458 + boolean check1 = (linkInformation.linkDestinationId() == routerId) ? true : false;
459 + if (check || check1) {
460 + toRemove.add(key);
461 + }
462 + }
463 + removeLinkFromMap();
464 + }
465 + }
466 +
467 + /**
468 + * Removes Device from DeviceInformationMap.
469 + *
470 + * @param routerId router id
471 + */
472 + public void removeDevice(Ip4Address routerId) {
473 + String key = "device:" + routerId;
474 + this.deviceInformationMap.remove(key);
475 + }
476 +
477 + /**
478 + * Removes link information from Map.
479 + */
480 + private void removeLinkFromMap() {
481 + Iterator iterator = toRemove.iterator();
482 + while (iterator.hasNext()) {
483 + String key = (String) iterator.next();
484 + removeLinkInformationMap(key);
485 + }
486 + }
487 +
488 + /**
489 + * Updates the deviceAndLinkInformation list for received OSPF LSA.
490 + *
491 + * @param ospfLsa OSPF LSA instance
492 + * @param ospfArea OSPF area instance
493 + */
494 + public void updateLinkInformation(OspfLsa ospfLsa, OspfArea ospfArea) {
495 + if (ospfLsa.getOspfLsaType().equals(OspfLsaType.ROUTER)) {
496 + RouterLsa routerLsa = (RouterLsa) ospfLsa;
497 + routerLsa.lsType();
498 + List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink();
499 + for (OspfLsaLink link : ospfLsaLinkList) {
500 + if (link.linkType == 1 || link.linkType == 2) {
501 + if ((routerLsa.advertisingRouter().equals(ospfArea.routerId())) ||
502 + (link.equals(ospfArea.routerId()))) {
503 + log.debug("OspfInterface information will not display in web ");
504 + } else {
505 + String key = routerLsa.advertisingRouter() + "-" + link.linkData();
506 + Set<OspfLsaLink> linkInformations = new HashSet<>();
507 + if (deviceAndLinkInformation.containsKey(key)) {
508 + linkInformations = deviceAndLinkInformation.get(key);
509 + linkInformations.add(link);
510 + deviceAndLinkInformation.put(key, linkInformations);
511 + } else {
512 + linkInformations.add(link);
513 + deviceAndLinkInformation.put(key, linkInformations);
514 + }
515 + }
516 + }
517 + }
518 + }
519 + }
520 +
521 + /**
522 + * Gets all the router information which needs to delete from deviceList.
523 + *
524 + * @param ospfLsa OSPF LSA instance
525 + * @param ospfArea OSPF area instance
526 + * @return list of deleted router information
527 + */
528 + public List<String> getDeleteRouterInformation(OspfLsa ospfLsa, OspfArea ospfArea) {
529 + List<String> removedLinkList = new ArrayList<>();
530 + if (ospfLsa.getOspfLsaType().equals(OspfLsaType.ROUTER)) {
531 +
532 + RouterLsa routerLsa = (RouterLsa) ospfLsa;
533 + List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink();
534 + for (OspfLsaLink link : ospfLsaLinkList) {
535 + if (link.linkType == 1 || link.linkType == 2) {
536 + if ((routerLsa.advertisingRouter().equals(ospfArea.routerId())) ||
537 + (link.equals(ospfArea.routerId()))) {
538 + log.debug("OspfInterface information will not display in web ");
539 + } else {
540 + String key = routerLsa.advertisingRouter() + "-" + link.linkData();
541 + Set<OspfLsaLink> linkInformations = deviceAndLinkInformation.get(key);
542 + if (linkInformations.contains(link)) {
543 + linkInformations.remove(link);
544 + deviceAndLinkInformation.put(key, linkInformations);
545 + }
546 + }
547 + }
548 + Set<String> keys = deviceAndLinkInformation.keySet();
549 + for (String key : keys) {
550 + Set<OspfLsaLink> linkInformations = deviceAndLinkInformation.get(key);
551 + for (OspfLsaLink link1 : linkInformations) {
552 + String removedLink = link1.linkId();
553 + removedLinkList.add(removedLink);
554 + }
555 + }
556 + }
557 + }
558 + return removedLinkList;
559 + }
560 +}
...\ No newline at end of file ...\ No newline at end of file