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