Committed by
Gerrit Code Review
ONOS-4086 to ONOS-4091, ONOS-4098 to ONOS-4100:ISIS controller implementation
Change-Id: I7be52805652fe762baf808515401d6b5042b2aa5
Showing
32 changed files
with
3757 additions
and
55 deletions
| ... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.isis.controller; | 16 | package org.onosproject.isis.controller; |
| 17 | 17 | ||
| 18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 18 | import org.onosproject.isis.controller.topology.IsisRouterListener; | 19 | import org.onosproject.isis.controller.topology.IsisRouterListener; |
| 19 | 20 | ||
| 20 | import java.util.List; | 21 | import java.util.List; |
| ... | @@ -41,18 +42,9 @@ public interface IsisController { | ... | @@ -41,18 +42,9 @@ public interface IsisController { |
| 41 | /** | 42 | /** |
| 42 | * Updates configuration of processes. | 43 | * Updates configuration of processes. |
| 43 | * | 44 | * |
| 44 | - * @param processes process instance to update | 45 | + * @param processesNode json node represents process |
| 45 | */ | 46 | */ |
| 46 | - void updateConfig(List<IsisProcess> processes); | 47 | + void updateConfig(JsonNode processesNode); |
| 47 | - | ||
| 48 | - /** | ||
| 49 | - * Deletes configuration parameters. | ||
| 50 | - * | ||
| 51 | - * @param processes list of process instance | ||
| 52 | - * @param attribute string key which deletes the particular node or element | ||
| 53 | - * from the controller | ||
| 54 | - */ | ||
| 55 | - void deleteConfig(List<IsisProcess> processes, String attribute); | ||
| 56 | 48 | ||
| 57 | /** | 49 | /** |
| 58 | * Gets the all configured processes. | 50 | * Gets the all configured processes. | ... | ... |
| ... | @@ -230,6 +230,13 @@ public interface IsisInterface { | ... | @@ -230,6 +230,13 @@ public interface IsisInterface { |
| 230 | void setPriority(int priority); | 230 | void setPriority(int priority); |
| 231 | 231 | ||
| 232 | /** | 232 | /** |
| 233 | + * Returns hello interval. | ||
| 234 | + * | ||
| 235 | + * @return hello interval | ||
| 236 | + */ | ||
| 237 | + public int helloInterval(); | ||
| 238 | + | ||
| 239 | + /** | ||
| 233 | * Sets hello interval. | 240 | * Sets hello interval. |
| 234 | * | 241 | * |
| 235 | * @param helloInterval hello interval | 242 | * @param helloInterval hello interval |
| ... | @@ -301,4 +308,11 @@ public interface IsisInterface { | ... | @@ -301,4 +308,11 @@ public interface IsisInterface { |
| 301 | * @param circuitId circuit ID | 308 | * @param circuitId circuit ID |
| 302 | */ | 309 | */ |
| 303 | void setCircuitId(String circuitId); | 310 | void setCircuitId(String circuitId); |
| 311 | + | ||
| 312 | + /** | ||
| 313 | + * Removes neighbor from the interface neighbor map. | ||
| 314 | + * | ||
| 315 | + * @param isisNeighbor ISIS neighbor instance | ||
| 316 | + */ | ||
| 317 | + void removeNeighbor(IsisNeighbor isisNeighbor); | ||
| 304 | } | 318 | } | ... | ... |
| ... | @@ -98,4 +98,14 @@ public interface IsisNeighbor { | ... | @@ -98,4 +98,14 @@ public interface IsisNeighbor { |
| 98 | * @param holdingTime Holding time of neighbor | 98 | * @param holdingTime Holding time of neighbor |
| 99 | */ | 99 | */ |
| 100 | void setHoldingTime(int holdingTime); | 100 | void setHoldingTime(int holdingTime); |
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Starts the inactivity timer for this neighbor. | ||
| 104 | + */ | ||
| 105 | + void startInactivityTimeCheck(); | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * Stops the inactivity timer. | ||
| 109 | + */ | ||
| 110 | + void stopInactivityTimeCheck(); | ||
| 101 | } | 111 | } | ... | ... |
| ... | @@ -23,6 +23,13 @@ import java.util.List; | ... | @@ -23,6 +23,13 @@ import java.util.List; |
| 23 | public interface IsisProcess { | 23 | public interface IsisProcess { |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | + * Returns process ID. | ||
| 27 | + * | ||
| 28 | + * @return process ID | ||
| 29 | + */ | ||
| 30 | + public String processId(); | ||
| 31 | + | ||
| 32 | + /** | ||
| 26 | * Sets process ID. | 33 | * Sets process ID. |
| 27 | * | 34 | * |
| 28 | * @param processId process ID | 35 | * @param processId process ID | ... | ... |
protocols/isis/ctl/pom.xml
0 → 100644
| 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-isis</artifactId> | ||
| 24 | + <version>1.6.0-SNAPSHOT</version> | ||
| 25 | + <relativePath>../pom.xml</relativePath> | ||
| 26 | + </parent> | ||
| 27 | + | ||
| 28 | + <artifactId>onos-isis-ctl</artifactId> | ||
| 29 | + <packaging>bundle</packaging> | ||
| 30 | + | ||
| 31 | + <description>ONOS ISIS controller subsystem API</description> | ||
| 32 | + | ||
| 33 | + <dependencies> | ||
| 34 | + <dependency> | ||
| 35 | + <groupId>org.onosproject</groupId> | ||
| 36 | + <artifactId>onos-isis-isisio</artifactId> | ||
| 37 | + <version>${project.version}</version> | ||
| 38 | + </dependency> | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>org.apache.felix</groupId> | ||
| 41 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
| 42 | + </dependency> | ||
| 43 | + <dependency> | ||
| 44 | + <groupId>org.osgi</groupId> | ||
| 45 | + <artifactId>org.osgi.compendium</artifactId> | ||
| 46 | + </dependency> | ||
| 47 | + <dependency> | ||
| 48 | + <groupId>org.easymock</groupId> | ||
| 49 | + <artifactId>easymock</artifactId> | ||
| 50 | + </dependency> | ||
| 51 | + </dependencies> | ||
| 52 | + | ||
| 53 | + <build> | ||
| 54 | + <plugins> | ||
| 55 | + <plugin> | ||
| 56 | + <groupId>org.apache.felix</groupId> | ||
| 57 | + <artifactId>maven-scr-plugin</artifactId> | ||
| 58 | + </plugin> | ||
| 59 | + </plugins> | ||
| 60 | + </build> | ||
| 61 | + | ||
| 62 | + | ||
| 63 | +</project> |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 19 | +import org.jboss.netty.bootstrap.ClientBootstrap; | ||
| 20 | +import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor; | ||
| 21 | +import org.jboss.netty.channel.ChannelFuture; | ||
| 22 | +import org.jboss.netty.channel.ChannelPipelineFactory; | ||
| 23 | +import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory; | ||
| 24 | +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; | ||
| 25 | +import org.onlab.packet.Ip4Address; | ||
| 26 | +import org.onlab.packet.MacAddress; | ||
| 27 | +import org.onlab.packet.TpPort; | ||
| 28 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 29 | +import org.onosproject.isis.controller.IsisNetworkType; | ||
| 30 | +import org.onosproject.isis.controller.IsisProcess; | ||
| 31 | +import org.onosproject.isis.controller.IsisRouterType; | ||
| 32 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 33 | +import org.slf4j.Logger; | ||
| 34 | +import org.slf4j.LoggerFactory; | ||
| 35 | + | ||
| 36 | +import java.net.InetAddress; | ||
| 37 | +import java.net.InetSocketAddress; | ||
| 38 | +import java.net.UnknownHostException; | ||
| 39 | +import java.util.ArrayList; | ||
| 40 | +import java.util.List; | ||
| 41 | +import java.util.concurrent.Executors; | ||
| 42 | + | ||
| 43 | +import static org.onlab.util.Tools.groupedThreads; | ||
| 44 | + | ||
| 45 | +/** | ||
| 46 | + * Representation of an ISIS controller. | ||
| 47 | + */ | ||
| 48 | +public class Controller { | ||
| 49 | + protected static final int BUFFER_SIZE = 4 * 1024 * 1024; | ||
| 50 | + private static final Logger log = LoggerFactory.getLogger(Controller.class); | ||
| 51 | + private final int peerWorkerThreads = 16; | ||
| 52 | + private List<IsisProcess> processes = null; | ||
| 53 | + private IsisChannelHandler isisChannelHandler; | ||
| 54 | + private NioClientSocketChannelFactory peerExecFactory; | ||
| 55 | + private ClientBootstrap peerBootstrap = null; | ||
| 56 | + private TpPort isisPort = TpPort.tpPort(IsisConstants.SPORT); | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * Deactivates ISIS controller. | ||
| 60 | + */ | ||
| 61 | + public void isisDeactivate() { | ||
| 62 | + peerExecFactory.shutdown(); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * Updates the processes configuration. | ||
| 67 | + * | ||
| 68 | + * @param jsonNode json node instance | ||
| 69 | + * @throws Exception might throws parse exception | ||
| 70 | + */ | ||
| 71 | + public void updateConfig(JsonNode jsonNode) throws Exception { | ||
| 72 | + log.debug("Controller::UpdateConfig called"); | ||
| 73 | + byte[] configPacket = new byte[IsisConstants.CONFIG_LENGTH]; | ||
| 74 | + byte numberOfInterface = 0; // number of interfaces to configure | ||
| 75 | + | ||
| 76 | + configPacket[0] = (byte) 0xFF; // its a conf packet - identifier | ||
| 77 | + List<IsisProcess> isisProcesses = getConfig(jsonNode); | ||
| 78 | + | ||
| 79 | + for (IsisProcess isisProcess : isisProcesses) { | ||
| 80 | + log.debug("IsisProcessDetails : " + isisProcess); | ||
| 81 | + for (IsisInterface isisInterface : isisProcess.isisInterfaceList()) { | ||
| 82 | + DefaultIsisInterface isisInterfaceImpl = (DefaultIsisInterface) isisInterface; | ||
| 83 | + log.debug("IsisInterfaceDetails : " + isisInterface); | ||
| 84 | + numberOfInterface++; | ||
| 85 | + configPacket[2 * numberOfInterface] = (byte) isisInterfaceImpl.interfaceIndex(); | ||
| 86 | + if (isisInterface.networkType() == IsisNetworkType.BROADCAST && | ||
| 87 | + isisInterfaceImpl.reservedPacketCircuitType() == IsisRouterType.L1.value()) { | ||
| 88 | + configPacket[(2 * numberOfInterface) + 1] = (byte) 0; | ||
| 89 | + } else if (isisInterface.networkType() == IsisNetworkType.BROADCAST && | ||
| 90 | + isisInterfaceImpl.reservedPacketCircuitType() == IsisRouterType.L2.value()) { | ||
| 91 | + configPacket[(2 * numberOfInterface) + 1] = (byte) 1; | ||
| 92 | + } else if (isisInterface.networkType() == IsisNetworkType.P2P) { | ||
| 93 | + configPacket[(2 * numberOfInterface) + 1] = (byte) 2; | ||
| 94 | + } else if (isisInterface.networkType() == IsisNetworkType.BROADCAST && | ||
| 95 | + isisInterfaceImpl.reservedPacketCircuitType() == IsisRouterType.L1L2.value()) { | ||
| 96 | + configPacket[(2 * numberOfInterface) + 1] = (byte) 3; | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + configPacket[1] = numberOfInterface; | ||
| 101 | + //First time configuration | ||
| 102 | + if (processes == null) { | ||
| 103 | + processes = isisProcesses; | ||
| 104 | + //Initialize connection by creating a channel handler instance and sent the config packet); | ||
| 105 | + initConnection(); | ||
| 106 | + //Initializing the interface map in channel handler | ||
| 107 | + isisChannelHandler.initializeInterfaceMap(); | ||
| 108 | + } else { | ||
| 109 | + isisChannelHandler.updateInterfaceMap(isisProcesses); | ||
| 110 | + } | ||
| 111 | + //Send the config packet | ||
| 112 | + isisChannelHandler.sentConfigPacket(configPacket); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * Initializes the netty client channel connection. | ||
| 117 | + */ | ||
| 118 | + private void initConnection() { | ||
| 119 | + if (peerBootstrap != null) { | ||
| 120 | + return; | ||
| 121 | + } | ||
| 122 | + peerBootstrap = createPeerBootStrap(); | ||
| 123 | + | ||
| 124 | + peerBootstrap.setOption("reuseAddress", true); | ||
| 125 | + peerBootstrap.setOption("tcpNoDelay", true); | ||
| 126 | + peerBootstrap.setOption("keepAlive", true); | ||
| 127 | + peerBootstrap.setOption("receiveBufferSize", Controller.BUFFER_SIZE); | ||
| 128 | + peerBootstrap.setOption("receiveBufferSizePredictorFactory", | ||
| 129 | + new FixedReceiveBufferSizePredictorFactory( | ||
| 130 | + Controller.BUFFER_SIZE)); | ||
| 131 | + peerBootstrap.setOption("receiveBufferSizePredictor", | ||
| 132 | + new AdaptiveReceiveBufferSizePredictor(64, 1024, 65536)); | ||
| 133 | + peerBootstrap.setOption("child.keepAlive", true); | ||
| 134 | + peerBootstrap.setOption("child.tcpNoDelay", true); | ||
| 135 | + peerBootstrap.setOption("child.sendBufferSize", Controller.BUFFER_SIZE); | ||
| 136 | + peerBootstrap.setOption("child.receiveBufferSize", Controller.BUFFER_SIZE); | ||
| 137 | + peerBootstrap.setOption("child.receiveBufferSizePredictorFactory", | ||
| 138 | + new FixedReceiveBufferSizePredictorFactory( | ||
| 139 | + Controller.BUFFER_SIZE)); | ||
| 140 | + peerBootstrap.setOption("child.reuseAddress", true); | ||
| 141 | + | ||
| 142 | + isisChannelHandler = new IsisChannelHandler(this, processes); | ||
| 143 | + ChannelPipelineFactory pfact = new IsisPipelineFactory(isisChannelHandler); | ||
| 144 | + peerBootstrap.setPipelineFactory(pfact); | ||
| 145 | + ChannelFuture connection = peerBootstrap.connect(new InetSocketAddress(IsisConstants.SHOST, isisPort.toInt())); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * Creates peer boot strap. | ||
| 150 | + * | ||
| 151 | + * @return client bootstrap instance | ||
| 152 | + */ | ||
| 153 | + private ClientBootstrap createPeerBootStrap() { | ||
| 154 | + | ||
| 155 | + if (peerWorkerThreads == 0) { | ||
| 156 | + peerExecFactory = new NioClientSocketChannelFactory( | ||
| 157 | + Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")), | ||
| 158 | + Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d"))); | ||
| 159 | + return new ClientBootstrap(peerExecFactory); | ||
| 160 | + } else { | ||
| 161 | + peerExecFactory = new NioClientSocketChannelFactory( | ||
| 162 | + Executors.newCachedThreadPool(groupedThreads("onos/isis", "boss-%d")), | ||
| 163 | + Executors.newCachedThreadPool(groupedThreads("onos/isis", "worker-%d")), | ||
| 164 | + peerWorkerThreads); | ||
| 165 | + return new ClientBootstrap(peerExecFactory); | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + /** | ||
| 170 | + * Gets all configured processes. | ||
| 171 | + * | ||
| 172 | + * @return all configured processes | ||
| 173 | + */ | ||
| 174 | + public List<IsisProcess> getAllConfiguredProcesses() { | ||
| 175 | + return processes; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + /** | ||
| 179 | + * Gets the list of processes configured. | ||
| 180 | + * | ||
| 181 | + * @param json posted json | ||
| 182 | + * @return list of processes configured | ||
| 183 | + */ | ||
| 184 | + private List<IsisProcess> getConfig(JsonNode json) throws Exception { | ||
| 185 | + | ||
| 186 | + List<IsisProcess> isisProcessesList = new ArrayList<>(); | ||
| 187 | + JsonNode jsonNodes = json; | ||
| 188 | + | ||
| 189 | + if (jsonNodes == null) { | ||
| 190 | + return isisProcessesList; | ||
| 191 | + } | ||
| 192 | + jsonNodes.forEach(jsonNode -> { | ||
| 193 | + List<IsisInterface> interfaceList = new ArrayList<>(); | ||
| 194 | + for (JsonNode jsonNode1 : jsonNode.path(IsisConstants.INTERFACE)) { | ||
| 195 | + IsisInterface isisInterface = new DefaultIsisInterface(); | ||
| 196 | + isisInterface.setInterfaceIndex(jsonNode1.path(IsisConstants.INTERFACEINDEX).asInt()); | ||
| 197 | + isisInterface.setInterfaceIpAddress(Ip4Address.valueOf(jsonNode1 | ||
| 198 | + .path(IsisConstants.INTERFACEIP) | ||
| 199 | + .asText())); | ||
| 200 | + try { | ||
| 201 | + isisInterface.setNetworkMask(InetAddress.getByName((jsonNode1 | ||
| 202 | + .path(IsisConstants.NETWORKMASK).asText())).getAddress()); | ||
| 203 | + } catch (UnknownHostException e) { | ||
| 204 | + log.debug("Error:: Parsing network mask"); | ||
| 205 | + } | ||
| 206 | + isisInterface.setInterfaceMacAddress(MacAddress.valueOf(jsonNode1 | ||
| 207 | + .path(IsisConstants.MACADDRESS) | ||
| 208 | + .asText())); | ||
| 209 | + isisInterface.setIntermediateSystemName(jsonNode1 | ||
| 210 | + .path(IsisConstants.INTERMEDIATESYSTEMNAME) | ||
| 211 | + .asText()); | ||
| 212 | + isisInterface.setSystemId(jsonNode1.path(IsisConstants.SYSTEMID).asText()); | ||
| 213 | + isisInterface.setReservedPacketCircuitType(jsonNode1 | ||
| 214 | + .path(IsisConstants.RESERVEDPACKETCIRCUITTYPE) | ||
| 215 | + .asInt()); | ||
| 216 | + if (isisInterface.reservedPacketCircuitType() == IsisRouterType.L1.value()) { | ||
| 217 | + isisInterface.setL1LanId(jsonNode1.path(IsisConstants.LANID).asText()); | ||
| 218 | + } | ||
| 219 | + isisInterface.setIdLength(jsonNode1.path(IsisConstants.IDLENGTH).asInt()); | ||
| 220 | + isisInterface.setMaxAreaAddresses(jsonNode1.path(IsisConstants.MAXAREAADDRESSES).asInt()); | ||
| 221 | + isisInterface.setNetworkType(IsisNetworkType.get(jsonNode1 | ||
| 222 | + .path(IsisConstants.NETWORKTYPE) | ||
| 223 | + .asInt())); | ||
| 224 | + isisInterface.setAreaAddress(jsonNode1.path(IsisConstants.AREAADDRESS).asText()); | ||
| 225 | + isisInterface.setAreaLength(jsonNode1.path(IsisConstants.AREALENGTH).asInt()); | ||
| 226 | + isisInterface.setLspId(jsonNode1.path(IsisConstants.LSPID).asText()); | ||
| 227 | + isisInterface.setCircuitId(jsonNode1.path(IsisConstants.CIRCUITID).asText()); | ||
| 228 | + isisInterface.setHoldingTime(jsonNode1.path(IsisConstants.HOLDINGTIME).asInt()); | ||
| 229 | + isisInterface.setPriority(jsonNode1.path(IsisConstants.PRIORITY).asInt()); | ||
| 230 | + isisInterface.setHelloInterval(jsonNode1.path(IsisConstants.HELLOINTERVAL).asInt()); | ||
| 231 | + interfaceList.add(isisInterface); | ||
| 232 | + } | ||
| 233 | + IsisProcess process = new DefaultIsisProcess(); | ||
| 234 | + process.setProcessId(jsonNode.path(IsisConstants.PROCESSESID).asText()); | ||
| 235 | + process.setIsisInterfaceList(interfaceList); | ||
| 236 | + isisProcessesList.add(process); | ||
| 237 | + }); | ||
| 238 | + | ||
| 239 | + return isisProcessesList; | ||
| 240 | + } | ||
| 241 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisController.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 19 | +import org.apache.felix.scr.annotations.Activate; | ||
| 20 | +import org.apache.felix.scr.annotations.Component; | ||
| 21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 22 | +import org.apache.felix.scr.annotations.Reference; | ||
| 23 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 24 | +import org.apache.felix.scr.annotations.Service; | ||
| 25 | +import org.onosproject.isis.controller.IsisController; | ||
| 26 | +import org.onosproject.isis.controller.IsisProcess; | ||
| 27 | +import org.onosproject.isis.controller.topology.IsisRouterListener; | ||
| 28 | +import org.onosproject.net.driver.DriverService; | ||
| 29 | +import org.slf4j.Logger; | ||
| 30 | +import org.slf4j.LoggerFactory; | ||
| 31 | + | ||
| 32 | +import java.util.List; | ||
| 33 | + | ||
| 34 | +/** | ||
| 35 | + * Represents ISIS controller implementation. | ||
| 36 | + */ | ||
| 37 | +@Component(immediate = true) | ||
| 38 | +@Service | ||
| 39 | +public class DefaultIsisController implements IsisController { | ||
| 40 | + | ||
| 41 | + protected static final Logger log = LoggerFactory.getLogger(DefaultIsisController.class); | ||
| 42 | + private final Controller controller = new Controller(); | ||
| 43 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 44 | + protected DriverService driverService; | ||
| 45 | + | ||
| 46 | + @Activate | ||
| 47 | + public void activate() { | ||
| 48 | + log.debug("ISISControllerImpl activate"); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @Deactivate | ||
| 52 | + public void deactivate() { | ||
| 53 | + controller.isisDeactivate(); | ||
| 54 | + log.debug("ISISControllerImpl deActivate"); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public List<IsisProcess> allConfiguredProcesses() { | ||
| 59 | + List<IsisProcess> processes = controller.getAllConfiguredProcesses(); | ||
| 60 | + return processes; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + @Override | ||
| 64 | + public void updateConfig(JsonNode jsonNode) { | ||
| 65 | + log.debug("updateConfig::IsisList::processes::{}", jsonNode); | ||
| 66 | + try { | ||
| 67 | + controller.updateConfig(jsonNode); | ||
| 68 | + } catch (Exception e) { | ||
| 69 | + log.debug("Error::updateConfig::{}", e.getMessage()); | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public void addRouterListener(IsisRouterListener isisRouterListener) { | ||
| 75 | + log.debug("IsisControllerImpl::addRouterListener..."); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Override | ||
| 79 | + public void removeRouterListener(IsisRouterListener isisRouterListener) { | ||
| 80 | + log.debug("IsisControllerImpl::removeRouterListener..."); | ||
| 81 | + } | ||
| 82 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisInterface.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import org.jboss.netty.channel.Channel; | ||
| 19 | +import org.onlab.packet.Ip4Address; | ||
| 20 | +import org.onlab.packet.MacAddress; | ||
| 21 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 22 | +import org.onosproject.isis.controller.IsisInterfaceState; | ||
| 23 | +import org.onosproject.isis.controller.IsisLsdb; | ||
| 24 | +import org.onosproject.isis.controller.IsisMessage; | ||
| 25 | +import org.onosproject.isis.controller.IsisNeighbor; | ||
| 26 | +import org.onosproject.isis.controller.IsisNetworkType; | ||
| 27 | +import org.onosproject.isis.controller.IsisPduType; | ||
| 28 | +import org.onosproject.isis.controller.IsisRouterType; | ||
| 29 | +import org.onosproject.isis.controller.LspWrapper; | ||
| 30 | +import org.onosproject.isis.io.isispacket.IsisHeader; | ||
| 31 | +import org.onosproject.isis.io.isispacket.pdu.Csnp; | ||
| 32 | +import org.onosproject.isis.io.isispacket.pdu.HelloPdu; | ||
| 33 | +import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; | ||
| 34 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
| 35 | +import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu; | ||
| 36 | +import org.onosproject.isis.io.isispacket.pdu.Psnp; | ||
| 37 | +import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; | ||
| 38 | +import org.onosproject.isis.io.isispacket.tlv.IsisTlv; | ||
| 39 | +import org.onosproject.isis.io.isispacket.tlv.LspEntriesTlv; | ||
| 40 | +import org.onosproject.isis.io.isispacket.tlv.LspEntry; | ||
| 41 | +import org.onosproject.isis.io.isispacket.tlv.TlvHeader; | ||
| 42 | +import org.onosproject.isis.io.isispacket.tlv.TlvType; | ||
| 43 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 44 | +import org.onosproject.isis.io.util.IsisUtil; | ||
| 45 | +import org.onosproject.isis.io.util.LspGenerator; | ||
| 46 | +import org.slf4j.Logger; | ||
| 47 | +import org.slf4j.LoggerFactory; | ||
| 48 | + | ||
| 49 | +import java.util.ArrayList; | ||
| 50 | +import java.util.Iterator; | ||
| 51 | +import java.util.List; | ||
| 52 | +import java.util.Map; | ||
| 53 | +import java.util.Set; | ||
| 54 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 55 | +import java.util.concurrent.Executors; | ||
| 56 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 57 | +import java.util.concurrent.ScheduledFuture; | ||
| 58 | +import java.util.concurrent.TimeUnit; | ||
| 59 | + | ||
| 60 | +/** | ||
| 61 | + * Representation of an ISIS interface. | ||
| 62 | + */ | ||
| 63 | +public class DefaultIsisInterface implements IsisInterface { | ||
| 64 | + private static final Logger log = LoggerFactory.getLogger(DefaultIsisInterface.class); | ||
| 65 | + boolean flagValue = false; | ||
| 66 | + private int interfaceIndex; | ||
| 67 | + private Ip4Address interfaceIpAddress; | ||
| 68 | + private byte[] networkMask; | ||
| 69 | + private MacAddress interfaceMacAddress; | ||
| 70 | + private String intermediateSystemName; | ||
| 71 | + private String systemId; | ||
| 72 | + private String l1LanId; | ||
| 73 | + private String l2LanId; | ||
| 74 | + private int idLength; | ||
| 75 | + private int maxAreaAddresses; | ||
| 76 | + private int reservedPacketCircuitType; | ||
| 77 | + private IsisNetworkType networkType; | ||
| 78 | + private String areaAddress; | ||
| 79 | + private int areaLength; | ||
| 80 | + private String lspId; | ||
| 81 | + private int holdingTime; | ||
| 82 | + private int priority; | ||
| 83 | + private String circuitId; | ||
| 84 | + private int helloInterval; | ||
| 85 | + private Map<MacAddress, IsisNeighbor> neighborList = new ConcurrentHashMap<>(); | ||
| 86 | + private IsisHelloPduSender isisHelloPduSender = null; | ||
| 87 | + private ScheduledExecutorService exServiceHello = null; | ||
| 88 | + private IsisInterfaceState interfaceState = IsisInterfaceState.DOWN; | ||
| 89 | + private IsisLsdb isisLsdb = null; | ||
| 90 | + private List<Ip4Address> allConfiguredInterfaceIps = null; | ||
| 91 | + private Channel channel; | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * Returns ISIS LSDB instance. | ||
| 95 | + * | ||
| 96 | + * @return ISIS LSDB instance | ||
| 97 | + */ | ||
| 98 | + public IsisLsdb isisLsdb() { | ||
| 99 | + return isisLsdb; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Sets all configured interface IPs. | ||
| 104 | + * | ||
| 105 | + * @param allConfiguredInterfaces all configured interface IPs | ||
| 106 | + */ | ||
| 107 | + public void setAllConfiguredInterfaceIps(List<Ip4Address> allConfiguredInterfaces) { | ||
| 108 | + allConfiguredInterfaceIps = allConfiguredInterfaces; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Removes neighbor from the interface neighbor map. | ||
| 113 | + * | ||
| 114 | + * @param isisNeighbor ISIS neighbor instance | ||
| 115 | + */ | ||
| 116 | + public void removeNeighbor(IsisNeighbor isisNeighbor) { | ||
| 117 | + neighborList.remove(isisNeighbor.neighborMacAddress()); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * Returns the ISIS neighbor instance if exists. | ||
| 122 | + * | ||
| 123 | + * @param isisNeighborMac mac address of the neighbor router | ||
| 124 | + * @return ISIS neighbor instance if exists else null | ||
| 125 | + */ | ||
| 126 | + public IsisNeighbor lookup(MacAddress isisNeighborMac) { | ||
| 127 | + return neighborList.get(isisNeighborMac); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * Returns the neighbors list. | ||
| 132 | + * | ||
| 133 | + * @return neighbors list | ||
| 134 | + */ | ||
| 135 | + public Set<MacAddress> neighbors() { | ||
| 136 | + return neighborList.keySet(); | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * Returns channel instance. | ||
| 141 | + * | ||
| 142 | + * @return channel instance | ||
| 143 | + */ | ||
| 144 | + public Channel channel() { | ||
| 145 | + return channel; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * Returns interface index. | ||
| 150 | + * | ||
| 151 | + * @return interface index | ||
| 152 | + */ | ||
| 153 | + public int interfaceIndex() { | ||
| 154 | + return interfaceIndex; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + /** | ||
| 158 | + * Set interface index. | ||
| 159 | + * | ||
| 160 | + * @param interfaceIndex interface index | ||
| 161 | + */ | ||
| 162 | + public void setInterfaceIndex(int interfaceIndex) { | ||
| 163 | + this.interfaceIndex = interfaceIndex; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + /** | ||
| 167 | + * Returns the interface IP address. | ||
| 168 | + * | ||
| 169 | + * @return interface IP address | ||
| 170 | + */ | ||
| 171 | + public Ip4Address interfaceIpAddress() { | ||
| 172 | + return interfaceIpAddress; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * Sets the interface IP address. | ||
| 177 | + * | ||
| 178 | + * @param interfaceIpAddress interfaceIpAddress interface IP address | ||
| 179 | + */ | ||
| 180 | + public void setInterfaceIpAddress(Ip4Address interfaceIpAddress) { | ||
| 181 | + this.interfaceIpAddress = interfaceIpAddress; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + /** | ||
| 185 | + * Returns the network mask. | ||
| 186 | + * | ||
| 187 | + * @return network mask | ||
| 188 | + */ | ||
| 189 | + public byte[] networkMask() { | ||
| 190 | + return networkMask; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + /** | ||
| 194 | + * Sets the network mask. | ||
| 195 | + * | ||
| 196 | + * @param networkMask network mask | ||
| 197 | + */ | ||
| 198 | + public void setNetworkMask(byte[] networkMask) { | ||
| 199 | + this.networkMask = networkMask; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + /** | ||
| 203 | + * Returns the interface mac address. | ||
| 204 | + * | ||
| 205 | + * @return interface mac address | ||
| 206 | + */ | ||
| 207 | + public MacAddress getInterfaceMacAddress() { | ||
| 208 | + return interfaceMacAddress; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + /** | ||
| 212 | + * Sets the interface mac address. | ||
| 213 | + * | ||
| 214 | + * @param interfaceMacAddress interface mac address | ||
| 215 | + */ | ||
| 216 | + public void setInterfaceMacAddress(MacAddress interfaceMacAddress) { | ||
| 217 | + this.interfaceMacAddress = interfaceMacAddress; | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + /** | ||
| 221 | + * Returns intermediate system name. | ||
| 222 | + * | ||
| 223 | + * @return intermediate system name | ||
| 224 | + */ | ||
| 225 | + public String intermediateSystemName() { | ||
| 226 | + return intermediateSystemName; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + /** | ||
| 230 | + * Sets intermediate system name. | ||
| 231 | + * | ||
| 232 | + * @param intermediateSystemName intermediate system name | ||
| 233 | + */ | ||
| 234 | + public void setIntermediateSystemName(String intermediateSystemName) { | ||
| 235 | + this.intermediateSystemName = intermediateSystemName; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + /** | ||
| 239 | + * Returns system ID. | ||
| 240 | + * | ||
| 241 | + * @return system ID | ||
| 242 | + */ | ||
| 243 | + public String systemId() { | ||
| 244 | + return systemId; | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + /** | ||
| 248 | + * Sets system ID. | ||
| 249 | + * | ||
| 250 | + * @param systemId system ID | ||
| 251 | + */ | ||
| 252 | + public void setSystemId(String systemId) { | ||
| 253 | + this.systemId = systemId; | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + /** | ||
| 257 | + * Returns LAN ID. | ||
| 258 | + * | ||
| 259 | + * @return LAN ID | ||
| 260 | + */ | ||
| 261 | + public String l1LanId() { | ||
| 262 | + return l1LanId; | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + /** | ||
| 266 | + * Sets LAN ID. | ||
| 267 | + * | ||
| 268 | + * @param l1LanId LAN ID | ||
| 269 | + */ | ||
| 270 | + public void setL1LanId(String l1LanId) { | ||
| 271 | + this.l1LanId = l1LanId; | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + /** | ||
| 275 | + * Returns LAN ID. | ||
| 276 | + * | ||
| 277 | + * @return LAN ID | ||
| 278 | + */ | ||
| 279 | + public String l2LanId() { | ||
| 280 | + return l2LanId; | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + /** | ||
| 284 | + * Sets LAN ID. | ||
| 285 | + * | ||
| 286 | + * @param l2LanId LAN ID | ||
| 287 | + */ | ||
| 288 | + public void setL2LanId(String l2LanId) { | ||
| 289 | + this.l2LanId = l2LanId; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + /** | ||
| 293 | + * Returns ID length. | ||
| 294 | + * | ||
| 295 | + * @return ID length | ||
| 296 | + */ | ||
| 297 | + public int getIdLength() { | ||
| 298 | + | ||
| 299 | + return ((idLength == 0) ? 6 : idLength); | ||
| 300 | + } | ||
| 301 | + | ||
| 302 | + /** | ||
| 303 | + * Sets ID length. | ||
| 304 | + * | ||
| 305 | + * @param idLength ID length | ||
| 306 | + */ | ||
| 307 | + public void setIdLength(int idLength) { | ||
| 308 | + this.idLength = idLength; | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + /** | ||
| 312 | + * Returns max area addresses. | ||
| 313 | + * | ||
| 314 | + * @return max area addresses | ||
| 315 | + */ | ||
| 316 | + public int getMaxAreaAddresses() { | ||
| 317 | + | ||
| 318 | + return maxAreaAddresses; | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + /** | ||
| 322 | + * Sets area max addresses. | ||
| 323 | + * | ||
| 324 | + * @param maxAreaAddresses max area addresses | ||
| 325 | + */ | ||
| 326 | + public void setMaxAreaAddresses(int maxAreaAddresses) { | ||
| 327 | + this.maxAreaAddresses = maxAreaAddresses; | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + /** | ||
| 331 | + * Returns reserved packet circuit type. | ||
| 332 | + * | ||
| 333 | + * @return reserved packet circuit type | ||
| 334 | + */ | ||
| 335 | + public int reservedPacketCircuitType() { | ||
| 336 | + return reservedPacketCircuitType; | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + /** | ||
| 340 | + * Sets reserved packet circuit type. | ||
| 341 | + * | ||
| 342 | + * @param reservedPacketCircuitType reserved packet circuit type | ||
| 343 | + */ | ||
| 344 | + public void setReservedPacketCircuitType(int reservedPacketCircuitType) { | ||
| 345 | + this.reservedPacketCircuitType = reservedPacketCircuitType; | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + /** | ||
| 349 | + * Returns point to point. | ||
| 350 | + * | ||
| 351 | + * @return point to point | ||
| 352 | + */ | ||
| 353 | + public IsisNetworkType networkType() { | ||
| 354 | + return networkType; | ||
| 355 | + } | ||
| 356 | + | ||
| 357 | + /** | ||
| 358 | + * Sets point to point or broadcast. | ||
| 359 | + * | ||
| 360 | + * @param networkType point to point or broadcast | ||
| 361 | + */ | ||
| 362 | + public void setNetworkType(IsisNetworkType networkType) { | ||
| 363 | + this.networkType = networkType; | ||
| 364 | + } | ||
| 365 | + | ||
| 366 | + /** | ||
| 367 | + * Returns area address. | ||
| 368 | + * | ||
| 369 | + * @return area address | ||
| 370 | + */ | ||
| 371 | + public String areaAddress() { | ||
| 372 | + return areaAddress; | ||
| 373 | + } | ||
| 374 | + | ||
| 375 | + /** | ||
| 376 | + * Sets area address. | ||
| 377 | + * | ||
| 378 | + * @param areaAddress area address | ||
| 379 | + */ | ||
| 380 | + public void setAreaAddress(String areaAddress) { | ||
| 381 | + this.areaAddress = areaAddress; | ||
| 382 | + } | ||
| 383 | + | ||
| 384 | + /** | ||
| 385 | + * Returns area length. | ||
| 386 | + * | ||
| 387 | + * @return area length | ||
| 388 | + */ | ||
| 389 | + public int getAreaLength() { | ||
| 390 | + return areaLength; | ||
| 391 | + } | ||
| 392 | + | ||
| 393 | + /** | ||
| 394 | + * Sets area length. | ||
| 395 | + * | ||
| 396 | + * @param areaLength area length | ||
| 397 | + */ | ||
| 398 | + public void setAreaLength(int areaLength) { | ||
| 399 | + this.areaLength = areaLength; | ||
| 400 | + } | ||
| 401 | + | ||
| 402 | + /** | ||
| 403 | + * Returns LSP ID. | ||
| 404 | + * | ||
| 405 | + * @return LSP ID | ||
| 406 | + */ | ||
| 407 | + public String getLspId() { | ||
| 408 | + return lspId; | ||
| 409 | + } | ||
| 410 | + | ||
| 411 | + /** | ||
| 412 | + * Sets LSP ID. | ||
| 413 | + * | ||
| 414 | + * @param lspId link state packet ID | ||
| 415 | + */ | ||
| 416 | + public void setLspId(String lspId) { | ||
| 417 | + this.lspId = lspId; | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + /** | ||
| 421 | + * Returns holding time. | ||
| 422 | + * | ||
| 423 | + * @return holding time | ||
| 424 | + */ | ||
| 425 | + public int holdingTime() { | ||
| 426 | + return holdingTime; | ||
| 427 | + } | ||
| 428 | + | ||
| 429 | + /** | ||
| 430 | + * Sets holding time. | ||
| 431 | + * | ||
| 432 | + * @param holdingTime holding time | ||
| 433 | + */ | ||
| 434 | + public void setHoldingTime(int holdingTime) { | ||
| 435 | + this.holdingTime = holdingTime; | ||
| 436 | + } | ||
| 437 | + | ||
| 438 | + /** | ||
| 439 | + * Returns priority. | ||
| 440 | + * | ||
| 441 | + * @return priority | ||
| 442 | + */ | ||
| 443 | + public int priority() { | ||
| 444 | + return priority; | ||
| 445 | + } | ||
| 446 | + | ||
| 447 | + /** | ||
| 448 | + * Sets priority. | ||
| 449 | + * | ||
| 450 | + * @param priority priority | ||
| 451 | + */ | ||
| 452 | + public void setPriority(int priority) { | ||
| 453 | + this.priority = priority; | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + /** | ||
| 457 | + * Returns hello interval. | ||
| 458 | + * | ||
| 459 | + * @return hello interval | ||
| 460 | + */ | ||
| 461 | + public int helloInterval() { | ||
| 462 | + return helloInterval; | ||
| 463 | + } | ||
| 464 | + | ||
| 465 | + /** | ||
| 466 | + * Sets hello interval. | ||
| 467 | + * | ||
| 468 | + * @param helloInterval hello interval | ||
| 469 | + */ | ||
| 470 | + public void setHelloInterval(int helloInterval) { | ||
| 471 | + this.helloInterval = helloInterval; | ||
| 472 | + } | ||
| 473 | + | ||
| 474 | + /** | ||
| 475 | + * Returns the interface state. | ||
| 476 | + * | ||
| 477 | + * @return interface state | ||
| 478 | + */ | ||
| 479 | + public IsisInterfaceState interfaceState() { | ||
| 480 | + return interfaceState; | ||
| 481 | + } | ||
| 482 | + | ||
| 483 | + /** | ||
| 484 | + * Sets the interface state. | ||
| 485 | + * | ||
| 486 | + * @param interfaceState the interface state | ||
| 487 | + */ | ||
| 488 | + public void setInterfaceState(IsisInterfaceState interfaceState) { | ||
| 489 | + this.interfaceState = interfaceState; | ||
| 490 | + } | ||
| 491 | + | ||
| 492 | + /** | ||
| 493 | + * Returns the circuit ID. | ||
| 494 | + * | ||
| 495 | + * @return circuit ID | ||
| 496 | + */ | ||
| 497 | + public String circuitId() { | ||
| 498 | + return circuitId; | ||
| 499 | + } | ||
| 500 | + | ||
| 501 | + /** | ||
| 502 | + * Sets the circuit ID. | ||
| 503 | + * | ||
| 504 | + * @param circuitId circuit ID | ||
| 505 | + */ | ||
| 506 | + public void setCircuitId(String circuitId) { | ||
| 507 | + this.circuitId = circuitId; | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + /** | ||
| 511 | + * Processes received ISIS message. | ||
| 512 | + * When an ISIS message received it is handed over to this method. | ||
| 513 | + * Based on the type of the ISIS message received it will be handed over | ||
| 514 | + * to corresponding message handler methods. | ||
| 515 | + * | ||
| 516 | + * @param isisMessage received ISIS message | ||
| 517 | + * @param isisLsdb ISIS LSDB instance | ||
| 518 | + */ | ||
| 519 | + public void processIsisMessage(IsisMessage isisMessage, IsisLsdb isisLsdb, Channel channel) { | ||
| 520 | + log.debug("IsisInterfaceImpl::processIsisMessage...!!!"); | ||
| 521 | + if (channel == null) { | ||
| 522 | + this.channel = channel; | ||
| 523 | + } | ||
| 524 | + if (this.isisLsdb == null) { | ||
| 525 | + this.isisLsdb = isisLsdb; | ||
| 526 | + } | ||
| 527 | + | ||
| 528 | + switch (isisMessage.isisPduType()) { | ||
| 529 | + case L1HELLOPDU: | ||
| 530 | + case L2HELLOPDU: | ||
| 531 | + processL1L2HelloPduMessage(isisMessage, channel); | ||
| 532 | + break; | ||
| 533 | + case P2PHELLOPDU: | ||
| 534 | + processP2pHelloPduMessage(isisMessage, channel); | ||
| 535 | + break; | ||
| 536 | + case L1LSPDU: | ||
| 537 | + case L2LSPDU: | ||
| 538 | + processLsPduMessage(isisMessage, channel); | ||
| 539 | + break; | ||
| 540 | + case L1CSNP: | ||
| 541 | + case L2CSNP: | ||
| 542 | + processCsnPduMessage(isisMessage, channel); | ||
| 543 | + break; | ||
| 544 | + case L1PSNP: | ||
| 545 | + case L2PSNP: | ||
| 546 | + log.debug("Received a PSNP packet...!!!"); | ||
| 547 | + break; | ||
| 548 | + default: | ||
| 549 | + log.debug("Unknown packet to process...!!!"); | ||
| 550 | + break; | ||
| 551 | + } | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + /** | ||
| 555 | + * Validates the received message. | ||
| 556 | + * | ||
| 557 | + * @param helloPdu ISIS message instance | ||
| 558 | + * @return true if valid ISIS message else false | ||
| 559 | + */ | ||
| 560 | + public boolean validateHelloMessage(HelloPdu helloPdu) { | ||
| 561 | + boolean isValid = false; | ||
| 562 | + | ||
| 563 | + //Local InterfaceAddress TLV and compare with the IP Interface address and check if they are in same subnet | ||
| 564 | + List<Ip4Address> interfaceIpAddresses = helloPdu.interfaceIpAddresses(); | ||
| 565 | + Ip4Address neighborIp = (helloPdu.interfaceIpAddresses() != null) ? | ||
| 566 | + interfaceIpAddresses.get(0) : Ip4Address.valueOf("0.0.0.0"); | ||
| 567 | + if (!IsisUtil.sameNetwork(interfaceIpAddress, neighborIp, networkMask)) { | ||
| 568 | + return false; | ||
| 569 | + } | ||
| 570 | + | ||
| 571 | + //Verify if it's in same area, Areas which the router belongs to | ||
| 572 | + List<String> areas = helloPdu.areaAddress(); | ||
| 573 | + for (String area : areas) { | ||
| 574 | + if (areaAddress.equals(area)) { | ||
| 575 | + isValid = true; | ||
| 576 | + } | ||
| 577 | + } | ||
| 578 | + | ||
| 579 | + return isValid; | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + /** | ||
| 583 | + * Checks neighbor presents in the list or not. | ||
| 584 | + * | ||
| 585 | + * @param neighborMac neighbor MAc address | ||
| 586 | + * @return true if neighbor exist else false | ||
| 587 | + */ | ||
| 588 | + private boolean isNeighborInList(MacAddress neighborMac) { | ||
| 589 | + return neighborList.containsKey(neighborMac); | ||
| 590 | + } | ||
| 591 | + | ||
| 592 | + /** | ||
| 593 | + * Adds neighbor in the list. | ||
| 594 | + * | ||
| 595 | + * @param neighbor neighbor MAC address | ||
| 596 | + * @return true if neighbor exist else false | ||
| 597 | + */ | ||
| 598 | + private void addNeighbouringRouter(IsisNeighbor neighbor) { | ||
| 599 | + neighborList.put(neighbor.neighborMacAddress(), neighbor); | ||
| 600 | + } | ||
| 601 | + | ||
| 602 | + /** | ||
| 603 | + * Returns neighbor presents in the list. | ||
| 604 | + * | ||
| 605 | + * @param neighborMac neighbor MAc address | ||
| 606 | + * @return neighbor instance | ||
| 607 | + */ | ||
| 608 | + private IsisNeighbor neighbouringRouter(MacAddress neighborMac) { | ||
| 609 | + return neighborList.get(neighborMac); | ||
| 610 | + } | ||
| 611 | + | ||
| 612 | + /** | ||
| 613 | + * Processes the L1 or L2 hello message. | ||
| 614 | + * | ||
| 615 | + * @param isisMessage hello message instance | ||
| 616 | + * @param channel channel instance | ||
| 617 | + */ | ||
| 618 | + public void processL1L2HelloPduMessage(IsisMessage isisMessage, Channel channel) { | ||
| 619 | + log.debug("Enters processL1L2HelloPduMessage ...!!!"); | ||
| 620 | + log.debug("IsisInterfaceImpl::processHelloMessage...!!!"); | ||
| 621 | + | ||
| 622 | + L1L2HelloPdu helloPacket = (L1L2HelloPdu) isisMessage; | ||
| 623 | + log.debug("IsisInterfaceImpl::processHelloMessage::Interface Type {} ISISInterfaceState {} ", | ||
| 624 | + networkType, interfaceState); | ||
| 625 | + | ||
| 626 | + //If L1 Hello, validate the area, network and max address | ||
| 627 | + if (IsisPduType.get(helloPacket.pduType()) == IsisPduType.L1HELLOPDU && | ||
| 628 | + !validateHelloMessage(helloPacket)) { | ||
| 629 | + return; | ||
| 630 | + } | ||
| 631 | + | ||
| 632 | + //Get the neighbor | ||
| 633 | + IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac()); | ||
| 634 | + //Neighbor is not in list | ||
| 635 | + if (!isNeighborInList(isisMessage.sourceMac())) { | ||
| 636 | + neighbor = new DefaultIsisNeighbor(helloPacket, this); | ||
| 637 | + addNeighbouringRouter(neighbor); | ||
| 638 | + } | ||
| 639 | + | ||
| 640 | + neighbor.stopInactivityTimeCheck(); | ||
| 641 | + neighbor.startInactivityTimeCheck(); | ||
| 642 | + | ||
| 643 | + //Assign the DIS | ||
| 644 | + String lanId = helloPacket.lanId(); | ||
| 645 | + | ||
| 646 | + if (IsisPduType.L1HELLOPDU == helloPacket.isisPduType()) { | ||
| 647 | + buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel); | ||
| 648 | + l1LanId = lanId; | ||
| 649 | + neighbor.setL1LanId(lanId); | ||
| 650 | + //if a change in lanid | ||
| 651 | + } else if (IsisPduType.L2HELLOPDU == helloPacket.isisPduType()) { | ||
| 652 | + buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel); | ||
| 653 | + l2LanId = lanId; | ||
| 654 | + neighbor.setL2LanId(lanId); | ||
| 655 | + } | ||
| 656 | + | ||
| 657 | + //Check in neighbors list our MAC address present | ||
| 658 | + List<MacAddress> neighbors = helloPacket.neighborList(); | ||
| 659 | + for (MacAddress macAddress : neighbors) { | ||
| 660 | + if (interfaceMacAddress.equals(macAddress)) { | ||
| 661 | + neighbor.setNeighborState(IsisInterfaceState.UP); | ||
| 662 | + //Build Self LSP add in LSDB and sent it. | ||
| 663 | + buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel); | ||
| 664 | + break; | ||
| 665 | + } | ||
| 666 | + } | ||
| 667 | + } | ||
| 668 | + | ||
| 669 | + /** | ||
| 670 | + * Builds and store and send self generated LSP. | ||
| 671 | + * | ||
| 672 | + * @param channel netty channel instance | ||
| 673 | + */ | ||
| 674 | + private void buildStoreAndSendSelfGeneratedLspIfNotExistInDb(Channel channel) { | ||
| 675 | + //Check our LSP is present in DB. else create a self LSP and store it and sent it | ||
| 676 | + String lspKey = isisLsdb.lspKey(systemId); | ||
| 677 | + LspWrapper wrapper = null; | ||
| 678 | + if (reservedPacketCircuitType == IsisRouterType.L1.value()) { | ||
| 679 | + wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey); | ||
| 680 | + if (wrapper == null) { | ||
| 681 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps); | ||
| 682 | + isisLsdb.addLsp(lsp, true, this); | ||
| 683 | + sendLsp(lsp, channel); | ||
| 684 | + } | ||
| 685 | + } else if (reservedPacketCircuitType == IsisRouterType.L2.value()) { | ||
| 686 | + wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey); | ||
| 687 | + if (wrapper == null) { | ||
| 688 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps); | ||
| 689 | + isisLsdb.addLsp(lsp, true, this); | ||
| 690 | + sendLsp(lsp, channel); | ||
| 691 | + } | ||
| 692 | + } else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) { | ||
| 693 | + wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey); | ||
| 694 | + if (wrapper == null) { | ||
| 695 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps); | ||
| 696 | + isisLsdb.addLsp(lsp, true, this); | ||
| 697 | + sendLsp(lsp, channel); | ||
| 698 | + } | ||
| 699 | + | ||
| 700 | + wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey); | ||
| 701 | + if (wrapper == null) { | ||
| 702 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps); | ||
| 703 | + isisLsdb.addLsp(lsp, true, this); | ||
| 704 | + sendLsp(lsp, channel); | ||
| 705 | + } | ||
| 706 | + } | ||
| 707 | + } | ||
| 708 | + | ||
| 709 | + /** | ||
| 710 | + * Builds and update in DB and send self generated LSP. | ||
| 711 | + * | ||
| 712 | + * @param previousLanId previous DIS ID | ||
| 713 | + * @param latestLanId latest DIS ID | ||
| 714 | + * @param channel netty channel instance | ||
| 715 | + */ | ||
| 716 | + private void buildUpdateAndSendSelfGeneratedLspIfDisChange(String previousLanId, | ||
| 717 | + String latestLanId, Channel channel) { | ||
| 718 | + //If DIS change then build and sent LSP | ||
| 719 | + if (previousLanId != null && !previousLanId.equals(IsisConstants.DEFAULTLANID) && | ||
| 720 | + !previousLanId.equals(latestLanId)) { | ||
| 721 | + //Create a self LSP and Update it in DB and sent it | ||
| 722 | + String lspKey = isisLsdb.lspKey(systemId); | ||
| 723 | + if (reservedPacketCircuitType == IsisRouterType.L1.value()) { | ||
| 724 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps); | ||
| 725 | + isisLsdb.addLsp(lsp, true, this); | ||
| 726 | + sendLsp(lsp, channel); | ||
| 727 | + } else if (reservedPacketCircuitType == IsisRouterType.L2.value()) { | ||
| 728 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps); | ||
| 729 | + isisLsdb.addLsp(lsp, true, this); | ||
| 730 | + sendLsp(lsp, channel); | ||
| 731 | + } else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) { | ||
| 732 | + //L1 LSPDU | ||
| 733 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps); | ||
| 734 | + isisLsdb.addLsp(lsp, true, this); | ||
| 735 | + sendLsp(lsp, channel); | ||
| 736 | + //L1 LSPDU | ||
| 737 | + lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps); | ||
| 738 | + isisLsdb.addLsp(lsp, true, this); | ||
| 739 | + sendLsp(lsp, channel); | ||
| 740 | + } | ||
| 741 | + } | ||
| 742 | + | ||
| 743 | + } | ||
| 744 | + | ||
| 745 | + /** | ||
| 746 | + * Sends LS PDU message to channel. | ||
| 747 | + * | ||
| 748 | + * @param lsp LS PDU message instance | ||
| 749 | + * @param channel channel instance | ||
| 750 | + */ | ||
| 751 | + private void sendLsp(LsPdu lsp, Channel channel) { | ||
| 752 | + byte[] lspBytes = lsp.asBytes(); | ||
| 753 | + lspBytes = IsisUtil.addLengthAndMarkItInReserved(lspBytes, IsisConstants.LENGTHPOSITION, | ||
| 754 | + IsisConstants.LENGTHPOSITION + 1, | ||
| 755 | + IsisConstants.RESERVEDPOSITION); | ||
| 756 | + lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION, | ||
| 757 | + IsisConstants.CHECKSUMPOSITION + 1); | ||
| 758 | + //write to the channel | ||
| 759 | + channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex)); | ||
| 760 | + } | ||
| 761 | + | ||
| 762 | + /** | ||
| 763 | + * Processes P2P hello message. | ||
| 764 | + * | ||
| 765 | + * @param isisMessage hello message instance | ||
| 766 | + * @param channel channel instance | ||
| 767 | + */ | ||
| 768 | + public void processP2pHelloPduMessage(IsisMessage isisMessage, Channel channel) { | ||
| 769 | + log.debug("Enters processP2pHelloPduMessage ...!!!"); | ||
| 770 | + P2PHelloPdu helloPacket = (P2PHelloPdu) isisMessage; | ||
| 771 | + | ||
| 772 | + log.debug("IsisInterfaceImpl::processHelloMessage::Interface Type {} OSPFInterfaceState {} ", | ||
| 773 | + networkType, interfaceState); | ||
| 774 | + | ||
| 775 | + //validate the area, network and max address | ||
| 776 | + if (!validateHelloMessage(helloPacket)) { | ||
| 777 | + return; | ||
| 778 | + } | ||
| 779 | + | ||
| 780 | + IsisNeighbor neighbor = null; | ||
| 781 | + List<IsisTlv> tlvs = ((P2PHelloPdu) isisMessage).tlvs(); | ||
| 782 | + AdjacencyStateTlv stateTlv = null; | ||
| 783 | + for (IsisTlv tlv : tlvs) { | ||
| 784 | + if (tlv instanceof AdjacencyStateTlv) { | ||
| 785 | + stateTlv = (AdjacencyStateTlv) tlv; | ||
| 786 | + break; | ||
| 787 | + } | ||
| 788 | + } | ||
| 789 | + | ||
| 790 | + if (stateTlv == null) { | ||
| 791 | + neighbor = neighbouringRouter(isisMessage.sourceMac()); | ||
| 792 | + if (neighbor == null) { | ||
| 793 | + neighbor = new DefaultIsisNeighbor(helloPacket, this); | ||
| 794 | + addNeighbouringRouter(neighbor); | ||
| 795 | + } | ||
| 796 | + neighbor.setNeighborState(IsisInterfaceState.DOWN); | ||
| 797 | + buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel); | ||
| 798 | + } else if (stateTlv.adjacencyType() == IsisInterfaceState.DOWN.value()) { | ||
| 799 | + neighbor = neighbouringRouter(isisMessage.sourceMac()); | ||
| 800 | + if (neighbor == null) { | ||
| 801 | + neighbor = new DefaultIsisNeighbor(helloPacket, this); | ||
| 802 | + addNeighbouringRouter(neighbor); | ||
| 803 | + } | ||
| 804 | + neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId()); | ||
| 805 | + } else if (stateTlv.adjacencyType() == IsisInterfaceState.INITIAL.value()) { | ||
| 806 | + //Neighbor already present in the list | ||
| 807 | + neighbor = neighbouringRouter(isisMessage.sourceMac()); | ||
| 808 | + neighbor.setNeighborState(IsisInterfaceState.INITIAL); | ||
| 809 | + neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId()); | ||
| 810 | + //interfaceState = IsisInterfaceState.UP; | ||
| 811 | + } else if (stateTlv.adjacencyType() == IsisInterfaceState.UP.value()) { | ||
| 812 | + //Build Self LSP add in LSDB and sent it. | ||
| 813 | + neighbor = neighbouringRouter(isisMessage.sourceMac()); | ||
| 814 | + neighbor.setNeighborState(IsisInterfaceState.UP); | ||
| 815 | + neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId()); | ||
| 816 | + buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel); | ||
| 817 | + } | ||
| 818 | + | ||
| 819 | + neighbor.stopInactivityTimeCheck(); | ||
| 820 | + neighbor.startInactivityTimeCheck(); | ||
| 821 | + } | ||
| 822 | + | ||
| 823 | + /** | ||
| 824 | + * Processes LS PDU message. | ||
| 825 | + * | ||
| 826 | + * @param isisMessage LS pdu message instance | ||
| 827 | + * @param channel channel instance | ||
| 828 | + */ | ||
| 829 | + public void processLsPduMessage(IsisMessage isisMessage, Channel channel) { | ||
| 830 | + log.debug("Enters processLsPduMessage ...!!!"); | ||
| 831 | + LsPdu lsPdu = (LsPdu) isisMessage; | ||
| 832 | + LspWrapper wrapper = isisLsdb.findLsp(lsPdu.isisPduType(), lsPdu.lspId()); | ||
| 833 | + if (wrapper == null || isisLsdb.isNewerOrSameLsp(lsPdu, wrapper.lsPdu()).equalsIgnoreCase("latest")) { | ||
| 834 | + //not exist in the database or latest, then add it in database | ||
| 835 | + isisLsdb.addLsp(lsPdu, false, this); | ||
| 836 | + } | ||
| 837 | + | ||
| 838 | + //If network type is P2P, acknowledge with a PSNP | ||
| 839 | + if (networkType() == IsisNetworkType.P2P) { | ||
| 840 | + IsisPduType psnpType = null; | ||
| 841 | + if (IsisPduType.get(lsPdu.pduType()) == IsisPduType.L1LSPDU) { | ||
| 842 | + psnpType = IsisPduType.L1PSNP; | ||
| 843 | + } else if (IsisPduType.get(lsPdu.pduType()) == IsisPduType.L2LSPDU) { | ||
| 844 | + psnpType = IsisPduType.L2PSNP; | ||
| 845 | + } | ||
| 846 | + IsisHeader isisHeader = new LspGenerator().getHeader(psnpType); | ||
| 847 | + Psnp psnp = new Psnp(isisHeader); | ||
| 848 | + psnp.setSourceId(lspKeyP2P(this.systemId)); | ||
| 849 | + TlvHeader tlvHeader = new TlvHeader(); | ||
| 850 | + tlvHeader.setTlvType(TlvType.LSPENTRY.value()); | ||
| 851 | + tlvHeader.setTlvLength(0); | ||
| 852 | + LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader); | ||
| 853 | + LspEntry lspEntry = new LspEntry(); | ||
| 854 | + lspEntry.setLspChecksum(lsPdu.checkSum()); | ||
| 855 | + lspEntry.setLspId(lsPdu.lspId()); | ||
| 856 | + lspEntry.setLspSequenceNumber(lsPdu.sequenceNumber()); | ||
| 857 | + lspEntry.setRemainingTime(lsPdu.remainingLifeTime()); | ||
| 858 | + lspEntriesTlv.addLspEntry(lspEntry); | ||
| 859 | + psnp.addTlv(lspEntriesTlv); | ||
| 860 | + | ||
| 861 | + //write it to channel buffer. | ||
| 862 | + byte[] psnpBytes = psnp.asBytes(); | ||
| 863 | + psnpBytes = IsisUtil.addLengthAndMarkItInReserved(psnpBytes, IsisConstants.LENGTHPOSITION, | ||
| 864 | + IsisConstants.LENGTHPOSITION + 1, | ||
| 865 | + IsisConstants.RESERVEDPOSITION); | ||
| 866 | + flagValue = false; | ||
| 867 | + //write to the channel | ||
| 868 | + channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex)); | ||
| 869 | + } | ||
| 870 | + } | ||
| 871 | + | ||
| 872 | + /** | ||
| 873 | + * Processes CSN PDU message. | ||
| 874 | + * | ||
| 875 | + * @param isisMessage CSN PDU message instance | ||
| 876 | + * @param channel channel instance | ||
| 877 | + */ | ||
| 878 | + public void processCsnPduMessage(IsisMessage isisMessage, Channel channel) { | ||
| 879 | + log.debug("Enters processCsnPduMessage ...!!!"); | ||
| 880 | + if (reservedPacketCircuitType == IsisRouterType.L1.value()) { | ||
| 881 | + processOnL1CsnPdu(isisMessage, channel); | ||
| 882 | + } else if (reservedPacketCircuitType == IsisRouterType.L2.value()) { | ||
| 883 | + processOnL2CsnPdu(isisMessage, channel); | ||
| 884 | + } | ||
| 885 | + } | ||
| 886 | + | ||
| 887 | + /** | ||
| 888 | + * Process the isisMessage which belongs to L1 CSN PDU. | ||
| 889 | + * checks the database for this LsPdu if it exists further check for sequence number | ||
| 890 | + * sequence number is greater will send PsnPdu. | ||
| 891 | + * | ||
| 892 | + * @param isisMessage CSN PDU message instance | ||
| 893 | + * @param channel netty channel instance | ||
| 894 | + */ | ||
| 895 | + private void processOnL1CsnPdu(IsisMessage isisMessage, Channel channel) { | ||
| 896 | + Csnp csnPacket = (Csnp) isisMessage; | ||
| 897 | + List<LspEntry> lspEntryRequestList = new ArrayList<>(); | ||
| 898 | + boolean selfOriginatedFound = false; | ||
| 899 | + if (IsisPduType.L1CSNP.equals(csnPacket.isisPduType())) { | ||
| 900 | + List<IsisTlv> isisTlvs = csnPacket.getAllTlv(); | ||
| 901 | + Iterator iterator = isisTlvs.iterator(); | ||
| 902 | + while (iterator.hasNext()) { | ||
| 903 | + IsisTlv isisTlv = (IsisTlv) iterator.next(); | ||
| 904 | + if (isisTlv instanceof LspEntriesTlv) { | ||
| 905 | + LspEntriesTlv lspEntriesTlv = (LspEntriesTlv) isisTlv; | ||
| 906 | + List<LspEntry> lspEntryList = lspEntriesTlv.lspEntry(); | ||
| 907 | + Iterator lspEntryListIterator = lspEntryList.iterator(); | ||
| 908 | + while (lspEntryListIterator.hasNext()) { | ||
| 909 | + LspEntry lspEntry = (LspEntry) lspEntryListIterator.next(); | ||
| 910 | + String lspKey = lspEntry.lspId(); | ||
| 911 | + LspWrapper lspWrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey); | ||
| 912 | + if (lspWrapper != null) { | ||
| 913 | + LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu(); | ||
| 914 | + if (lspWrapper.isSelfOriginated()) { | ||
| 915 | + selfOriginatedFound = true; | ||
| 916 | + if (lspEntry.lspSequenceNumber() > lsPdu.sequenceNumber()) { | ||
| 917 | + sendLsPduMessage(lspEntry.lspSequenceNumber(), csnPacket.isisPduType(), channel); | ||
| 918 | + } | ||
| 919 | + } else { | ||
| 920 | + if (lsPdu.sequenceNumber() < lspEntry.lspSequenceNumber()) { | ||
| 921 | + lspEntryRequestList.add(lspEntry); | ||
| 922 | + flagValue = true; | ||
| 923 | + } | ||
| 924 | + } | ||
| 925 | + } else { | ||
| 926 | + lspEntryRequestList.add(lspEntry); | ||
| 927 | + flagValue = true; | ||
| 928 | + } | ||
| 929 | + } | ||
| 930 | + } | ||
| 931 | + } | ||
| 932 | + if (flagValue) { | ||
| 933 | + sendPsnPduMessage(lspEntryRequestList, csnPacket.isisPduType(), channel); | ||
| 934 | + } | ||
| 935 | + | ||
| 936 | + if (!selfOriginatedFound) { | ||
| 937 | + String lspKey = isisLsdb.lspKey(systemId); | ||
| 938 | + LspWrapper wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey); | ||
| 939 | + sendLsp((LsPdu) wrapper.lsPdu(), channel); | ||
| 940 | + } | ||
| 941 | + } | ||
| 942 | + } | ||
| 943 | + | ||
| 944 | + /** | ||
| 945 | + * Process the isisMessage which belongs to L2 CSNP. | ||
| 946 | + * checks the database for this LsPdu if it exists further check for sequence number | ||
| 947 | + * sequence number is greater will send PsnPdu. | ||
| 948 | + * | ||
| 949 | + * @param isisMessage received CSNP message | ||
| 950 | + * @param channel netty channel instance | ||
| 951 | + */ | ||
| 952 | + private void processOnL2CsnPdu(IsisMessage isisMessage, Channel channel) { | ||
| 953 | + Csnp csnPacket = (Csnp) isisMessage; | ||
| 954 | + List<LspEntry> lspEntryRequestList = new ArrayList<>(); | ||
| 955 | + boolean selfOriginatedFound = false; | ||
| 956 | + if (IsisPduType.L2CSNP.equals(csnPacket.isisPduType())) { | ||
| 957 | + List<IsisTlv> isisTlvs = csnPacket.getAllTlv(); | ||
| 958 | + Iterator iterator = isisTlvs.iterator(); | ||
| 959 | + while (iterator.hasNext()) { | ||
| 960 | + IsisTlv isisTlv = (IsisTlv) iterator.next(); | ||
| 961 | + if (isisTlv instanceof LspEntriesTlv) { | ||
| 962 | + LspEntriesTlv lspEntriesTlv = (LspEntriesTlv) isisTlv; | ||
| 963 | + List<LspEntry> lspEntryList = lspEntriesTlv.lspEntry(); | ||
| 964 | + Iterator lspEntryListIterator = lspEntryList.iterator(); | ||
| 965 | + while (lspEntryListIterator.hasNext()) { | ||
| 966 | + LspEntry lspEntry = (LspEntry) lspEntryListIterator.next(); | ||
| 967 | + String lspKey = lspEntry.lspId(); | ||
| 968 | + LspWrapper lspWrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey); | ||
| 969 | + if (lspWrapper != null) { | ||
| 970 | + LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu(); | ||
| 971 | + if (lspWrapper.isSelfOriginated()) { | ||
| 972 | + selfOriginatedFound = true; | ||
| 973 | + if (lspEntry.lspSequenceNumber() > lsPdu.sequenceNumber()) { | ||
| 974 | + sendLsPduMessage(lspEntry.lspSequenceNumber(), csnPacket.isisPduType(), channel); | ||
| 975 | + } | ||
| 976 | + } else { | ||
| 977 | + if (lsPdu.sequenceNumber() < lspEntry.lspSequenceNumber()) { | ||
| 978 | + lspEntryRequestList.add(lspEntry); | ||
| 979 | + flagValue = true; | ||
| 980 | + } | ||
| 981 | + } | ||
| 982 | + } else { | ||
| 983 | + lspEntryRequestList.add(lspEntry); | ||
| 984 | + flagValue = true; | ||
| 985 | + } | ||
| 986 | + } | ||
| 987 | + } | ||
| 988 | + } | ||
| 989 | + if (flagValue) { | ||
| 990 | + sendPsnPduMessage(lspEntryRequestList, csnPacket.isisPduType(), channel); | ||
| 991 | + lspEntryRequestList.clear(); | ||
| 992 | + } | ||
| 993 | + | ||
| 994 | + if (!selfOriginatedFound) { | ||
| 995 | + String lspKey = isisLsdb.lspKey(systemId); | ||
| 996 | + LspWrapper wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey); | ||
| 997 | + sendLsp((LsPdu) wrapper.lsPdu(), channel); | ||
| 998 | + } | ||
| 999 | + } | ||
| 1000 | + } | ||
| 1001 | + | ||
| 1002 | + /** | ||
| 1003 | + * Sends the partial sequence number PDU. | ||
| 1004 | + * | ||
| 1005 | + * @param lspEntryRequestList list of lsp entry request | ||
| 1006 | + * @param isisPduType intermediate system PDU type | ||
| 1007 | + * @param channel netty channel instance | ||
| 1008 | + */ | ||
| 1009 | + private void sendPsnPduMessage(List<LspEntry> lspEntryRequestList, IsisPduType isisPduType, Channel channel) { | ||
| 1010 | + IsisPduType psnpType = null; | ||
| 1011 | + if (isisPduType == IsisPduType.L1CSNP) { | ||
| 1012 | + psnpType = IsisPduType.L1PSNP; | ||
| 1013 | + } else if (reservedPacketCircuitType == IsisRouterType.L2.value()) { | ||
| 1014 | + psnpType = IsisPduType.L2PSNP; | ||
| 1015 | + } | ||
| 1016 | + IsisHeader isisHeader = new LspGenerator().getHeader(psnpType); | ||
| 1017 | + Psnp psnp = new Psnp(isisHeader); | ||
| 1018 | + psnp.setSourceId(lspKeyP2P(this.systemId)); | ||
| 1019 | + TlvHeader tlvHeader = new TlvHeader(); | ||
| 1020 | + tlvHeader.setTlvType(TlvType.LSPENTRY.value()); | ||
| 1021 | + tlvHeader.setTlvLength(0); | ||
| 1022 | + LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader); | ||
| 1023 | + for (LspEntry lspEntry : lspEntryRequestList) { | ||
| 1024 | + lspEntriesTlv.addLspEntry(lspEntry); | ||
| 1025 | + } | ||
| 1026 | + psnp.addTlv(lspEntriesTlv); | ||
| 1027 | + //write it to channel buffer. | ||
| 1028 | + byte[] psnpBytes = psnp.asBytes(); | ||
| 1029 | + psnpBytes = IsisUtil.addLengthAndMarkItInReserved(psnpBytes, IsisConstants.LENGTHPOSITION, | ||
| 1030 | + IsisConstants.LENGTHPOSITION + 1, | ||
| 1031 | + IsisConstants.RESERVEDPOSITION); | ||
| 1032 | + flagValue = false; | ||
| 1033 | + //write to the channel | ||
| 1034 | + channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex)); | ||
| 1035 | + } | ||
| 1036 | + | ||
| 1037 | + /** | ||
| 1038 | + * Gets the LSP key. | ||
| 1039 | + * | ||
| 1040 | + * @param systemId system ID | ||
| 1041 | + * @return key | ||
| 1042 | + */ | ||
| 1043 | + public String lspKeyP2P(String systemId) { | ||
| 1044 | + StringBuilder lspKey = new StringBuilder(); | ||
| 1045 | + lspKey.append(systemId); | ||
| 1046 | + lspKey.append(".00"); | ||
| 1047 | + return lspKey.toString(); | ||
| 1048 | + } | ||
| 1049 | + | ||
| 1050 | + /** | ||
| 1051 | + * Sends the link state PDU with latest self generated lsp entry. | ||
| 1052 | + * | ||
| 1053 | + * @param sequenceNumber sequence number of the self generated lsp | ||
| 1054 | + * @param isisPduType intermediate system type | ||
| 1055 | + * @param channel netty channel instance | ||
| 1056 | + */ | ||
| 1057 | + private void sendLsPduMessage(int sequenceNumber, IsisPduType isisPduType, Channel channel) { | ||
| 1058 | + String lspKey = isisLsdb.lspKey(systemId); | ||
| 1059 | + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, isisPduType, allConfiguredInterfaceIps); | ||
| 1060 | + lsp.setSequenceNumber(sequenceNumber); | ||
| 1061 | + byte[] lspBytes = lsp.asBytes(); | ||
| 1062 | + lspBytes = IsisUtil.addLengthAndMarkItInReserved(lspBytes, IsisConstants.LENGTHPOSITION, | ||
| 1063 | + IsisConstants.LENGTHPOSITION + 1, | ||
| 1064 | + IsisConstants.RESERVEDPOSITION); | ||
| 1065 | + lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION, | ||
| 1066 | + IsisConstants.CHECKSUMPOSITION + 1); | ||
| 1067 | + //write to the channel | ||
| 1068 | + channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex)); | ||
| 1069 | + } | ||
| 1070 | + | ||
| 1071 | + | ||
| 1072 | + /** | ||
| 1073 | + * Starts the hello timer which sends hello packet every configured seconds. | ||
| 1074 | + * | ||
| 1075 | + * @param channel netty channel instance | ||
| 1076 | + */ | ||
| 1077 | + public void startHelloSender(Channel channel) { | ||
| 1078 | + log.debug("IsisInterfaceImpl::startHelloSender"); | ||
| 1079 | + | ||
| 1080 | + isisHelloPduSender = new IsisHelloPduSender(channel, this); | ||
| 1081 | + exServiceHello = Executors.newSingleThreadScheduledExecutor(); | ||
| 1082 | + final ScheduledFuture<?> helloHandle = | ||
| 1083 | + exServiceHello.scheduleAtFixedRate(isisHelloPduSender, 0, | ||
| 1084 | + helloInterval, TimeUnit.SECONDS); | ||
| 1085 | + } | ||
| 1086 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisNeighbor.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import org.onlab.packet.Ip4Address; | ||
| 19 | +import org.onlab.packet.MacAddress; | ||
| 20 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 21 | +import org.onosproject.isis.controller.IsisInterfaceState; | ||
| 22 | +import org.onosproject.isis.controller.IsisNeighbor; | ||
| 23 | +import org.onosproject.isis.controller.IsisPduType; | ||
| 24 | +import org.onosproject.isis.controller.IsisRouterType; | ||
| 25 | +import org.onosproject.isis.io.isispacket.pdu.HelloPdu; | ||
| 26 | +import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; | ||
| 27 | +import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu; | ||
| 28 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 29 | +import org.slf4j.Logger; | ||
| 30 | +import org.slf4j.LoggerFactory; | ||
| 31 | + | ||
| 32 | +import java.util.List; | ||
| 33 | +import java.util.concurrent.Executors; | ||
| 34 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 35 | +import java.util.concurrent.TimeUnit; | ||
| 36 | + | ||
| 37 | +/** | ||
| 38 | + * Representation of an ISIS neighbor. | ||
| 39 | + * The first thing an ISIS router must do is find its neighbors and form adjacency. | ||
| 40 | + * Each neighbor that the router finds will be represented by this class. | ||
| 41 | + */ | ||
| 42 | +public class DefaultIsisNeighbor implements IsisNeighbor { | ||
| 43 | + private static final Logger log = LoggerFactory.getLogger(DefaultIsisNeighbor.class); | ||
| 44 | + private String neighborAreaId; | ||
| 45 | + private String neighborSystemId; | ||
| 46 | + private Ip4Address interfaceIp; | ||
| 47 | + private MacAddress neighborMacAddress; | ||
| 48 | + private int holdingTime; | ||
| 49 | + private IsisRouterType routerType; | ||
| 50 | + private String l1LanId; | ||
| 51 | + private String l2LanId; | ||
| 52 | + private byte localCircuitId; | ||
| 53 | + private int localExtendedCircuitId; | ||
| 54 | + private IsisInterfaceState neighborState = IsisInterfaceState.INITIAL; | ||
| 55 | + private InternalInactivityTimeCheck inActivityTimeCheckTask; | ||
| 56 | + private ScheduledExecutorService exServiceInActivity; | ||
| 57 | + private boolean inActivityTimerScheduled = false; | ||
| 58 | + private IsisInterface isisInterface; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Creates an instance of ISIS neighbor. | ||
| 62 | + * | ||
| 63 | + * @param helloMessage hello message instance | ||
| 64 | + * @param isisInterface ISIS interface instance | ||
| 65 | + */ | ||
| 66 | + public DefaultIsisNeighbor(HelloPdu helloMessage, IsisInterface isisInterface) { | ||
| 67 | + this.neighborMacAddress = helloMessage.sourceMac(); | ||
| 68 | + List<String> areaAddresses = helloMessage.areaAddress(); | ||
| 69 | + this.neighborAreaId = (areaAddresses != null) ? areaAddresses.get(0) : ""; | ||
| 70 | + this.neighborSystemId = helloMessage.sourceId(); | ||
| 71 | + List<Ip4Address> interfaceIpAddresses = helloMessage.interfaceIpAddresses(); | ||
| 72 | + this.interfaceIp = (helloMessage.interfaceIpAddresses() != null) ? | ||
| 73 | + interfaceIpAddresses.get(0) : IsisConstants.DEFAULTIP; | ||
| 74 | + this.holdingTime = helloMessage.holdingTime(); | ||
| 75 | + this.routerType = IsisRouterType.get(helloMessage.circuitType()); | ||
| 76 | + if (helloMessage instanceof L1L2HelloPdu) { | ||
| 77 | + if (IsisPduType.L1HELLOPDU == helloMessage.isisPduType()) { | ||
| 78 | + l1LanId = ((L1L2HelloPdu) helloMessage).lanId(); | ||
| 79 | + } else if (IsisPduType.L2HELLOPDU == helloMessage.isisPduType()) { | ||
| 80 | + l2LanId = ((L1L2HelloPdu) helloMessage).lanId(); | ||
| 81 | + } | ||
| 82 | + } else if (helloMessage instanceof P2PHelloPdu) { | ||
| 83 | + this.localCircuitId = ((P2PHelloPdu) helloMessage).localCircuitId(); | ||
| 84 | + } | ||
| 85 | + this.isisInterface = isisInterface; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * Returns local extended circuit ID. | ||
| 90 | + * | ||
| 91 | + * @return local extended circuit ID | ||
| 92 | + */ | ||
| 93 | + public int localExtendedCircuitId() { | ||
| 94 | + return localExtendedCircuitId; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * Sets local extended circuit ID. | ||
| 99 | + * | ||
| 100 | + * @param localExtendedCircuitId neighbor extended circuit ID | ||
| 101 | + */ | ||
| 102 | + public void setLocalExtendedCircuitId(int localExtendedCircuitId) { | ||
| 103 | + this.localExtendedCircuitId = localExtendedCircuitId; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /** | ||
| 107 | + * Returns neighbor area ID. | ||
| 108 | + * | ||
| 109 | + * @return neighbor area ID | ||
| 110 | + */ | ||
| 111 | + public String neighborAreaId() { | ||
| 112 | + return neighborAreaId; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * Sets neighbor area ID. | ||
| 117 | + * | ||
| 118 | + * @param neighborAreaId neighbor area ID | ||
| 119 | + */ | ||
| 120 | + public void setNeighborAreaId(String neighborAreaId) { | ||
| 121 | + this.neighborAreaId = neighborAreaId; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * Returns neighbor system ID. | ||
| 126 | + * | ||
| 127 | + * @return neighbor system ID | ||
| 128 | + */ | ||
| 129 | + public String neighborSystemId() { | ||
| 130 | + return neighborSystemId; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * Sets neighbor system ID. | ||
| 135 | + * | ||
| 136 | + * @param neighborSystemId neighbor system ID | ||
| 137 | + */ | ||
| 138 | + public void setNeighborSystemId(String neighborSystemId) { | ||
| 139 | + this.neighborSystemId = neighborSystemId; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * Returns interface IP. | ||
| 144 | + * | ||
| 145 | + * @return interface IP | ||
| 146 | + */ | ||
| 147 | + public Ip4Address interfaceIp() { | ||
| 148 | + return interfaceIp; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + /** | ||
| 152 | + * Sets interface IP. | ||
| 153 | + * | ||
| 154 | + * @param interfaceIp IP | ||
| 155 | + */ | ||
| 156 | + public void setInterfaceIp(Ip4Address interfaceIp) { | ||
| 157 | + this.interfaceIp = interfaceIp; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + /** | ||
| 161 | + * Returns neighbor mac address. | ||
| 162 | + * | ||
| 163 | + * @return neighborMacAddress neighbor mac address | ||
| 164 | + */ | ||
| 165 | + public MacAddress neighborMacAddress() { | ||
| 166 | + return neighborMacAddress; | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + /** | ||
| 170 | + * Sets neighbor mac address. | ||
| 171 | + * | ||
| 172 | + * @param neighborMacAddress mac address | ||
| 173 | + */ | ||
| 174 | + public void setNeighborMacAddress(MacAddress neighborMacAddress) { | ||
| 175 | + this.neighborMacAddress = neighborMacAddress; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + /** | ||
| 179 | + * Returns holding time. | ||
| 180 | + * | ||
| 181 | + * @return holding time | ||
| 182 | + */ | ||
| 183 | + public int holdingTime() { | ||
| 184 | + return holdingTime; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * Sets holding time. | ||
| 189 | + * | ||
| 190 | + * @param holdingTime holding time | ||
| 191 | + */ | ||
| 192 | + public void setHoldingTime(int holdingTime) { | ||
| 193 | + this.holdingTime = holdingTime; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + /** | ||
| 197 | + * Returns router type. | ||
| 198 | + * | ||
| 199 | + * @return router type | ||
| 200 | + */ | ||
| 201 | + public IsisRouterType routerType() { | ||
| 202 | + return routerType; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + /** | ||
| 206 | + * Sets router type. | ||
| 207 | + * | ||
| 208 | + * @param routerType router type | ||
| 209 | + */ | ||
| 210 | + public void setRouterType(IsisRouterType routerType) { | ||
| 211 | + this.routerType = routerType; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + /** | ||
| 215 | + * Returns L1 lan ID. | ||
| 216 | + * | ||
| 217 | + * @return L1 lan ID | ||
| 218 | + */ | ||
| 219 | + public String l1LanId() { | ||
| 220 | + return l1LanId; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + /** | ||
| 224 | + * Sets L1 lan ID. | ||
| 225 | + * | ||
| 226 | + * @param l1LanId L1 lan ID | ||
| 227 | + */ | ||
| 228 | + public void setL1LanId(String l1LanId) { | ||
| 229 | + this.l1LanId = l1LanId; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + /** | ||
| 233 | + * Returns L2 lan ID. | ||
| 234 | + * | ||
| 235 | + * @return L2 lan ID | ||
| 236 | + */ | ||
| 237 | + public String l2LanId() { | ||
| 238 | + return l2LanId; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + /** | ||
| 242 | + * Sets L2 lan ID. | ||
| 243 | + * | ||
| 244 | + * @param l2LanId L2 lan ID | ||
| 245 | + */ | ||
| 246 | + public void setL2LanId(String l2LanId) { | ||
| 247 | + this.l1LanId = l1LanId; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + /** | ||
| 251 | + * Gets the neighbor interface state. | ||
| 252 | + * | ||
| 253 | + * @return neighbor interface state | ||
| 254 | + */ | ||
| 255 | + public IsisInterfaceState interfaceState() { | ||
| 256 | + return neighborState; | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + /** | ||
| 260 | + * Sets the neighbor interface state. | ||
| 261 | + * | ||
| 262 | + * @param neighborState the neighbor interface state | ||
| 263 | + */ | ||
| 264 | + public void setNeighborState(IsisInterfaceState neighborState) { | ||
| 265 | + this.neighborState = neighborState; | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + /** | ||
| 269 | + * Returns local circuit ID. | ||
| 270 | + * | ||
| 271 | + * @return local circuit ID | ||
| 272 | + */ | ||
| 273 | + public byte localCircuitId() { | ||
| 274 | + return localCircuitId; | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + /** | ||
| 278 | + * Sets local circuit ID. | ||
| 279 | + * | ||
| 280 | + * @param localCircuitId local circuit ID | ||
| 281 | + */ | ||
| 282 | + public void setLocalCircuitId(byte localCircuitId) { | ||
| 283 | + this.localCircuitId = localCircuitId; | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + /** | ||
| 287 | + * Returns neighbor state. | ||
| 288 | + * | ||
| 289 | + * @return neighbor state | ||
| 290 | + */ | ||
| 291 | + public IsisInterfaceState neighborState() { | ||
| 292 | + return neighborState; | ||
| 293 | + } | ||
| 294 | + | ||
| 295 | + /** | ||
| 296 | + * Starts the inactivity timer. | ||
| 297 | + */ | ||
| 298 | + public void startInactivityTimeCheck() { | ||
| 299 | + if (!inActivityTimerScheduled) { | ||
| 300 | + log.debug("IsisNeighbor::startInactivityTimeCheck"); | ||
| 301 | + inActivityTimeCheckTask = new InternalInactivityTimeCheck(); | ||
| 302 | + exServiceInActivity = Executors.newSingleThreadScheduledExecutor(); | ||
| 303 | + exServiceInActivity.scheduleAtFixedRate(inActivityTimeCheckTask, holdingTime, | ||
| 304 | + holdingTime, TimeUnit.SECONDS); | ||
| 305 | + inActivityTimerScheduled = true; | ||
| 306 | + } | ||
| 307 | + } | ||
| 308 | + | ||
| 309 | + /** | ||
| 310 | + * Stops the inactivity timer. | ||
| 311 | + */ | ||
| 312 | + public void stopInactivityTimeCheck() { | ||
| 313 | + if (inActivityTimerScheduled) { | ||
| 314 | + log.debug("IsisNeighbor::stopInactivityTimeCheck "); | ||
| 315 | + exServiceInActivity.shutdown(); | ||
| 316 | + inActivityTimerScheduled = false; | ||
| 317 | + } | ||
| 318 | + } | ||
| 319 | + | ||
| 320 | + /** | ||
| 321 | + * Called when neighbor is down. | ||
| 322 | + */ | ||
| 323 | + public void neighborDown() { | ||
| 324 | + log.debug("Neighbor Down {} and NeighborSystemId {}", neighborMacAddress, | ||
| 325 | + neighborSystemId); | ||
| 326 | + stopInactivityTimeCheck(); | ||
| 327 | + isisInterface.setL1LanId(IsisConstants.DEFAULTLANID); | ||
| 328 | + isisInterface.setL2LanId(IsisConstants.DEFAULTLANID); | ||
| 329 | + | ||
| 330 | + neighborState = IsisInterfaceState.DOWN; | ||
| 331 | + isisInterface.removeNeighbor(this); | ||
| 332 | + } | ||
| 333 | + | ||
| 334 | + /** | ||
| 335 | + * Represents a Task which will do an inactivity time check. | ||
| 336 | + */ | ||
| 337 | + private class InternalInactivityTimeCheck implements Runnable { | ||
| 338 | + /** | ||
| 339 | + * Creates an instance. | ||
| 340 | + */ | ||
| 341 | + InternalInactivityTimeCheck() { | ||
| 342 | + } | ||
| 343 | + | ||
| 344 | + @Override | ||
| 345 | + public void run() { | ||
| 346 | + log.debug("Neighbor Not Heard till the past router dead interval ."); | ||
| 347 | + neighborDown(); | ||
| 348 | + } | ||
| 349 | + } | ||
| 350 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisProcess.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 19 | +import org.onosproject.isis.controller.IsisProcess; | ||
| 20 | + | ||
| 21 | +import java.util.List; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Represents of an ISIS process. | ||
| 25 | + */ | ||
| 26 | +public class DefaultIsisProcess implements IsisProcess { | ||
| 27 | + private String processId; | ||
| 28 | + private List<IsisInterface> isisInterfaceList; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Gets process ID. | ||
| 32 | + * | ||
| 33 | + * @return process ID | ||
| 34 | + */ | ||
| 35 | + public String processId() { | ||
| 36 | + return processId; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * Sets process ID. | ||
| 41 | + * | ||
| 42 | + * @param processId process ID | ||
| 43 | + */ | ||
| 44 | + public void setProcessId(String processId) { | ||
| 45 | + this.processId = processId; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Gets list of ISIS interface details. | ||
| 50 | + * | ||
| 51 | + * @return list of ISIS interface details | ||
| 52 | + */ | ||
| 53 | + public List<IsisInterface> isisInterfaceList() { | ||
| 54 | + return isisInterfaceList; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * Sets list of ISIS interface details. | ||
| 59 | + * | ||
| 60 | + * @param isisInterfaceList list of ISIS interface details | ||
| 61 | + */ | ||
| 62 | + public void setIsisInterfaceList(List<IsisInterface> isisInterfaceList) { | ||
| 63 | + this.isisInterfaceList = isisInterfaceList; | ||
| 64 | + } | ||
| 65 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisChannelHandler.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import org.jboss.netty.channel.Channel; | ||
| 19 | +import org.jboss.netty.channel.ChannelHandlerContext; | ||
| 20 | +import org.jboss.netty.channel.ChannelStateEvent; | ||
| 21 | +import org.jboss.netty.channel.ExceptionEvent; | ||
| 22 | +import org.jboss.netty.channel.MessageEvent; | ||
| 23 | +import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; | ||
| 24 | +import org.jboss.netty.handler.timeout.ReadTimeoutException; | ||
| 25 | +import org.onlab.packet.Ip4Address; | ||
| 26 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 27 | +import org.onosproject.isis.controller.IsisLsdb; | ||
| 28 | +import org.onosproject.isis.controller.IsisMessage; | ||
| 29 | +import org.onosproject.isis.controller.IsisProcess; | ||
| 30 | +import org.onosproject.isis.controller.impl.lsdb.DefaultIsisLsdb; | ||
| 31 | +import org.onosproject.isis.exceptions.IsisParseException; | ||
| 32 | +import org.slf4j.Logger; | ||
| 33 | +import org.slf4j.LoggerFactory; | ||
| 34 | + | ||
| 35 | +import java.io.IOException; | ||
| 36 | +import java.nio.channels.ClosedChannelException; | ||
| 37 | +import java.util.ArrayList; | ||
| 38 | +import java.util.List; | ||
| 39 | +import java.util.Map; | ||
| 40 | +import java.util.Set; | ||
| 41 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 42 | +import java.util.concurrent.RejectedExecutionException; | ||
| 43 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 44 | + | ||
| 45 | +/** | ||
| 46 | + * Channel handler deals with the ISIS channel connection. | ||
| 47 | + * Also it dispatches messages to the appropriate handlers for processing. | ||
| 48 | + */ | ||
| 49 | +public class IsisChannelHandler extends IdleStateAwareChannelHandler { | ||
| 50 | + | ||
| 51 | + private static final Logger log = LoggerFactory.getLogger(IsisChannelHandler.class); | ||
| 52 | + private static Map<Integer, Object> isisDb = null; | ||
| 53 | + private Channel channel; | ||
| 54 | + private Controller controller; | ||
| 55 | + private List<IsisProcess> processes = null; | ||
| 56 | + private List<ScheduledExecutorService> executorList = new ArrayList<>(); | ||
| 57 | + private byte[] configPacket = null; | ||
| 58 | + private Map<Integer, IsisInterface> isisInterfaceMap = new ConcurrentHashMap<>(); | ||
| 59 | + private IsisLsdb isisLsdb = new DefaultIsisLsdb(); | ||
| 60 | + private List<Ip4Address> interfaceIps = new ArrayList<>(); | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Creates an instance of ISIS channel handler. | ||
| 64 | + * | ||
| 65 | + * @param controller controller instance | ||
| 66 | + * @param processes list of configured processes | ||
| 67 | + */ | ||
| 68 | + public IsisChannelHandler(Controller controller, List<IsisProcess> processes) { | ||
| 69 | + this.controller = controller; | ||
| 70 | + this.processes = processes; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * Initializes the interface map with interface details. | ||
| 75 | + */ | ||
| 76 | + public void initializeInterfaceMap() { | ||
| 77 | + for (IsisProcess process : processes) { | ||
| 78 | + for (IsisInterface isisInterface : process.isisInterfaceList()) { | ||
| 79 | + isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface); | ||
| 80 | + interfaceIps.add(isisInterface.interfaceIpAddress()); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + //Initializes the interface with all interface ip details - for ls pdu generation | ||
| 84 | + initializeInterfaceIpList(); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Updates the interface map with interface details. | ||
| 89 | + * | ||
| 90 | + * @param isisProcesses updated process instances | ||
| 91 | + */ | ||
| 92 | + public void updateInterfaceMap(List<IsisProcess> isisProcesses) { | ||
| 93 | + for (IsisProcess isisUpdatedProcess : isisProcesses) { | ||
| 94 | + for (IsisInterface isisUpdatedInterface : isisUpdatedProcess.isisInterfaceList()) { | ||
| 95 | + IsisInterface isisInterface = isisInterfaceMap.get(isisUpdatedInterface.interfaceIndex()); | ||
| 96 | + if (isisInterface == null) { | ||
| 97 | + isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface); | ||
| 98 | + interfaceIps.add(isisInterface.interfaceIpAddress()); | ||
| 99 | + } else { | ||
| 100 | + isisInterface.setReservedPacketCircuitType(isisUpdatedInterface.reservedPacketCircuitType()); | ||
| 101 | + isisInterface.setNetworkType(isisUpdatedInterface.networkType()); | ||
| 102 | + isisInterface.setHoldingTime(isisUpdatedInterface.holdingTime()); | ||
| 103 | + isisInterface.setHelloInterval(isisUpdatedInterface.helloInterval()); | ||
| 104 | + isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface); | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * Initializes the interface with all interface ip details. | ||
| 112 | + */ | ||
| 113 | + public void initializeInterfaceIpList() { | ||
| 114 | + for (IsisProcess process : processes) { | ||
| 115 | + for (IsisInterface isisInterface : process.isisInterfaceList()) { | ||
| 116 | + ((DefaultIsisInterface) isisInterface).setAllConfiguredInterfaceIps(interfaceIps); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * Initialize channel, start hello sender and initialize LSDB. | ||
| 123 | + */ | ||
| 124 | + private void initialize() { | ||
| 125 | + log.debug("IsisChannelHandler initialize..!!!"); | ||
| 126 | + if (configPacket != null) { | ||
| 127 | + log.debug("IsisChannelHandler initialize -> sentConfig packet of length ::" | ||
| 128 | + + configPacket.length); | ||
| 129 | + sentConfigPacket(configPacket); | ||
| 130 | + } | ||
| 131 | + //start the hello timer | ||
| 132 | + startHelloSender(); | ||
| 133 | + //Initialize Database | ||
| 134 | + isisLsdb.initializeDb(); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent evt) throws Exception { | ||
| 139 | + log.info("ISIS channelConnected from {}", evt.getChannel().getRemoteAddress()); | ||
| 140 | + this.channel = evt.getChannel(); | ||
| 141 | + initialize(); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + @Override | ||
| 145 | + public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) { | ||
| 146 | + log.debug("IsisChannelHandler::channelDisconnected...!!!"); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + @Override | ||
| 150 | + public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { | ||
| 151 | + log.info("[exceptionCaught]: " + e.toString()); | ||
| 152 | + if (e.getCause() instanceof ReadTimeoutException) { | ||
| 153 | + log.error("Disconnecting device {} due to read timeout", e.getChannel().getRemoteAddress()); | ||
| 154 | + return; | ||
| 155 | + } else if (e.getCause() instanceof ClosedChannelException) { | ||
| 156 | + log.debug("Channel for ISIS {} already closed", e.getChannel().getRemoteAddress()); | ||
| 157 | + } else if (e.getCause() instanceof IOException) { | ||
| 158 | + log.error("Disconnecting ISIS {} due to IO Error: {}", e.getChannel().getRemoteAddress(), | ||
| 159 | + e.getCause().getMessage()); | ||
| 160 | + if (log.isDebugEnabled()) { | ||
| 161 | + log.debug("StackTrace for previous Exception: {}", e.getCause()); | ||
| 162 | + } | ||
| 163 | + } else if (e.getCause() instanceof IsisParseException) { | ||
| 164 | + IsisParseException errMsg = (IsisParseException) e.getCause(); | ||
| 165 | + byte errorCode = errMsg.errorCode(); | ||
| 166 | + byte errorSubCode = errMsg.errorSubCode(); | ||
| 167 | + log.error("Error while parsing message from ISIS {}, ErrorCode {}", | ||
| 168 | + e.getChannel().getRemoteAddress(), errorCode); | ||
| 169 | + } else if (e.getCause() instanceof RejectedExecutionException) { | ||
| 170 | + log.warn("Could not process message: queue full"); | ||
| 171 | + } else { | ||
| 172 | + log.error("Error while processing message from ISIS {}", | ||
| 173 | + e.getChannel().getRemoteAddress()); | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + @Override | ||
| 178 | + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { | ||
| 179 | + log.debug("IsisChannelHandler::messageReceived...!!!"); | ||
| 180 | + Object message = e.getMessage(); | ||
| 181 | + if (message instanceof List) { | ||
| 182 | + List<IsisMessage> isisMessageList = (List<IsisMessage>) message; | ||
| 183 | + log.debug("IsisChannelHandler::List of IsisMessages Size {}", isisMessageList.size()); | ||
| 184 | + if (isisMessageList != null) { | ||
| 185 | + for (IsisMessage isisMessage : isisMessageList) { | ||
| 186 | + processIsisMessage(isisMessage, ctx); | ||
| 187 | + } | ||
| 188 | + } else { | ||
| 189 | + log.debug("IsisChannelHandler::IsisMessages Null List...!!"); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + if (message instanceof IsisMessage) { | ||
| 193 | + IsisMessage isisMessage = (IsisMessage) message; | ||
| 194 | + log.debug("IsisChannelHandler::IsisMessages received...!!"); | ||
| 195 | + processIsisMessage(isisMessage, ctx); | ||
| 196 | + } | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + /** | ||
| 200 | + * When an ISIS message received it is handed over to this method. | ||
| 201 | + * Based on the type of the ISIS message received it will be handed over | ||
| 202 | + * to corresponding message handler methods. | ||
| 203 | + * | ||
| 204 | + * @param isisMessage received ISIS message | ||
| 205 | + * @param ctx channel handler context instance. | ||
| 206 | + * @throws Exception might throws exception | ||
| 207 | + */ | ||
| 208 | + public void processIsisMessage(IsisMessage isisMessage, ChannelHandlerContext ctx) throws Exception { | ||
| 209 | + log.debug("IsisChannelHandler::processIsisMessage...!!!"); | ||
| 210 | + int interfaceIndex = isisMessage.interfaceIndex(); | ||
| 211 | + IsisInterface isisInterface = isisInterfaceMap.get(interfaceIndex); | ||
| 212 | + isisInterface.processIsisMessage(isisMessage, isisLsdb, channel); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * Starts the hello timer which sends hello packet every configured seconds. | ||
| 217 | + */ | ||
| 218 | + public void startHelloSender() { | ||
| 219 | + log.debug("IsisController::startHelloSender"); | ||
| 220 | + Set<Integer> interfaceIndexes = isisInterfaceMap.keySet(); | ||
| 221 | + for (Integer interfaceIndex : interfaceIndexes) { | ||
| 222 | + IsisInterface isisInterface = isisInterfaceMap.get(interfaceIndex); | ||
| 223 | + isisInterface.startHelloSender(channel); | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + /** | ||
| 228 | + * Stops the hello timer. | ||
| 229 | + */ | ||
| 230 | + public void stopHelloSender() { | ||
| 231 | + log.debug("ISISChannelHandler::stopHelloTimer "); | ||
| 232 | + for (ScheduledExecutorService exServiceHello : executorList) { | ||
| 233 | + exServiceHello.shutdown(); | ||
| 234 | + } | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + /** | ||
| 238 | + * Sends the interface configuration packet to server. | ||
| 239 | + * | ||
| 240 | + * @param configPacket interface configuration | ||
| 241 | + */ | ||
| 242 | + public void sentConfigPacket(byte[] configPacket) { | ||
| 243 | + if (channel != null) { | ||
| 244 | + channel.write(configPacket); | ||
| 245 | + log.debug("IsisChannelHandler sentConfigPacket packet sent..!!!"); | ||
| 246 | + } else { | ||
| 247 | + log.debug("IsisChannelHandler sentConfigPacket channel not connected - re try..!!!"); | ||
| 248 | + this.configPacket = configPacket; | ||
| 249 | + } | ||
| 250 | + } | ||
| 251 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisHelloPduSender.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import com.google.common.primitives.Bytes; | ||
| 19 | +import org.jboss.netty.channel.Channel; | ||
| 20 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 21 | +import org.onosproject.isis.controller.IsisNetworkType; | ||
| 22 | +import org.onosproject.isis.controller.IsisRouterType; | ||
| 23 | +import org.onosproject.isis.io.util.IsisUtil; | ||
| 24 | +import org.slf4j.Logger; | ||
| 25 | +import org.slf4j.LoggerFactory; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * Representation of an ISIS hello pdu sender task. | ||
| 29 | + */ | ||
| 30 | +public class IsisHelloPduSender implements Runnable { | ||
| 31 | + private static final Logger log = LoggerFactory.getLogger(IsisHelloPduSender.class); | ||
| 32 | + private Channel channel = null; | ||
| 33 | + private IsisInterface isisInterface = null; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * Creates an instance of Hello PDU Sender task. | ||
| 37 | + * | ||
| 38 | + * @param channel netty channel instance | ||
| 39 | + * @param isisInterface ISIS interface instance | ||
| 40 | + */ | ||
| 41 | + public IsisHelloPduSender(Channel channel, IsisInterface isisInterface) { | ||
| 42 | + this.channel = channel; | ||
| 43 | + this.isisInterface = isisInterface; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public void run() { | ||
| 48 | + if (channel != null) { | ||
| 49 | + try { | ||
| 50 | + byte[] helloPdu = null; | ||
| 51 | + byte[] interfaceIndex = {(byte) isisInterface.interfaceIndex()}; | ||
| 52 | + | ||
| 53 | + if (isisInterface.networkType() == IsisNetworkType.P2P) { | ||
| 54 | + helloPdu = IsisUtil.getP2pHelloPdu(isisInterface, true); | ||
| 55 | + helloPdu = Bytes.concat(helloPdu, interfaceIndex); | ||
| 56 | + channel.write(helloPdu); | ||
| 57 | + } else if (isisInterface.networkType() == IsisNetworkType.BROADCAST) { | ||
| 58 | + switch (IsisRouterType.get(isisInterface.reservedPacketCircuitType())) { | ||
| 59 | + case L1: | ||
| 60 | + helloPdu = IsisUtil.getL1HelloPdu(isisInterface, true); | ||
| 61 | + helloPdu = Bytes.concat(helloPdu, interfaceIndex); | ||
| 62 | + channel.write(helloPdu); | ||
| 63 | + break; | ||
| 64 | + case L2: | ||
| 65 | + helloPdu = IsisUtil.getL2HelloPdu(isisInterface, true); | ||
| 66 | + helloPdu = Bytes.concat(helloPdu, interfaceIndex); | ||
| 67 | + channel.write(helloPdu); | ||
| 68 | + break; | ||
| 69 | + case L1L2: | ||
| 70 | + helloPdu = IsisUtil.getL1HelloPdu(isisInterface, true); | ||
| 71 | + helloPdu = Bytes.concat(helloPdu, interfaceIndex); | ||
| 72 | + channel.write(helloPdu); | ||
| 73 | + | ||
| 74 | + helloPdu = IsisUtil.getL2HelloPdu(isisInterface, true); | ||
| 75 | + helloPdu = Bytes.concat(helloPdu, interfaceIndex); | ||
| 76 | + channel.write(helloPdu); | ||
| 77 | + break; | ||
| 78 | + default: | ||
| 79 | + log.debug("IsisHelloPduSender::Unknown circuit type...!!!"); | ||
| 80 | + break; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + } catch (Exception e) { | ||
| 84 | + log.debug("Exception @IsisHelloPduSender:: {}", e.getMessage()); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisMessageDecoder.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.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.onlab.packet.MacAddress; | ||
| 23 | +import org.onosproject.isis.controller.IsisMessage; | ||
| 24 | +import org.onosproject.isis.io.isispacket.IsisMessageReader; | ||
| 25 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 26 | +import org.onosproject.isis.io.util.IsisUtil; | ||
| 27 | +import org.slf4j.Logger; | ||
| 28 | +import org.slf4j.LoggerFactory; | ||
| 29 | + | ||
| 30 | +import java.util.LinkedList; | ||
| 31 | +import java.util.List; | ||
| 32 | + | ||
| 33 | +/** | ||
| 34 | + * Decodes an ISIS message from a Channel, for use in a netty pipeline. | ||
| 35 | + */ | ||
| 36 | +public class IsisMessageDecoder extends FrameDecoder { | ||
| 37 | + | ||
| 38 | + private static final Logger log = LoggerFactory.getLogger(IsisMessageDecoder.class); | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { | ||
| 42 | + log.debug("IsisMessageDecoder::Message received <:> length {}", buffer.readableBytes()); | ||
| 43 | + if (!channel.isConnected()) { | ||
| 44 | + log.info("Channel is not connected."); | ||
| 45 | + return null; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + IsisMessageReader messageReader = new IsisMessageReader(); | ||
| 49 | + List<IsisMessage> isisMessageList = new LinkedList<>(); | ||
| 50 | + int dataLength = buffer.readableBytes(); | ||
| 51 | + while (buffer.readableBytes() >= IsisConstants.MINIMUM_FRAME_LEN) { | ||
| 52 | + ChannelBuffer payload = buffer.readBytes(IsisConstants.MINIMUM_FRAME_LEN); | ||
| 53 | + ChannelBuffer ethernetHeader = payload.readBytes(IsisUtil.ETHER_HEADER_LEN); | ||
| 54 | + //Read the Source MAC address from ethernet header at the 6th position | ||
| 55 | + MacAddress sourceMac = getSourceMac(ethernetHeader); | ||
| 56 | + //Strip 17 byte ethernet header and get the ISIS data buffer | ||
| 57 | + ChannelBuffer isisDataBuffer = payload.readBytes(payload.readableBytes()); | ||
| 58 | + int readableBytes = isisDataBuffer.readableBytes(); | ||
| 59 | + IsisMessage message = messageReader.readFromBuffer(isisDataBuffer); | ||
| 60 | + //Last 7 bytes is metadata. ie. interface MAC address and interface index. | ||
| 61 | + if (message != null) { | ||
| 62 | + if (isisDataBuffer.readableBytes() >= IsisConstants.METADATA_LEN) { | ||
| 63 | + //Sets the source MAC | ||
| 64 | + message.setSourceMac(sourceMac); | ||
| 65 | + isisDataBuffer.readerIndex(readableBytes - IsisConstants.METADATA_LEN); | ||
| 66 | + log.debug("IsisMessageDecoder::Reading metadata <:> length {}", isisDataBuffer.readableBytes()); | ||
| 67 | + byte[] macBytes = new byte[IsisUtil.SIX_BYTES]; | ||
| 68 | + isisDataBuffer.readBytes(macBytes, 0, IsisUtil.SIX_BYTES); | ||
| 69 | + MacAddress macAddress = MacAddress.valueOf(macBytes); | ||
| 70 | + int interfaceIndex = isisDataBuffer.readByte(); | ||
| 71 | + message.setInterfaceMac(macAddress); | ||
| 72 | + message.setInterfaceIndex(interfaceIndex); | ||
| 73 | + } | ||
| 74 | + isisMessageList.add(message); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + return isisMessageList; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * Gets the source MAC address from the ethernet header. | ||
| 83 | + * | ||
| 84 | + * @param ethHeader ethernet header bytes | ||
| 85 | + * @return MAC address of the source router | ||
| 86 | + */ | ||
| 87 | + private MacAddress getSourceMac(ChannelBuffer ethHeader) { | ||
| 88 | + //Source MAC is at position 6 to 11 (6 bytes) | ||
| 89 | + ethHeader.skipBytes(IsisUtil.SIX_BYTES); | ||
| 90 | + MacAddress sourceMac = MacAddress.valueOf(ethHeader.readBytes(IsisUtil.SIX_BYTES).array()); | ||
| 91 | + | ||
| 92 | + return sourceMac; | ||
| 93 | + } | ||
| 94 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisMessageEncoder.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl; | ||
| 17 | + | ||
| 18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 19 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
| 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.slf4j.Logger; | ||
| 24 | +import org.slf4j.LoggerFactory; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Encodes an ISIS message for output into a ChannelBuffer, for use in a netty pipeline. | ||
| 28 | + */ | ||
| 29 | +public class IsisMessageEncoder extends OneToOneEncoder { | ||
| 30 | + private static final Logger log = LoggerFactory.getLogger(IsisMessageEncoder.class); | ||
| 31 | + | ||
| 32 | + @Override | ||
| 33 | + protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { | ||
| 34 | + | ||
| 35 | + byte[] byteMsg = (byte[]) msg; | ||
| 36 | + log.debug("Encoding isisMessage of length {}", byteMsg.length); | ||
| 37 | + ChannelBuffer channelBuffer = ChannelBuffers.buffer(byteMsg.length); | ||
| 38 | + channelBuffer.writeBytes(byteMsg); | ||
| 39 | + | ||
| 40 | + return channelBuffer; | ||
| 41 | + } | ||
| 42 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/IsisPipelineFactory.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.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 | + | ||
| 22 | +/** | ||
| 23 | + * Creates a ChannelPipeline for a client-side ISIS channel. | ||
| 24 | + */ | ||
| 25 | +public class IsisPipelineFactory implements ChannelPipelineFactory { | ||
| 26 | + private IsisChannelHandler isisChannelHandler; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * Creates an instance of ISIS channel pipeline factory. | ||
| 30 | + * | ||
| 31 | + * @param isisChannelHandler ISIS channel handler instance | ||
| 32 | + */ | ||
| 33 | + public IsisPipelineFactory(IsisChannelHandler isisChannelHandler) { | ||
| 34 | + this.isisChannelHandler = isisChannelHandler; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public ChannelPipeline getPipeline() throws Exception { | ||
| 39 | + ChannelPipeline pipeline = Channels.pipeline(); | ||
| 40 | + pipeline.addLast("encoder", new IsisMessageDecoder()); | ||
| 41 | + pipeline.addLast("decoder", new IsisMessageEncoder()); | ||
| 42 | + pipeline.addLast("handler", isisChannelHandler); | ||
| 43 | + | ||
| 44 | + return pipeline; | ||
| 45 | + } | ||
| 46 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/lsdb/DefaultIsisLsdb.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl.lsdb; | ||
| 17 | + | ||
| 18 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 19 | +import org.onosproject.isis.controller.IsisLsdb; | ||
| 20 | +import org.onosproject.isis.controller.IsisLsdbAge; | ||
| 21 | +import org.onosproject.isis.controller.IsisLspBin; | ||
| 22 | +import org.onosproject.isis.controller.IsisMessage; | ||
| 23 | +import org.onosproject.isis.controller.IsisPduType; | ||
| 24 | +import org.onosproject.isis.controller.LspWrapper; | ||
| 25 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
| 26 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 27 | +import org.slf4j.Logger; | ||
| 28 | +import org.slf4j.LoggerFactory; | ||
| 29 | + | ||
| 30 | +import java.util.Iterator; | ||
| 31 | +import java.util.List; | ||
| 32 | +import java.util.Map; | ||
| 33 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 34 | +import java.util.concurrent.CopyOnWriteArrayList; | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * Representation of ISIS link state database. | ||
| 38 | + */ | ||
| 39 | +public class DefaultIsisLsdb implements IsisLsdb { | ||
| 40 | + private static final Logger log = LoggerFactory.getLogger(DefaultIsisLsdb.class); | ||
| 41 | + private Map<String, LspWrapper> isisL1Db = new ConcurrentHashMap<>(); | ||
| 42 | + private Map<String, LspWrapper> isisL2Db = new ConcurrentHashMap<>(); | ||
| 43 | + private IsisLsdbAge lsdbAge = null; | ||
| 44 | + private int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; | ||
| 45 | + private int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Creates an instance of ISIS LSDB. | ||
| 49 | + */ | ||
| 50 | + public DefaultIsisLsdb() { | ||
| 51 | + lsdbAge = new DefaultIsisLsdbAge(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * Initializes the link state database. | ||
| 56 | + */ | ||
| 57 | + public void initializeDb() { | ||
| 58 | + lsdbAge.startDbAging(); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * Returns the LSDB LSP key. | ||
| 63 | + * | ||
| 64 | + * @param systemId system ID | ||
| 65 | + * @return key | ||
| 66 | + */ | ||
| 67 | + public String lspKey(String systemId) { | ||
| 68 | + StringBuilder lspKey = new StringBuilder(); | ||
| 69 | + lspKey.append(systemId); | ||
| 70 | + lspKey.append(".00"); | ||
| 71 | + lspKey.append("-"); | ||
| 72 | + lspKey.append("00"); | ||
| 73 | + | ||
| 74 | + return lspKey.toString(); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Returns the neighbor L1 database information. | ||
| 79 | + * | ||
| 80 | + * @return neighbor L1 database information | ||
| 81 | + */ | ||
| 82 | + public Map<String, LspWrapper> getL1Db() { | ||
| 83 | + return isisL1Db; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Returns the neighbor L2 database information. | ||
| 88 | + * | ||
| 89 | + * @return neighbor L2 database information | ||
| 90 | + */ | ||
| 91 | + public Map<String, LspWrapper> getL2Db() { | ||
| 92 | + return isisL2Db; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * Returns the LSDB instance. | ||
| 97 | + * | ||
| 98 | + * @return LSDB instance | ||
| 99 | + */ | ||
| 100 | + public IsisLsdb isisLsdb() { | ||
| 101 | + return this; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Returns all LSPs (L1 and L2). | ||
| 106 | + * | ||
| 107 | + * @param excludeMaxAgeLsp exclude the max age LSPs | ||
| 108 | + * @return List of LSPs | ||
| 109 | + */ | ||
| 110 | + public List<LspWrapper> allLspHeaders(boolean excludeMaxAgeLsp) { | ||
| 111 | + List<LspWrapper> summaryList = new CopyOnWriteArrayList(); | ||
| 112 | + addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL1Db); | ||
| 113 | + addLspToHeaderList(summaryList, excludeMaxAgeLsp, isisL2Db); | ||
| 114 | + | ||
| 115 | + return summaryList; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * Adds the LSPs to summary list. | ||
| 120 | + * | ||
| 121 | + * @param summaryList summary list | ||
| 122 | + * @param excludeMaxAgeLsp exclude max age LSP | ||
| 123 | + * @param lspMap map of LSP | ||
| 124 | + */ | ||
| 125 | + private void addLspToHeaderList(List summaryList, boolean excludeMaxAgeLsp, Map lspMap) { | ||
| 126 | + Iterator slotVals = lspMap.values().iterator(); | ||
| 127 | + while (slotVals.hasNext()) { | ||
| 128 | + LspWrapper wrapper = (LspWrapper) slotVals.next(); | ||
| 129 | + if (excludeMaxAgeLsp) { | ||
| 130 | + //if current age of lsa is max age or lsa present in Max Age bin | ||
| 131 | + if (wrapper.remainingLifetime() != 0) { | ||
| 132 | + addToList(wrapper, summaryList); | ||
| 133 | + } | ||
| 134 | + } else { | ||
| 135 | + addToList(wrapper, summaryList); | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * Adds the LSPWrapper to summary list. | ||
| 142 | + * | ||
| 143 | + * @param wrapper LSP wrapper instance | ||
| 144 | + * @param summList LSP summary list | ||
| 145 | + */ | ||
| 146 | + private void addToList(LspWrapper wrapper, List summList) { | ||
| 147 | + //set the current age | ||
| 148 | + ((LsPdu) wrapper.lsPdu()).setRemainingLifeTime(wrapper.remainingLifetime()); | ||
| 149 | + summList.add(wrapper); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * Finds the LSP from appropriate maps L1 or L2 based on type. | ||
| 154 | + * | ||
| 155 | + * @param pduType L1 or L2 LSP | ||
| 156 | + * @param lspId LSP ID | ||
| 157 | + * @return LSP wrapper object | ||
| 158 | + */ | ||
| 159 | + public LspWrapper findLsp(IsisPduType pduType, String lspId) { | ||
| 160 | + LspWrapper lspWrapper = null; | ||
| 161 | + | ||
| 162 | + switch (pduType) { | ||
| 163 | + case L1LSPDU: | ||
| 164 | + lspWrapper = isisL1Db.get(lspId); | ||
| 165 | + break; | ||
| 166 | + case L2LSPDU: | ||
| 167 | + lspWrapper = isisL2Db.get(lspId); | ||
| 168 | + break; | ||
| 169 | + default: | ||
| 170 | + log.debug("Unknown LSP type..!!!"); | ||
| 171 | + break; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + //set the current age | ||
| 175 | + if (lspWrapper != null) { | ||
| 176 | + //set the current age | ||
| 177 | + ((DefaultLspWrapper) lspWrapper).lsPdu().setRemainingLifeTime(lspWrapper.remainingLifetime()); | ||
| 178 | + } | ||
| 179 | + | ||
| 180 | + return lspWrapper; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * Installs a new self-originated LSP. | ||
| 185 | + * | ||
| 186 | + * @return true if successfully added | ||
| 187 | + */ | ||
| 188 | + public boolean addLsp(IsisMessage isisMessage, boolean isSelfOriginated, IsisInterface isisInterface) { | ||
| 189 | + LsPdu lspdu = (LsPdu) isisMessage; | ||
| 190 | + DefaultLspWrapper lspWrapper = new DefaultLspWrapper(); | ||
| 191 | + lspWrapper.setLspAgeReceived(IsisConstants.LSPMAXAGE - lspdu.remainingLifeTime()); | ||
| 192 | + lspWrapper.setRemainingLifetime(IsisConstants.LSPMAXAGE - lsdbAge.ageCounter()); | ||
| 193 | + lspWrapper.setLspType(IsisPduType.get(lspdu.pduType())); | ||
| 194 | + lspWrapper.setLsPdu(lspdu); | ||
| 195 | + lspWrapper.setAgeCounterWhenReceived(lsdbAge.ageCounter()); | ||
| 196 | + lspWrapper.setAgeCounterRollOverWhenAdded(lsdbAge.ageCounterRollOver()); | ||
| 197 | + lspWrapper.setSelfOriginated(isSelfOriginated); | ||
| 198 | + lspWrapper.setIsisInterface(isisInterface); | ||
| 199 | + lspWrapper.setLsdbAge(lsdbAge); | ||
| 200 | + addLsp(lspWrapper, lspdu.lspId()); | ||
| 201 | + | ||
| 202 | + log.debug("Added LSp In LSDB: {}", lspWrapper); | ||
| 203 | + | ||
| 204 | + return true; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * Adds the LSP to L1 or L2 database. | ||
| 209 | + * | ||
| 210 | + * @param lspWrapper LSA wrapper instance | ||
| 211 | + * @param key key | ||
| 212 | + * @return True if added else false | ||
| 213 | + */ | ||
| 214 | + private boolean addLsp(LspWrapper lspWrapper, String key) { | ||
| 215 | + //Remove the lsa from bin if exist. | ||
| 216 | + removeLspFromBin(lspWrapper); | ||
| 217 | + | ||
| 218 | + switch (lspWrapper.lsPdu().isisPduType()) { | ||
| 219 | + case L1LSPDU: | ||
| 220 | + isisL1Db.put(key, lspWrapper); | ||
| 221 | + break; | ||
| 222 | + case L2LSPDU: | ||
| 223 | + isisL2Db.put(key, lspWrapper); | ||
| 224 | + break; | ||
| 225 | + default: | ||
| 226 | + log.debug("Unknown LSP type to add..!!!"); | ||
| 227 | + break; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + //add it to bin | ||
| 231 | + Integer binNumber = lsdbAge.age2Bin(IsisConstants.LSPMAXAGE - lspWrapper.remainingLifetime()); | ||
| 232 | + IsisLspBin lspBin = lsdbAge.getLspBin(binNumber); | ||
| 233 | + if (lspBin != null) { | ||
| 234 | + //remove from existing | ||
| 235 | + lspWrapper.setBinNumber(binNumber); | ||
| 236 | + lspBin.addIsisLsp(key, lspWrapper); | ||
| 237 | + lsdbAge.addLspBin(binNumber, lspBin); | ||
| 238 | + log.debug("Added Type {} LSP to LSDB and LSABin[{}], Remaining life time of LSA {}", | ||
| 239 | + lspWrapper.lsPdu().isisPduType(), | ||
| 240 | + binNumber, lspWrapper.remainingLifetime()); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + return false; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /** | ||
| 247 | + * Removes LSP from Bin. | ||
| 248 | + * | ||
| 249 | + * @param lsaWrapper LSP wrapper instance | ||
| 250 | + */ | ||
| 251 | + public void removeLspFromBin(LspWrapper lsaWrapper) { | ||
| 252 | + if (lsaWrapper != null) { | ||
| 253 | + lsdbAge.removeLspFromBin(lsaWrapper); | ||
| 254 | + } | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + /** | ||
| 258 | + * Returns new ,latest or old according to the type of ISIS message received. | ||
| 259 | + * | ||
| 260 | + * @param lsp1 LSP instance | ||
| 261 | + * @param lsp2 LSP instance | ||
| 262 | + * @return string status | ||
| 263 | + */ | ||
| 264 | + public String isNewerOrSameLsp(IsisMessage lsp1, IsisMessage lsp2) { | ||
| 265 | + LsPdu receivedLsp = (LsPdu) lsp1; | ||
| 266 | + LsPdu lspFromDb = (LsPdu) lsp2; | ||
| 267 | + if (receivedLsp.sequenceNumber() > lspFromDb.sequenceNumber()) { | ||
| 268 | + return "latest"; | ||
| 269 | + } else if (receivedLsp.sequenceNumber() < lspFromDb.sequenceNumber()) { | ||
| 270 | + return "old"; | ||
| 271 | + } else if (receivedLsp.sequenceNumber() == lspFromDb.sequenceNumber()) { | ||
| 272 | + return "same"; | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + return ""; | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + /** | ||
| 279 | + * Returns the sequence number. | ||
| 280 | + * | ||
| 281 | + * @param lspType type of LSP | ||
| 282 | + * @return sequence number | ||
| 283 | + */ | ||
| 284 | + public int lsSequenceNumber(IsisPduType lspType) { | ||
| 285 | + switch (lspType) { | ||
| 286 | + case L1LSPDU: | ||
| 287 | + return l1LspSeqNo++; | ||
| 288 | + case L2LSPDU: | ||
| 289 | + return l2LspSeqNo++; | ||
| 290 | + default: | ||
| 291 | + return IsisConstants.STARTLSSEQUENCENUM; | ||
| 292 | + } | ||
| 293 | + } | ||
| 294 | + | ||
| 295 | + /** | ||
| 296 | + * Deletes the given LSP. | ||
| 297 | + * | ||
| 298 | + * @param lspMessage LSP instance | ||
| 299 | + */ | ||
| 300 | + public void deleteLsp(IsisMessage lspMessage) { | ||
| 301 | + LsPdu lsp = (LsPdu) lspMessage; | ||
| 302 | + String lspKey = lsp.lspId(); | ||
| 303 | + switch (lsp.isisPduType()) { | ||
| 304 | + case L1LSPDU: | ||
| 305 | + isisL1Db.remove(lspKey); | ||
| 306 | + break; | ||
| 307 | + case L2LSPDU: | ||
| 308 | + isisL2Db.remove(lspKey); | ||
| 309 | + break; | ||
| 310 | + default: | ||
| 311 | + log.debug("Unknown LSP type to remove..!!!"); | ||
| 312 | + break; | ||
| 313 | + } | ||
| 314 | + } | ||
| 315 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/lsdb/DefaultIsisLsdbAge.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl.lsdb; | ||
| 17 | + | ||
| 18 | +import org.onosproject.isis.controller.IsisLsdbAge; | ||
| 19 | +import org.onosproject.isis.controller.IsisLspBin; | ||
| 20 | +import org.onosproject.isis.controller.LspWrapper; | ||
| 21 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
| 22 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 23 | +import org.slf4j.Logger; | ||
| 24 | +import org.slf4j.LoggerFactory; | ||
| 25 | + | ||
| 26 | +import java.util.Map; | ||
| 27 | +import java.util.concurrent.ArrayBlockingQueue; | ||
| 28 | +import java.util.concurrent.BlockingQueue; | ||
| 29 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 30 | +import java.util.concurrent.Executors; | ||
| 31 | +import java.util.concurrent.ScheduledExecutorService; | ||
| 32 | +import java.util.concurrent.TimeUnit; | ||
| 33 | + | ||
| 34 | +/** | ||
| 35 | + * Representation of ISIS link state database ageing process. | ||
| 36 | + */ | ||
| 37 | +public class DefaultIsisLsdbAge implements IsisLsdbAge { | ||
| 38 | + private static final Logger log = LoggerFactory.getLogger(DefaultIsisLsdbAge.class); | ||
| 39 | + protected static int ageCounter = 0; | ||
| 40 | + private InternalAgeTimer dbAgeTimer; | ||
| 41 | + private ScheduledExecutorService exServiceage; | ||
| 42 | + private Integer maxBins = 1200; | ||
| 43 | + private Map<Integer, IsisLspBin> ageBins = new ConcurrentHashMap<>(maxBins); | ||
| 44 | + private int ageCounterRollOver = 0; | ||
| 45 | + private IsisLspQueueConsumer queueConsumer = null; | ||
| 46 | + private BlockingQueue<LspWrapper> lsaQueue = new ArrayBlockingQueue<>(1024); | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Creates an instance of LSDB age. | ||
| 50 | + */ | ||
| 51 | + public DefaultIsisLsdbAge() { | ||
| 52 | + // create LSBin's in the HashMap. | ||
| 53 | + for (int i = 0; i < maxBins; i++) { | ||
| 54 | + IsisLspBin lspBin = new DefaultIsisLspBin(i); | ||
| 55 | + ageBins.put(i, lspBin); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Returns age counter. | ||
| 61 | + * | ||
| 62 | + * @return age counter | ||
| 63 | + */ | ||
| 64 | + public int ageCounter() { | ||
| 65 | + return ageCounter; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Returns age counter roll over. | ||
| 70 | + * | ||
| 71 | + * @return age counter roll over | ||
| 72 | + */ | ||
| 73 | + public int ageCounterRollOver() { | ||
| 74 | + | ||
| 75 | + return ageCounterRollOver; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Adds LSP to LS bin for ageing. | ||
| 80 | + * | ||
| 81 | + * @param binNumber key to store in bin | ||
| 82 | + * @param lspBin LSP bin instance | ||
| 83 | + */ | ||
| 84 | + public void addLspBin(int binNumber, IsisLspBin lspBin) { | ||
| 85 | + if (!ageBins.containsKey(binNumber)) { | ||
| 86 | + ageBins.put(binNumber, lspBin); | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * Returns LSP from Bin. | ||
| 92 | + * | ||
| 93 | + * @param binKey key | ||
| 94 | + * @return bin instance | ||
| 95 | + */ | ||
| 96 | + public IsisLspBin getLspBin(int binKey) { | ||
| 97 | + | ||
| 98 | + return ageBins.get(binKey); | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * Removes LSP from Bin. | ||
| 103 | + * | ||
| 104 | + * @param lspWrapper wrapper instance | ||
| 105 | + */ | ||
| 106 | + public void removeLspFromBin(LspWrapper lspWrapper) { | ||
| 107 | + if (ageBins.containsKey(lspWrapper.binNumber())) { | ||
| 108 | + IsisLspBin lsaBin = ageBins.get(lspWrapper.binNumber()); | ||
| 109 | + lsaBin.removeIsisLsp(((LsPdu) lspWrapper.lsPdu()).lspId(), lspWrapper); | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * Returns the bin number. | ||
| 115 | + * | ||
| 116 | + * @param age Can be either age or ageCounter | ||
| 117 | + * @return bin number. | ||
| 118 | + */ | ||
| 119 | + public int age2Bin(int age) { | ||
| 120 | + if (age <= ageCounter) { | ||
| 121 | + return (ageCounter - age); | ||
| 122 | + } else { | ||
| 123 | + return ((IsisConstants.LSPMAXAGE - 1) + (ageCounter - age)); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Starts the aging timer and queue consumer. | ||
| 129 | + */ | ||
| 130 | + public void startDbAging() { | ||
| 131 | + startDbAgeTimer(); | ||
| 132 | + queueConsumer = new IsisLspQueueConsumer(lsaQueue); | ||
| 133 | + new Thread(queueConsumer).start(); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + /** | ||
| 137 | + * Starts DB aging task. | ||
| 138 | + */ | ||
| 139 | + private void startDbAgeTimer() { | ||
| 140 | + dbAgeTimer = new InternalAgeTimer(); | ||
| 141 | + //from 1 sec | ||
| 142 | + exServiceage = Executors.newSingleThreadScheduledExecutor(); | ||
| 143 | + exServiceage.scheduleAtFixedRate(dbAgeTimer, 1, 1, TimeUnit.SECONDS); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + /** | ||
| 147 | + * Gets called every second as part of the aging process. | ||
| 148 | + */ | ||
| 149 | + public void ageLsp() { | ||
| 150 | + refreshLsa(); | ||
| 151 | + maxAgeLsa(); | ||
| 152 | + | ||
| 153 | + if (ageCounter == IsisConstants.LSPMAXAGE) { | ||
| 154 | + ageCounter = 0; | ||
| 155 | + ageCounterRollOver++; | ||
| 156 | + } else { | ||
| 157 | + ageCounter++; | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + /** | ||
| 162 | + * If the LSP have completed the MaxAge - they are moved called stop aging. | ||
| 163 | + */ | ||
| 164 | + public void maxAgeLsa() { | ||
| 165 | + if (ageCounter == 0) { | ||
| 166 | + return; | ||
| 167 | + } | ||
| 168 | + //Get from Age Bins | ||
| 169 | + IsisLspBin lspBin = ageBins.get(ageCounter - 1); | ||
| 170 | + if (lspBin == null) { | ||
| 171 | + return; | ||
| 172 | + } | ||
| 173 | + Map lspBinMap = lspBin.listOfLsp(); | ||
| 174 | + for (Object key : lspBinMap.keySet()) { | ||
| 175 | + LspWrapper lspWrapper = (LspWrapper) lspBinMap.get((String) key); | ||
| 176 | + if (lspWrapper.currentAge() == IsisConstants.LSPMAXAGE) { | ||
| 177 | + lspWrapper.setLspProcessing(IsisConstants.MAXAGELSP); | ||
| 178 | + log.debug("Lsp picked for maxage removal. Age Counter: {}, AgeCounterRollover: {}, " + | ||
| 179 | + "AgeCounterRollover WhenAddedToDb: {}, LSA Type: {}, LSA Key: {}", | ||
| 180 | + ageCounter, ageCounterRollOver, lspWrapper.currentAge(), | ||
| 181 | + lspWrapper.lsPdu().isisPduType(), key); | ||
| 182 | + //add it to lspQueue for processing | ||
| 183 | + try { | ||
| 184 | + lsaQueue.put(lspWrapper); | ||
| 185 | + //remove from bin | ||
| 186 | + lspBin.removeIsisLsp((String) key, lspWrapper); | ||
| 187 | + } catch (InterruptedException e) { | ||
| 188 | + log.debug("Error::LSDBAge::maxAgeLsp::{}", e.getMessage()); | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + /* | ||
| 196 | + * If the LSP is in age bin of 900s- it's pushed into refresh list. | ||
| 197 | + */ | ||
| 198 | + public void refreshLsa() { | ||
| 199 | + int binNumber; | ||
| 200 | + if (ageCounter < IsisConstants.LSPREFRESH) { | ||
| 201 | + binNumber = ageCounter + IsisConstants.LSPREFRESH; | ||
| 202 | + } else { | ||
| 203 | + binNumber = ageCounter - IsisConstants.LSPREFRESH; | ||
| 204 | + } | ||
| 205 | + if (binNumber > IsisConstants.LSPMAXAGE) { | ||
| 206 | + binNumber = binNumber - IsisConstants.LSPMAXAGE; | ||
| 207 | + } | ||
| 208 | + IsisLspBin lspBin = ageBins.get(binNumber); | ||
| 209 | + if (lspBin == null) { | ||
| 210 | + return; | ||
| 211 | + } | ||
| 212 | + Map lspBinMap = lspBin.listOfLsp(); | ||
| 213 | + for (Object key : lspBinMap.keySet()) { | ||
| 214 | + LspWrapper lsp = (LspWrapper) lspBinMap.get((String) key); | ||
| 215 | + try { | ||
| 216 | + if (lsp.isSelfOriginated()) { | ||
| 217 | + log.debug("Lsp picked for refreshLsp. binNumber: {}, LSA Type: {}, LSA Key: {}", | ||
| 218 | + binNumber, lsp.lspType(), key); | ||
| 219 | + lsp.setLspProcessing(IsisConstants.REFRESHLSP); | ||
| 220 | + lsaQueue.put(lsp); | ||
| 221 | + //remove from bin | ||
| 222 | + lspBin.removeIsisLsp((String) key, lsp); | ||
| 223 | + } | ||
| 224 | + } catch (InterruptedException e) { | ||
| 225 | + log.debug("Error::LSDBAge::refreshLsp::{}", e.getMessage()); | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + | ||
| 231 | + /** | ||
| 232 | + * Runnable task which runs every second and calls aging process. | ||
| 233 | + */ | ||
| 234 | + private class InternalAgeTimer implements Runnable { | ||
| 235 | + | ||
| 236 | + /** | ||
| 237 | + * Creates an instance of age timer task. | ||
| 238 | + */ | ||
| 239 | + InternalAgeTimer() { | ||
| 240 | + log.debug("Starts::IsisLsdbAge::AgeTimer...!!! "); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + @Override | ||
| 244 | + public void run() { | ||
| 245 | + ageLsp(); | ||
| 246 | + } | ||
| 247 | + } | ||
| 248 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/lsdb/DefaultIsisLspBin.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl.lsdb; | ||
| 17 | + | ||
| 18 | +import com.google.common.base.MoreObjects; | ||
| 19 | +import org.onosproject.isis.controller.IsisLspBin; | ||
| 20 | +import org.onosproject.isis.controller.LspWrapper; | ||
| 21 | + | ||
| 22 | +import java.util.Map; | ||
| 23 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Representation of LSP bin, where an LSP is stored for Aging. | ||
| 27 | + * A bin is identified by a bin number and can have one or more LSPs | ||
| 28 | + * store in a particular bin location | ||
| 29 | + */ | ||
| 30 | +public class DefaultIsisLspBin implements IsisLspBin { | ||
| 31 | + private int binNumber; | ||
| 32 | + private Map<String, LspWrapper> listOfLsp = new ConcurrentHashMap<>(); | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * Creates ISIS LSP bin instance. | ||
| 36 | + * | ||
| 37 | + * @param binNumber bin number | ||
| 38 | + */ | ||
| 39 | + public DefaultIsisLspBin(int binNumber) { | ||
| 40 | + this.binNumber = binNumber; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * Adds the LSP to wrapper. | ||
| 45 | + * | ||
| 46 | + * @param lspKey key to add the LSP | ||
| 47 | + * @param lspWrapper LSP wrapper instance | ||
| 48 | + */ | ||
| 49 | + public void addIsisLsp(String lspKey, LspWrapper lspWrapper) { | ||
| 50 | + if (!listOfLsp.containsKey(lspKey)) { | ||
| 51 | + listOfLsp.put(lspKey, lspWrapper); | ||
| 52 | + lspWrapper.setBinNumber(this.binNumber); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * Returns the LSP wrapper. | ||
| 58 | + * | ||
| 59 | + * @param lspKey LSP key | ||
| 60 | + * @return LSP wrapper | ||
| 61 | + */ | ||
| 62 | + public LspWrapper isisLsp(String lspKey) { | ||
| 63 | + return listOfLsp.get(lspKey); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Removes ISIS LSP from database. | ||
| 68 | + * | ||
| 69 | + * @param lspKey LSP key | ||
| 70 | + * @param lspWrapper LSP wrapper instance | ||
| 71 | + */ | ||
| 72 | + public void removeIsisLsp(String lspKey, LspWrapper lspWrapper) { | ||
| 73 | + if (listOfLsp.containsKey(lspKey)) { | ||
| 74 | + listOfLsp.remove(lspKey); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Returns all LSP wrappers. | ||
| 80 | + * | ||
| 81 | + * @return all LSP wrappers | ||
| 82 | + */ | ||
| 83 | + public Map<String, LspWrapper> listOfLsp() { | ||
| 84 | + return listOfLsp; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Returns the bin number. | ||
| 89 | + * | ||
| 90 | + * @return the bin number | ||
| 91 | + */ | ||
| 92 | + public int binNumber() { | ||
| 93 | + return binNumber; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public String toString() { | ||
| 98 | + return MoreObjects.toStringHelper(getClass()) | ||
| 99 | + .omitNullValues() | ||
| 100 | + .add("binNumber", binNumber) | ||
| 101 | + .add("listOfLsp", listOfLsp) | ||
| 102 | + .toString(); | ||
| 103 | + } | ||
| 104 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/lsdb/DefaultLspWrapper.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl.lsdb; | ||
| 17 | + | ||
| 18 | +import org.onosproject.isis.controller.IsisInterface; | ||
| 19 | +import org.onosproject.isis.controller.IsisLsdbAge; | ||
| 20 | +import org.onosproject.isis.controller.IsisPduType; | ||
| 21 | +import org.onosproject.isis.controller.LspWrapper; | ||
| 22 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
| 23 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Representation of LSP wrapper where the LSPs are stored with metadata. | ||
| 27 | + */ | ||
| 28 | +public class DefaultLspWrapper implements LspWrapper { | ||
| 29 | + private int binNumber = -1; | ||
| 30 | + private boolean selfOriginated = false; | ||
| 31 | + private IsisPduType lspType; | ||
| 32 | + private int lspAgeReceived; | ||
| 33 | + private int ageCounterWhenReceived; | ||
| 34 | + private LsPdu lsPdu; | ||
| 35 | + private IsisLsdbAge lsdbAge; | ||
| 36 | + private int ageCounterRollOverWhenAdded; | ||
| 37 | + private int remainingLifetime; | ||
| 38 | + private IsisInterface isisInterface; | ||
| 39 | + private String lspProcessing; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Returns "refreshLsp" or "maxageLsp" based on LSP to process. | ||
| 43 | + * | ||
| 44 | + * @return LSP processing string | ||
| 45 | + */ | ||
| 46 | + public String lspProcessing() { | ||
| 47 | + return lspProcessing; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * Sets LSP processing "refreshLsp" or "maxageLsp" based on LSP to process. | ||
| 52 | + * | ||
| 53 | + * @param lspProcessing "refreshLsp" or "maxageLsp" based on LSP to process | ||
| 54 | + */ | ||
| 55 | + public void setLspProcessing(String lspProcessing) { | ||
| 56 | + this.lspProcessing = lspProcessing; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * Returns LSP age received. | ||
| 61 | + * | ||
| 62 | + * @return LSP age received | ||
| 63 | + */ | ||
| 64 | + public int lspAgeReceived() { | ||
| 65 | + return lspAgeReceived; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * Sets LSP age received. | ||
| 70 | + * | ||
| 71 | + * @param lspAgeReceived LSP age received. | ||
| 72 | + */ | ||
| 73 | + public void setLspAgeReceived(int lspAgeReceived) { | ||
| 74 | + this.lspAgeReceived = lspAgeReceived; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Returns ISIS interface instance. | ||
| 79 | + * | ||
| 80 | + * @return ISIS interface instance | ||
| 81 | + */ | ||
| 82 | + public IsisInterface isisInterface() { | ||
| 83 | + return isisInterface; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Sets ISIS interface. | ||
| 88 | + * | ||
| 89 | + * @param isisInterface ISIS interface instance | ||
| 90 | + */ | ||
| 91 | + public void setIsisInterface(IsisInterface isisInterface) { | ||
| 92 | + this.isisInterface = isisInterface; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * Returns age counter when received. | ||
| 97 | + * | ||
| 98 | + * @return age counter when received | ||
| 99 | + */ | ||
| 100 | + public int ageCounterWhenReceived() { | ||
| 101 | + | ||
| 102 | + return ageCounterWhenReceived; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * Sets age counter when received. | ||
| 107 | + * | ||
| 108 | + * @param ageCounterWhenReceived age counter when received | ||
| 109 | + */ | ||
| 110 | + public void setAgeCounterWhenReceived(int ageCounterWhenReceived) { | ||
| 111 | + this.ageCounterWhenReceived = ageCounterWhenReceived; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Returns age counter roll over. | ||
| 116 | + * | ||
| 117 | + * @return age counter roll over | ||
| 118 | + */ | ||
| 119 | + public int ageCounterRollOverWhenAdded() { | ||
| 120 | + return ageCounterRollOverWhenAdded; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Sets age counter roll over when added. | ||
| 125 | + * | ||
| 126 | + * @param ageCounterRollOverWhenAdded age counter roll over when added | ||
| 127 | + */ | ||
| 128 | + public void setAgeCounterRollOverWhenAdded(int ageCounterRollOverWhenAdded) { | ||
| 129 | + this.ageCounterRollOverWhenAdded = ageCounterRollOverWhenAdded; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * Returns bin number. | ||
| 134 | + * | ||
| 135 | + * @return bin number | ||
| 136 | + */ | ||
| 137 | + public int binNumber() { | ||
| 138 | + return binNumber; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + /** | ||
| 142 | + * Sets bin number. | ||
| 143 | + * | ||
| 144 | + * @param binNumber bin number | ||
| 145 | + */ | ||
| 146 | + public void setBinNumber(int binNumber) { | ||
| 147 | + this.binNumber = binNumber; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * Returns true if self originated. | ||
| 152 | + * | ||
| 153 | + * @return true if self originated. | ||
| 154 | + */ | ||
| 155 | + public boolean isSelfOriginated() { | ||
| 156 | + return selfOriginated; | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + /** | ||
| 160 | + * Sets true if self originated. | ||
| 161 | + * | ||
| 162 | + * @param selfOriginated true if self originated else false | ||
| 163 | + */ | ||
| 164 | + public void setSelfOriginated(boolean selfOriginated) { | ||
| 165 | + this.selfOriginated = selfOriginated; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + /** | ||
| 169 | + * Returns ISIS PDU type. | ||
| 170 | + * | ||
| 171 | + * @return ISIS PDU type | ||
| 172 | + */ | ||
| 173 | + public IsisPduType lspType() { | ||
| 174 | + return lspType; | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + /** | ||
| 178 | + * Sets ISIS PDU type. | ||
| 179 | + * | ||
| 180 | + * @param lspType ISIS PDU type | ||
| 181 | + */ | ||
| 182 | + public void setLspType(IsisPduType lspType) { | ||
| 183 | + this.lspType = lspType; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + /** | ||
| 187 | + * Returns LSPDU which the wrapper contains. | ||
| 188 | + * | ||
| 189 | + * @return LSPDU which the wrapper contains | ||
| 190 | + */ | ||
| 191 | + public LsPdu lsPdu() { | ||
| 192 | + return lsPdu; | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + /** | ||
| 196 | + * Sets LSPDU which the wrapper contains. | ||
| 197 | + * | ||
| 198 | + * @param lsPdu LSPDU which the wrapper contains | ||
| 199 | + */ | ||
| 200 | + public void setLsPdu(LsPdu lsPdu) { | ||
| 201 | + this.lsPdu = lsPdu; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + /** | ||
| 205 | + * Returns ISIS LSDB age. | ||
| 206 | + * | ||
| 207 | + * @return ISIS LSDB age | ||
| 208 | + */ | ||
| 209 | + public IsisLsdbAge lsdbAge() { | ||
| 210 | + return lsdbAge; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + /** | ||
| 214 | + * Sets LSDB age. | ||
| 215 | + * | ||
| 216 | + * @param lsdbAge LSDB age | ||
| 217 | + */ | ||
| 218 | + public void setLsdbAge(IsisLsdbAge lsdbAge) { | ||
| 219 | + this.lsdbAge = lsdbAge; | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + /** | ||
| 223 | + * Returns the current LSP Age. | ||
| 224 | + * | ||
| 225 | + * @return LSP age | ||
| 226 | + */ | ||
| 227 | + public int currentAge() { | ||
| 228 | + | ||
| 229 | + int currentAge = 0; | ||
| 230 | + //ls age received | ||
| 231 | + if (lsdbAge.ageCounter() >= ageCounterWhenReceived) { | ||
| 232 | + currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived); | ||
| 233 | + } else { | ||
| 234 | + currentAge = lspAgeReceived + ((IsisConstants.LSPMAXAGE + lsdbAge.ageCounter()) | ||
| 235 | + - ageCounterWhenReceived); | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + if (currentAge >= IsisConstants.LSPMAXAGE) { | ||
| 239 | + return IsisConstants.LSPMAXAGE; | ||
| 240 | + } else if ((currentAge == lspAgeReceived) && ageCounterRollOverWhenAdded | ||
| 241 | + != lsdbAge.ageCounterRollOver()) { | ||
| 242 | + return IsisConstants.LSPMAXAGE; | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + return currentAge; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + /** | ||
| 249 | + * Returns remaining time. | ||
| 250 | + * | ||
| 251 | + * @return remaining time | ||
| 252 | + */ | ||
| 253 | + public int remainingLifetime() { | ||
| 254 | + //Calculate the remaining lifetime | ||
| 255 | + remainingLifetime = IsisConstants.LSPMAXAGE - lsdbAge.ageCounter(); | ||
| 256 | + return remainingLifetime; | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + /** | ||
| 260 | + * Sets remaining life time. | ||
| 261 | + * | ||
| 262 | + * @param remainingLifetime LSPs remaining life time | ||
| 263 | + */ | ||
| 264 | + public void setRemainingLifetime(int remainingLifetime) { | ||
| 265 | + this.remainingLifetime = remainingLifetime; | ||
| 266 | + } | ||
| 267 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/lsdb/IsisLspQueueConsumer.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.controller.impl.lsdb; | ||
| 17 | + | ||
| 18 | +import org.jboss.netty.channel.Channel; | ||
| 19 | +import org.onosproject.isis.controller.IsisLsdb; | ||
| 20 | +import org.onosproject.isis.controller.IsisPduType; | ||
| 21 | +import org.onosproject.isis.controller.LspWrapper; | ||
| 22 | +import org.onosproject.isis.controller.impl.DefaultIsisInterface; | ||
| 23 | +import org.onosproject.isis.io.isispacket.pdu.LsPdu; | ||
| 24 | +import org.onosproject.isis.io.util.IsisConstants; | ||
| 25 | +import org.onosproject.isis.io.util.IsisUtil; | ||
| 26 | +import org.slf4j.Logger; | ||
| 27 | +import org.slf4j.LoggerFactory; | ||
| 28 | + | ||
| 29 | +import java.util.concurrent.BlockingQueue; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Representation of LSP queue consumer. | ||
| 33 | + */ | ||
| 34 | +public class IsisLspQueueConsumer implements Runnable { | ||
| 35 | + private static final Logger log = LoggerFactory.getLogger(IsisLspQueueConsumer.class); | ||
| 36 | + private BlockingQueue queue = null; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Creates an instance of LSP queue consumer. | ||
| 40 | + * | ||
| 41 | + * @param queue queue instance | ||
| 42 | + */ | ||
| 43 | + public IsisLspQueueConsumer(BlockingQueue queue) { | ||
| 44 | + this.queue = queue; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Gets the LSP wrapper instance from queue and process it. | ||
| 49 | + */ | ||
| 50 | + @Override | ||
| 51 | + public void run() { | ||
| 52 | + log.debug("LSPQueueConsumer:run...!!!"); | ||
| 53 | + try { | ||
| 54 | + while (true) { | ||
| 55 | + if (!queue.isEmpty()) { | ||
| 56 | + LspWrapper wrapper = (LspWrapper) queue.take(); | ||
| 57 | + String lspProcessing = wrapper.lspProcessing(); | ||
| 58 | + switch (lspProcessing) { | ||
| 59 | + case IsisConstants.REFRESHLSP: | ||
| 60 | + log.debug("LSPQueueConsumer: Message - " + IsisConstants.REFRESHLSP + | ||
| 61 | + " consumed."); | ||
| 62 | + processRefreshLsp(wrapper); | ||
| 63 | + break; | ||
| 64 | + case IsisConstants.MAXAGELSP: | ||
| 65 | + log.debug("LSPQueueConsumer: Message - " + IsisConstants.MAXAGELSP + | ||
| 66 | + " consumed."); | ||
| 67 | + processMaxAgeLsa(wrapper); | ||
| 68 | + break; | ||
| 69 | + default: | ||
| 70 | + log.debug("Unknown command to process the LSP in queue ...!!!"); | ||
| 71 | + break; | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + } catch (Exception e) { | ||
| 77 | + log.debug("Error::LSPQueueConsumer::{}", e.getMessage()); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * Process refresh LSP. | ||
| 83 | + * | ||
| 84 | + * @param wrapper LSP wrapper instance | ||
| 85 | + */ | ||
| 86 | + private void processRefreshLsp(LspWrapper wrapper) throws Exception { | ||
| 87 | + if (wrapper.isSelfOriginated()) { //self originated | ||
| 88 | + DefaultIsisInterface isisInterface = (DefaultIsisInterface) wrapper.isisInterface(); | ||
| 89 | + Channel channel = isisInterface.channel(); | ||
| 90 | + if (channel != null && channel.isConnected()) { | ||
| 91 | + LsPdu lsPdu = (LsPdu) wrapper.lsPdu(); | ||
| 92 | + lsPdu.setSequenceNumber(isisInterface.isisLsdb().lsSequenceNumber( | ||
| 93 | + IsisPduType.get(lsPdu.pduType()))); | ||
| 94 | + lsPdu.setRemainingLifeTime(IsisConstants.LSPMAXAGE); | ||
| 95 | + byte[] lspBytes = lsPdu.asBytes(); | ||
| 96 | + lspBytes = IsisUtil.addLengthAndMarkItInReserved(lspBytes, IsisConstants.LENGTHPOSITION, | ||
| 97 | + IsisConstants.LENGTHPOSITION + 1, | ||
| 98 | + IsisConstants.RESERVEDPOSITION); | ||
| 99 | + lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION, | ||
| 100 | + IsisConstants.CHECKSUMPOSITION + 1); | ||
| 101 | + //write to the channel | ||
| 102 | + channel.write(IsisUtil.framePacket(lspBytes, isisInterface.interfaceIndex())); | ||
| 103 | + | ||
| 104 | + log.debug("LSPQueueConsumer: processRefreshLsp - Flooded SelfOriginated LSP {}", | ||
| 105 | + wrapper.lsPdu()); | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + /** | ||
| 112 | + * Process max age LSP. | ||
| 113 | + * | ||
| 114 | + * @param wrapper LSP wrapper instance | ||
| 115 | + */ | ||
| 116 | + private void processMaxAgeLsa(LspWrapper wrapper) { | ||
| 117 | + //set the destination | ||
| 118 | + DefaultIsisInterface isisInterface = (DefaultIsisInterface) wrapper.isisInterface(); | ||
| 119 | + if (isisInterface != null) { | ||
| 120 | + //delete from db | ||
| 121 | + LsPdu lsPdu = (LsPdu) wrapper.lsPdu(); | ||
| 122 | + IsisLsdb isisDb = isisInterface.isisLsdb(); | ||
| 123 | + isisDb.deleteLsp(lsPdu); | ||
| 124 | + log.debug("LSPQueueConsumer: processMaxAgeLsp - Removed-Max Age LSP {}", | ||
| 125 | + wrapper.lsPdu()); | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -13,32 +13,8 @@ | ... | @@ -13,32 +13,8 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.isis.io.util; | ||
| 17 | - | ||
| 18 | -import com.fasterxml.jackson.databind.JsonNode; | ||
| 19 | 16 | ||
| 20 | /** | 17 | /** |
| 21 | - * Representation of ISIS config. | 18 | + * Implementation of the ISIS controller LSDB and related functionality. |
| 22 | */ | 19 | */ |
| 23 | -public enum IsisConfig { | ||
| 24 | - INSTANCE; | ||
| 25 | - private JsonNode jsonNodes = null; | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * Returns the config value. | ||
| 29 | - * | ||
| 30 | - * @return jsonNodes json node | ||
| 31 | - */ | ||
| 32 | - public JsonNode config() { | ||
| 33 | - return jsonNodes; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - /** | ||
| 37 | - * Sets the config value for jsonNode. | ||
| 38 | - * | ||
| 39 | - * @param jsonNodes json node | ||
| 40 | - */ | ||
| 41 | - public void setConfig(JsonNode jsonNodes) { | ||
| 42 | - this.jsonNodes = jsonNodes; | ||
| 43 | - } | ||
| 44 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 20 | +package org.onosproject.isis.controller.impl.lsdb; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Implementation of the ISIS controller. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.isis.controller.impl; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -280,7 +280,7 @@ public class LsPdu extends IsisHeader { | ... | @@ -280,7 +280,7 @@ public class LsPdu extends IsisHeader { |
| 280 | * Returns the packet data unit length of link state packet. | 280 | * Returns the packet data unit length of link state packet. |
| 281 | * Entire length of this PDU, in octets | 281 | * Entire length of this PDU, in octets |
| 282 | * | 282 | * |
| 283 | - * @return pduLength packte date unit length | 283 | + * @return pduLength packet data unit length |
| 284 | */ | 284 | */ |
| 285 | public int pduLength() { | 285 | public int pduLength() { |
| 286 | return pduLength; | 286 | return pduLength; |
| ... | @@ -290,7 +290,7 @@ public class LsPdu extends IsisHeader { | ... | @@ -290,7 +290,7 @@ public class LsPdu extends IsisHeader { |
| 290 | * Sets the packet data unit length for link state packet. | 290 | * Sets the packet data unit length for link state packet. |
| 291 | * Entire Length of this PDU, in octets | 291 | * Entire Length of this PDU, in octets |
| 292 | * | 292 | * |
| 293 | - * @param pduLength packte data length | 293 | + * @param pduLength packet data length |
| 294 | */ | 294 | */ |
| 295 | public void setPduLength(int pduLength) { | 295 | public void setPduLength(int pduLength) { |
| 296 | this.pduLength = pduLength; | 296 | this.pduLength = pduLength; | ... | ... |
| ... | @@ -220,10 +220,9 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -220,10 +220,9 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
| 220 | byte[] bytes = null; | 220 | byte[] bytes = null; |
| 221 | byte[] tlvHeader = tlvHeaderAsByteArray(); | 221 | byte[] tlvHeader = tlvHeaderAsByteArray(); |
| 222 | byte[] tlvBody = tlvBodyAsBytes(); | 222 | byte[] tlvBody = tlvBodyAsBytes(); |
| 223 | - //systemID + pseudo number+length of subtlv=11l | ||
| 224 | - tlvBody[10] = (byte) (tlvBody.length - 11); | ||
| 225 | tlvHeader[1] = (byte) tlvBody.length; | 223 | tlvHeader[1] = (byte) tlvBody.length; |
| 226 | bytes = Bytes.concat(tlvHeader, tlvBody); | 224 | bytes = Bytes.concat(tlvHeader, tlvBody); |
| 225 | + | ||
| 227 | return bytes; | 226 | return bytes; |
| 228 | } | 227 | } |
| 229 | 228 | ||
| ... | @@ -246,8 +245,8 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -246,8 +245,8 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
| 246 | } else { | 245 | } else { |
| 247 | controlInfo = controlInfo + "0"; | 246 | controlInfo = controlInfo + "0"; |
| 248 | } | 247 | } |
| 249 | - String prefixlength = IsisUtil.toEightBitBinary(Integer.toBinaryString(this.prefixLength())); | 248 | + String prefixLength = IsisUtil.toEightBitBinary(Integer.toBinaryString(this.prefixLength())); |
| 250 | - controlInfo = controlInfo + prefixlength.substring(2, prefixlength.length()); | 249 | + controlInfo = controlInfo + prefixLength.substring(2, prefixLength.length()); |
| 251 | bodyLst.add(Byte.parseByte(controlInfo, 2)); | 250 | bodyLst.add(Byte.parseByte(controlInfo, 2)); |
| 252 | if (this.isSubTlvPresence()) { | 251 | if (this.isSubTlvPresence()) { |
| 253 | bodyLst.add(this.subTlvLength()); | 252 | bodyLst.add(this.subTlvLength()); |
| ... | @@ -255,6 +254,8 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { | ... | @@ -255,6 +254,8 @@ public class IpExtendedReachabilityTlv extends TlvHeader implements IsisTlv { |
| 255 | bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv)); | 254 | bodyLst.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv)); |
| 256 | } | 255 | } |
| 257 | } | 256 | } |
| 257 | + bodyLst.addAll(Bytes.asList(IsisUtil.prefixToBytes(this.prefix()))); | ||
| 258 | + | ||
| 258 | return Bytes.toArray(bodyLst); | 259 | return Bytes.toArray(bodyLst); |
| 259 | } | 260 | } |
| 260 | 261 | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.isis.io.isispacket.tlv; | ||
| 17 | + | ||
| 18 | +import com.google.common.base.MoreObjects; | ||
| 19 | +import com.google.common.primitives.Bytes; | ||
| 20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 21 | +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvFinder; | ||
| 22 | +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes; | ||
| 23 | +import org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvType; | ||
| 24 | +import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv; | ||
| 25 | +import org.onosproject.isis.io.util.IsisUtil; | ||
| 26 | + | ||
| 27 | +import java.util.ArrayList; | ||
| 28 | +import java.util.List; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Representation of IS extended reachability TLV. | ||
| 32 | + */ | ||
| 33 | +public class IsExtendedReachability extends TlvHeader implements IsisTlv { | ||
| 34 | + | ||
| 35 | + private String neighborId; | ||
| 36 | + private int metric; | ||
| 37 | + private List<TrafficEngineeringSubTlv> trafEnginSubTlv = new ArrayList<>(); | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * Creates an instance of IP external reachability TLV. | ||
| 41 | + * | ||
| 42 | + * @param tlvHeader TLV header | ||
| 43 | + */ | ||
| 44 | + public IsExtendedReachability(TlvHeader tlvHeader) { | ||
| 45 | + this.setTlvType(tlvHeader.tlvType()); | ||
| 46 | + this.setTlvLength(tlvHeader.tlvLength()); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Returns neighbor ID. | ||
| 51 | + * | ||
| 52 | + * @return neighbor ID | ||
| 53 | + */ | ||
| 54 | + public String neighborId() { | ||
| 55 | + return neighborId; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * Sets neighbor ID. | ||
| 60 | + * | ||
| 61 | + * @param neighborId neighbor ID | ||
| 62 | + */ | ||
| 63 | + public void setNeighborId(String neighborId) { | ||
| 64 | + this.neighborId = neighborId; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Returns metric. | ||
| 69 | + * | ||
| 70 | + * @return metric | ||
| 71 | + */ | ||
| 72 | + public int metric() { | ||
| 73 | + return metric; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Sets metric. | ||
| 78 | + * | ||
| 79 | + * @param metric metric | ||
| 80 | + */ | ||
| 81 | + public void setMetric(int metric) { | ||
| 82 | + this.metric = metric; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * Adds the traffic engineering sub TLV to IS extended reachability TLV. | ||
| 87 | + * | ||
| 88 | + * @param trafEnginSubTlv traffic engineering sub TLV | ||
| 89 | + */ | ||
| 90 | + public void addSubTlv(TrafficEngineeringSubTlv trafEnginSubTlv) { | ||
| 91 | + this.trafEnginSubTlv.add(trafEnginSubTlv); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public void readFrom(ChannelBuffer channelBuffer) { | ||
| 96 | + byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES]; | ||
| 97 | + channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES); | ||
| 98 | + this.setNeighborId(IsisUtil.systemId(tempByteArray)); | ||
| 99 | + this.setMetric(channelBuffer.readUnsignedMedium()); | ||
| 100 | + while (channelBuffer.readableBytes() > 0) { | ||
| 101 | + TlvHeader tlvHeader = new TlvHeader(); | ||
| 102 | + tlvHeader.setTlvType(channelBuffer.readByte()); | ||
| 103 | + tlvHeader.setTlvLength(channelBuffer.readByte()); | ||
| 104 | + SubTlvType tlvValue = SubTlvType.get(tlvHeader.tlvType()); | ||
| 105 | + if (tlvValue != null) { | ||
| 106 | + this.addSubTlv(SubTlvFinder.findSubTlv(tlvHeader, | ||
| 107 | + channelBuffer.readBytes(tlvHeader.tlvLength()))); | ||
| 108 | + } else { | ||
| 109 | + channelBuffer.readBytes(tlvHeader.tlvLength()); | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public byte[] asBytes() { | ||
| 116 | + byte[] bytes = null; | ||
| 117 | + byte[] tlvHeader = tlvHeaderAsByteArray(); | ||
| 118 | + byte[] tlvBody = tlvBodyAsBytes(); | ||
| 119 | + tlvHeader[1] = (byte) tlvBody.length; | ||
| 120 | + bytes = Bytes.concat(tlvHeader, tlvBody); | ||
| 121 | + return bytes; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /** | ||
| 125 | + * Returns TLV body of IS extended reachability TLV. | ||
| 126 | + * | ||
| 127 | + * @return byteArray TLV body of IS extended reachability TLV. | ||
| 128 | + */ | ||
| 129 | + private byte[] tlvBodyAsBytes() { | ||
| 130 | + List<Byte> byteList = new ArrayList<>(); | ||
| 131 | + byteList.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborId())); | ||
| 132 | + byteList.addAll(Bytes.asList(IsisUtil.convertToThreeBytes(this.metric()))); | ||
| 133 | + if (this.trafEnginSubTlv.size() > 0) { | ||
| 134 | + for (TrafficEngineeringSubTlv trafficEngineeringSubTlv : this.trafEnginSubTlv) { | ||
| 135 | + byteList.addAll(SubTlvToBytes.tlvToBytes(trafficEngineeringSubTlv)); | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + return Bytes.toArray(byteList); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + @Override | ||
| 142 | + public String toString() { | ||
| 143 | + return MoreObjects.toStringHelper(getClass()) | ||
| 144 | + .omitNullValues() | ||
| 145 | + .add("neighborId", neighborId) | ||
| 146 | + .add("metric", metric) | ||
| 147 | + .add("trafEnginSubTlv", trafEnginSubTlv) | ||
| 148 | + .toString(); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | +} |
| ... | @@ -358,10 +358,7 @@ public class MetricOfInternalReachability { | ... | @@ -358,10 +358,7 @@ public class MetricOfInternalReachability { |
| 358 | } else { | 358 | } else { |
| 359 | this.setErrorMetricSupported(false); | 359 | this.setErrorMetricSupported(false); |
| 360 | } | 360 | } |
| 361 | - List<Byte> byteList = new ArrayList<>(); | 361 | + |
| 362 | - while (channelBuffer.readableBytes() > 0) { | ||
| 363 | - byteList.add(channelBuffer.readByte()); | ||
| 364 | - } | ||
| 365 | byte[] tempByteArray = new byte[IsisUtil.FOUR_BYTES]; | 362 | byte[] tempByteArray = new byte[IsisUtil.FOUR_BYTES]; |
| 366 | channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES); | 363 | channelBuffer.readBytes(tempByteArray, 0, IsisUtil.FOUR_BYTES); |
| 367 | this.setIpAddress(Ip4Address.valueOf(tempByteArray)); | 364 | this.setIpAddress(Ip4Address.valueOf(tempByteArray)); | ... | ... |
| ... | @@ -42,7 +42,10 @@ public class TlvFinder extends TlvHeader { | ... | @@ -42,7 +42,10 @@ public class TlvFinder extends TlvHeader { |
| 42 | //TODO | 42 | //TODO |
| 43 | break; | 43 | break; |
| 44 | case EXTENDEDISREACHABILITY: | 44 | case EXTENDEDISREACHABILITY: |
| 45 | - //TODO | 45 | + IsExtendedReachability isExtendedReachability = |
| 46 | + new IsExtendedReachability(tlvHeader); | ||
| 47 | + isExtendedReachability.readFrom(channelBuffer); | ||
| 48 | + isisTlv = isExtendedReachability; | ||
| 46 | break; | 49 | break; |
| 47 | case HOSTNAME: | 50 | case HOSTNAME: |
| 48 | HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader); | 51 | HostNameTlv hostNameTlv = new HostNameTlv(tlvHeader); | ... | ... |
| ... | @@ -82,6 +82,10 @@ public final class TlvsToBytes { | ... | @@ -82,6 +82,10 @@ public final class TlvsToBytes { |
| 82 | LspEntriesTlv lspEntriesTlv | 82 | LspEntriesTlv lspEntriesTlv |
| 83 | = (LspEntriesTlv) isisTlv; | 83 | = (LspEntriesTlv) isisTlv; |
| 84 | tlvBytes.addAll(Bytes.asList(lspEntriesTlv.asBytes())); | 84 | tlvBytes.addAll(Bytes.asList(lspEntriesTlv.asBytes())); |
| 85 | + } else if (isisTlv instanceof IsExtendedReachability) { | ||
| 86 | + IsExtendedReachability isExtendedReachability | ||
| 87 | + = (IsExtendedReachability) isisTlv; | ||
| 88 | + tlvBytes.addAll(Bytes.asList(isExtendedReachability.asBytes())); | ||
| 85 | } else { | 89 | } else { |
| 86 | log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes "); | 90 | log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes "); |
| 87 | } | 91 | } | ... | ... |
| ... | @@ -16,21 +16,25 @@ | ... | @@ -16,21 +16,25 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.isis.io.util; | 17 | package org.onosproject.isis.io.util; |
| 18 | 18 | ||
| 19 | +import org.onlab.packet.Ip4Address; | ||
| 20 | + | ||
| 19 | /** | 21 | /** |
| 20 | * Representation of ISIS Constants. | 22 | * Representation of ISIS Constants. |
| 21 | */ | 23 | */ |
| 22 | public final class IsisConstants { | 24 | public final class IsisConstants { |
| 23 | - public static final char PDU_LENGTH = 1497; // mtu (1500) - (3) LLC | 25 | + public static final char PDU_LENGTH = 1497; |
| 26 | + public static final char CONFIG_LENGTH = 1498; | ||
| 24 | public static final int MINIMUM_FRAME_LEN = 1521; | 27 | public static final int MINIMUM_FRAME_LEN = 1521; |
| 25 | public static final int METADATA_LEN = 7; | 28 | public static final int METADATA_LEN = 7; |
| 26 | public static final String SHOST = "127.0.0.1"; | 29 | public static final String SHOST = "127.0.0.1"; |
| 30 | + public static final Ip4Address DEFAULTIP = Ip4Address.valueOf("0.0.0.0"); | ||
| 27 | public static final int SPORT = 3000; | 31 | public static final int SPORT = 3000; |
| 28 | public static final byte L2 = 1; | 32 | public static final byte L2 = 1; |
| 29 | public static final int IRPDISCRIMINATOR = 131; | 33 | public static final int IRPDISCRIMINATOR = 131; |
| 30 | public static final int ISISVERSION = 1; | 34 | public static final int ISISVERSION = 1; |
| 31 | public static final int RESERVED = 0; | 35 | public static final int RESERVED = 0; |
| 32 | public static final int MAXAREAADDRESS = 0; | 36 | public static final int MAXAREAADDRESS = 0; |
| 33 | - public static final int IDLENGTH = 0; | 37 | + public static final int SYSTEMIDLENGTH = 0; |
| 34 | public static final int PROTOCOLSUPPORTED = 204; | 38 | public static final int PROTOCOLSUPPORTED = 204; |
| 35 | public static final int LOCALCIRCUITIDFORP2P = 130; | 39 | public static final int LOCALCIRCUITIDFORP2P = 130; |
| 36 | public static final int P2PHELLOHEADERLENGTH = 20; | 40 | public static final int P2PHELLOHEADERLENGTH = 20; |
| ... | @@ -48,6 +52,27 @@ public final class IsisConstants { | ... | @@ -48,6 +52,27 @@ public final class IsisConstants { |
| 48 | public static final int CHECKSUMPOSITION = 24; | 52 | public static final int CHECKSUMPOSITION = 24; |
| 49 | public static final String REFRESHLSP = "refreshLsp"; | 53 | public static final String REFRESHLSP = "refreshLsp"; |
| 50 | public static final String MAXAGELSP = "maxAgeLsp"; | 54 | public static final String MAXAGELSP = "maxAgeLsp"; |
| 55 | + public static final String DEFAULTLANID = "0000.0000.0000.00"; | ||
| 56 | + public static final String PROCESSESID = "processId"; | ||
| 57 | + public static final String INTERFACE = "interface"; | ||
| 58 | + public static final String INTERFACEIP = "interfaceIp"; | ||
| 59 | + public static final String NETWORKMASK = "networkMask"; | ||
| 60 | + public static final String INTERFACEINDEX = "interfaceIndex"; | ||
| 61 | + public static final String INTERMEDIATESYSTEMNAME = "intermediateSystemName"; | ||
| 62 | + public static final String SYSTEMID = "systemId"; | ||
| 63 | + public static final String LANID = "lanId"; | ||
| 64 | + public static final String IDLENGTH = "idLength"; | ||
| 65 | + public static final String MAXAREAADDRESSES = "maxAreaAddresses"; | ||
| 66 | + public static final String RESERVEDPACKETCIRCUITTYPE = "reservedPacketCircuitType"; | ||
| 67 | + public static final String CIRCUITID = "circuitId"; | ||
| 68 | + public static final String NETWORKTYPE = "networkType"; | ||
| 69 | + public static final String AREAADDRESS = "areaAddress"; | ||
| 70 | + public static final String AREALENGTH = "areaLength"; | ||
| 71 | + public static final String LSPID = "lspId"; | ||
| 72 | + public static final String HOLDINGTIME = "holdingTime"; | ||
| 73 | + public static final String HELLOINTERVAL = "helloInterval"; | ||
| 74 | + public static final String PRIORITY = "priority"; | ||
| 75 | + public static final String MACADDRESS = "macAddress"; | ||
| 51 | 76 | ||
| 52 | /** | 77 | /** |
| 53 | * Non parameterized constructor. | 78 | * Non parameterized constructor. | ... | ... |
| ... | @@ -391,7 +391,7 @@ public final class IsisUtil { | ... | @@ -391,7 +391,7 @@ public final class IsisUtil { |
| 391 | isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); | 391 | isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); |
| 392 | isisHeader.setPduHeaderLength((byte) IsisConstants.P2PHELLOHEADERLENGTH); | 392 | isisHeader.setPduHeaderLength((byte) IsisConstants.P2PHELLOHEADERLENGTH); |
| 393 | isisHeader.setVersion((byte) IsisConstants.ISISVERSION); | 393 | isisHeader.setVersion((byte) IsisConstants.ISISVERSION); |
| 394 | - isisHeader.setIdLength((byte) IsisConstants.IDLENGTH); | 394 | + isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH); |
| 395 | isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); | 395 | isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); |
| 396 | isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); | 396 | isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); |
| 397 | //isisHeader.setReserved((byte) IsisConstants.RESERVED); | 397 | //isisHeader.setReserved((byte) IsisConstants.RESERVED); |
| ... | @@ -484,7 +484,7 @@ public final class IsisUtil { | ... | @@ -484,7 +484,7 @@ public final class IsisUtil { |
| 484 | isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); | 484 | isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); |
| 485 | isisHeader.setPduHeaderLength((byte) IsisConstants.HELLOHEADERLENGTH); | 485 | isisHeader.setPduHeaderLength((byte) IsisConstants.HELLOHEADERLENGTH); |
| 486 | isisHeader.setVersion((byte) IsisConstants.ISISVERSION); | 486 | isisHeader.setVersion((byte) IsisConstants.ISISVERSION); |
| 487 | - isisHeader.setIdLength((byte) IsisConstants.IDLENGTH); | 487 | + isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH); |
| 488 | if (isisPduType == IsisPduType.L1HELLOPDU) { | 488 | if (isisPduType == IsisPduType.L1HELLOPDU) { |
| 489 | isisHeader.setIsisPduType(IsisPduType.L1HELLOPDU.value()); | 489 | isisHeader.setIsisPduType(IsisPduType.L1HELLOPDU.value()); |
| 490 | lanId = isisInterface.l1LanId(); | 490 | lanId = isisInterface.l1LanId(); |
| ... | @@ -693,4 +693,19 @@ public final class IsisUtil { | ... | @@ -693,4 +693,19 @@ public final class IsisUtil { |
| 693 | } | 693 | } |
| 694 | return prefix; | 694 | return prefix; |
| 695 | } | 695 | } |
| 696 | + | ||
| 697 | + /** | ||
| 698 | + * Converts the prefix to bytes. | ||
| 699 | + * | ||
| 700 | + * @param prefix prefix | ||
| 701 | + * @return prefix to bytes | ||
| 702 | + */ | ||
| 703 | + public static byte[] prefixToBytes(String prefix) { | ||
| 704 | + List<Byte> byteList = new ArrayList<>(); | ||
| 705 | + StringTokenizer tokenizer = new StringTokenizer(prefix, "."); | ||
| 706 | + while (tokenizer.hasMoreTokens()) { | ||
| 707 | + byteList.add((byte) Integer.parseInt(tokenizer.nextToken())); | ||
| 708 | + } | ||
| 709 | + return Bytes.toArray(byteList); | ||
| 710 | + } | ||
| 696 | } | 711 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -26,6 +26,7 @@ import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas; | ... | @@ -26,6 +26,7 @@ import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas; |
| 26 | import org.onosproject.isis.io.isispacket.pdu.LsPdu; | 26 | import org.onosproject.isis.io.isispacket.pdu.LsPdu; |
| 27 | import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv; | 27 | import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv; |
| 28 | import org.onosproject.isis.io.isispacket.tlv.HostNameTlv; | 28 | import org.onosproject.isis.io.isispacket.tlv.HostNameTlv; |
| 29 | +import org.onosproject.isis.io.isispacket.tlv.IpExtendedReachabilityTlv; | ||
| 29 | import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv; | 30 | import org.onosproject.isis.io.isispacket.tlv.IpInterfaceAddressTlv; |
| 30 | import org.onosproject.isis.io.isispacket.tlv.IpInternalReachabilityTlv; | 31 | import org.onosproject.isis.io.isispacket.tlv.IpInternalReachabilityTlv; |
| 31 | import org.onosproject.isis.io.isispacket.tlv.IsReachabilityTlv; | 32 | import org.onosproject.isis.io.isispacket.tlv.IsReachabilityTlv; |
| ... | @@ -115,7 +116,7 @@ public class LspGenerator { | ... | @@ -115,7 +116,7 @@ public class LspGenerator { |
| 115 | } else if (isisInterface.networkType() == IsisNetworkType.P2P) { | 116 | } else if (isisInterface.networkType() == IsisNetworkType.P2P) { |
| 116 | MacAddress neighborMac = isisInterface.neighbors().iterator().next(); | 117 | MacAddress neighborMac = isisInterface.neighbors().iterator().next(); |
| 117 | IsisNeighbor neighbor = isisInterface.lookup(neighborMac); | 118 | IsisNeighbor neighbor = isisInterface.lookup(neighborMac); |
| 118 | - metricsOfReachability.setNeighborId(neighbor.neighborSystemId()); | 119 | + metricsOfReachability.setNeighborId(neighbor.neighborSystemId() + ".00"); |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | isReachabilityTlv.addMeticsOfReachability(metricsOfReachability); | 122 | isReachabilityTlv.addMeticsOfReachability(metricsOfReachability); |
| ... | @@ -137,10 +138,25 @@ public class LspGenerator { | ... | @@ -137,10 +138,25 @@ public class LspGenerator { |
| 137 | metricOfIntRea.setErrorMetric((byte) 0); | 138 | metricOfIntRea.setErrorMetric((byte) 0); |
| 138 | metricOfIntRea.setErrorMetricSupported(false); | 139 | metricOfIntRea.setErrorMetricSupported(false); |
| 139 | metricOfIntRea.setExpenseIsInternal(true); | 140 | metricOfIntRea.setExpenseIsInternal(true); |
| 140 | - metricOfIntRea.setIpAddress(isisInterface.interfaceIpAddress()); | 141 | + Ip4Address ip4Address = isisInterface.interfaceIpAddress(); |
| 142 | + byte[] ipAddress = ip4Address.toOctets(); | ||
| 143 | + ipAddress[ipAddress.length - 1] = 0; | ||
| 144 | + metricOfIntRea.setIpAddress(Ip4Address.valueOf(ipAddress)); | ||
| 141 | metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask())); | 145 | metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask())); |
| 142 | ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea); | 146 | ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea); |
| 143 | lsp.addTlv(ipInterReacTlv); | 147 | lsp.addTlv(ipInterReacTlv); |
| 148 | + | ||
| 149 | + tlvHeader.setTlvType(TlvType.IPEXTENDEDREACHABILITY.value()); | ||
| 150 | + tlvHeader.setTlvLength(0); | ||
| 151 | + IpExtendedReachabilityTlv extendedTlv = new IpExtendedReachabilityTlv(tlvHeader); | ||
| 152 | + extendedTlv.setDown(false); | ||
| 153 | + extendedTlv.setMetric(10); | ||
| 154 | + extendedTlv.setPrefix("192.168.7"); | ||
| 155 | + extendedTlv.setPrefixLength(24); | ||
| 156 | + extendedTlv.setSubTlvLength((byte) 0); | ||
| 157 | + extendedTlv.setSubTlvPresence(false); | ||
| 158 | + lsp.addTlv(extendedTlv); | ||
| 159 | + | ||
| 144 | return lsp; | 160 | return lsp; |
| 145 | } | 161 | } |
| 146 | 162 | ||
| ... | @@ -149,7 +165,7 @@ public class LspGenerator { | ... | @@ -149,7 +165,7 @@ public class LspGenerator { |
| 149 | isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); | 165 | isisHeader.setIrpDiscriminator((byte) IsisConstants.IRPDISCRIMINATOR); |
| 150 | isisHeader.setPduHeaderLength((byte) IsisUtil.getPduHeaderLength(pduType.value())); | 166 | isisHeader.setPduHeaderLength((byte) IsisUtil.getPduHeaderLength(pduType.value())); |
| 151 | isisHeader.setVersion((byte) IsisConstants.ISISVERSION); | 167 | isisHeader.setVersion((byte) IsisConstants.ISISVERSION); |
| 152 | - isisHeader.setIdLength((byte) IsisConstants.IDLENGTH); | 168 | + isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH); |
| 153 | isisHeader.setIsisPduType(pduType.value()); | 169 | isisHeader.setIsisPduType(pduType.value()); |
| 154 | isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); | 170 | isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); |
| 155 | isisHeader.setReserved((byte) IsisConstants.RESERVED); | 171 | isisHeader.setReserved((byte) IsisConstants.RESERVED); | ... | ... |
-
Please register or login to post a comment