Dhruv Dhody
Committed by Gerrit Code Review

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

Change-Id: I86db4dd46d29f636e33494a2a4d0c3be4f373f89
<!--
~ Copyright 2016 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf</artifactId>
<version>1.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-ospf-ctl</artifactId>
<packaging>bundle</packaging>
<description>ONOS Ospf controller subsystem API</description>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ospf-protocol</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.DeviceInformation;
import java.util.ArrayList;
import java.util.List;
/**
* Representation of an OSPF device information.
*/
public class DeviceInformationImpl implements DeviceInformation {
Ip4Address deviceId;
Ip4Address routerId;
List<Ip4Address> interfaceId = new ArrayList<>();
Ip4Address areaId;
boolean alreadyCreated;
boolean isDr;
Ip4Address neighborId;
/**
* Gets router id.
*
* @return router id
*/
public Ip4Address routerId() {
return routerId;
}
/**
* Sets router id.
*
* @param routerId router id
*/
public void setRouterId(Ip4Address routerId) {
this.routerId = routerId;
}
/**
* Gets device id.
*
* @return device id
*/
public Ip4Address deviceId() {
return deviceId;
}
/**
* Sets device id.
*
* @param deviceId device id
*/
public void setDeviceId(Ip4Address deviceId) {
this.deviceId = deviceId;
}
/**
* Gets interface id list.
*
* @return interface id list
*/
public List<Ip4Address> interfaceId() {
return this.interfaceId;
}
/**
* Adds interface id to list.
*
* @param interfaceId interface id
*/
public void addInterfaceId(Ip4Address interfaceId) {
this.interfaceId.add(interfaceId);
}
/**
* Gets area id.
*
* @return area id
*/
public Ip4Address areaId() {
return areaId;
}
/**
* Sets area id.
*
* @param areaId area id
*/
public void setAreaId(Ip4Address areaId) {
this.areaId = areaId;
}
/**
* Gets is already created or not.
*
* @return true if already created else false
*/
public boolean isAlreadyCreated() {
return alreadyCreated;
}
/**
* Sets is already created or not.
*
* @param alreadyCreated true or false
*/
public void setAlreadyCreated(boolean alreadyCreated) {
this.alreadyCreated = alreadyCreated;
}
/**
* Gets is DR or not.
*
* @return true if DR else false
*/
public boolean isDr() {
return isDr;
}
/**
* Stes DR or not.
*
* @param dr true or false
*/
public void setDr(boolean dr) {
this.isDr = dr;
}
/**
* Gets neighbor id.
*
* @return neighbor id
*/
public Ip4Address neighborId() {
return neighborId;
}
/**
* Sets neighbor id.
*
* @param neighborId neighbor id
*/
public void setNeighborId(Ip4Address neighborId) {
this.neighborId = neighborId;
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.LinkInformation;
/**
* Representation of an OSPF link information..
*/
public class LinkInformationImpl implements LinkInformation {
String linkId;
Ip4Address linkSourceId;
Ip4Address linkDestinationId;
Ip4Address interfaceIp;
boolean linkSrcIdNotRouterId;
boolean alreadyCreated;
Ip4Address linkSourceIpAddress;
Ip4Address linkDestinationIpAddress;
/**
* Gets link id.
*
* @return link id
*/
public String linkId() {
return linkId;
}
/**
* Sets link id.
*
* @param linkId link id
*/
public void setLinkId(String linkId) {
this.linkId = linkId;
}
/**
* Gets is already created or not.
*
* @return true if already created else false
*/
public boolean isAlreadyCreated() {
return alreadyCreated;
}
/**
* Sets is already created or not.
*
* @param alreadyCreated true or false
*/
public void setAlreadyCreated(boolean alreadyCreated) {
this.alreadyCreated = alreadyCreated;
}
/**
* Gets is link source id is not router id.
*
* @return true if link source id is router id else false
*/
public boolean isLinkSrcIdNotRouterId() {
return linkSrcIdNotRouterId;
}
/**
* Sets is link source id is not router id.
*
* @param linkSrcIdNotRouterId true or false
*/
public void setLinkSrcIdNotRouterId(boolean linkSrcIdNotRouterId) {
this.linkSrcIdNotRouterId = linkSrcIdNotRouterId;
}
/**
* Gets link destination id.
*
* @return link destination id
*/
public Ip4Address linkDestinationId() {
return linkDestinationId;
}
/**
* Sets link destination id.
*
* @param linkDestinationId link destination id
*/
public void setLinkDestinationId(Ip4Address linkDestinationId) {
this.linkDestinationId = linkDestinationId;
}
/**
* Gets link source id.
*
* @return link source id
*/
public Ip4Address linkSourceId() {
return linkSourceId;
}
/**
* Sets link source id.
*
* @param linkSourceId link source id
*/
public void setLinkSourceId(Ip4Address linkSourceId) {
this.linkSourceId = linkSourceId;
}
/**
* Gets interface IP address.
*
* @return interface IP address
*/
public Ip4Address interfaceIp() {
return interfaceIp;
}
/**
* Sets interface IP address.
*
* @param interfaceIp interface IP address
*/
public void setInterfaceIp(Ip4Address interfaceIp) {
this.interfaceIp = interfaceIp;
}
/**
* Gets link source IP address.
*
* @return link source IP address
*/
public Ip4Address linkSourceIpAddress() {
return linkSourceIpAddress;
}
/**
* Sets link source IP address.
*
* @param linkSourceIpAddress link source IP address
*/
public void setLinkSourceIpAddress(Ip4Address linkSourceIpAddress) {
this.linkSourceIpAddress = linkSourceIpAddress;
}
/**
* Gets link destination IP address.
*
* @return link destination IP address
*/
public Ip4Address linkDestinationIpAddress() {
return linkDestinationIpAddress;
}
/**
* Sets link destination IP address.
*
* @param linkDestinationIpAddress link destination IP address
*/
public void setLinkDestinationIpAddress(Ip4Address linkDestinationIpAddress) {
this.linkDestinationIpAddress = linkDestinationIpAddress;
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.net.driver.DriverService;
import org.onosproject.ospf.controller.OspfAgent;
import org.onosproject.ospf.controller.OspfController;
import org.onosproject.ospf.controller.OspfLinkListener;
import org.onosproject.ospf.controller.OspfLinkTed;
import org.onosproject.ospf.controller.OspfProcess;
import org.onosproject.ospf.controller.OspfRouter;
import org.onosproject.ospf.controller.OspfRouterListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Representation of an OSPF controller implementation.
* Serves as a one stop shop for obtaining OSPF devices and (un)register listeners on OSPF events
*/
@Component(immediate = true)
@Service
public class OspfControllerImpl implements OspfController {
protected static final Logger log = LoggerFactory.getLogger(OspfControllerImpl.class);
private final Controller ctrl = new Controller();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverService driverService;
protected Set<OspfRouterListener> ospfRouterListener = new HashSet<>();
protected Set<OspfLinkListener> ospfLinkListener = Sets.newHashSet();
protected OspfAgent agent = new InternalDeviceConfig();
@Activate
public void activate() {
log.info("OSPFControllerImpl activate...!!!");
ctrl.start(agent, driverService);
log.info("Started");
}
@Deactivate
public void deactivate() {
ctrl.stop();
log.info("Stopped");
}
@Override
public void addRouterListener(OspfRouterListener listener) {
if (!ospfRouterListener.contains(listener)) {
this.ospfRouterListener.add(listener);
}
}
@Override
public void removeRouterListener(OspfRouterListener listener) {
this.ospfRouterListener.remove(listener);
}
@Override
public void addLinkListener(OspfLinkListener listener) {
ospfLinkListener.add(listener);
}
@Override
public void removeLinkListener(OspfLinkListener listener) {
ospfLinkListener.remove(listener);
}
@Override
public Set<OspfRouterListener> listener() {
return ospfRouterListener;
}
@Override
public Set<OspfLinkListener> linkListener() {
return ospfLinkListener;
}
@Override
public List<OspfProcess> getAllConfiguredProcesses() {
List<OspfProcess> processes = ctrl.getAllConfiguredProcesses();
return processes;
}
@Override
public void updateConfig(List processes) {
List<OspfProcess> ospfProcesses = new ArrayList<>();
if (processes != null) {
for (Object process : processes) {
ospfProcesses.add((OspfProcess) process);
}
}
log.debug("updateConfig::OspfList::processes::{}", ospfProcesses);
ctrl.updateConfig(ospfProcesses);
}
@Override
public void deleteConfig(List<OspfProcess> processes, String attribute) {
List<OspfProcess> ospfProcesses = new ArrayList<>();
if (processes != null) {
for (Object process : processes) {
ospfProcesses.add((OspfProcess) process);
}
}
log.debug("deleteConfig::OspfList::processes::{}", ospfProcesses);
ctrl.deleteConfig(ospfProcesses, attribute);
}
/**
* Notifier for internal OSPF device and link changes.
*/
private class InternalDeviceConfig implements OspfAgent {
@Override
public boolean addConnectedRouter(OspfRouter ospfRouter) {
for (OspfRouterListener l : listener()) {
l.routerAdded(ospfRouter);
}
return true;
}
@Override
public void removeConnectedRouter(OspfRouter ospfRouter) {
for (OspfRouterListener l : listener()) {
l.routerRemoved(ospfRouter);
}
}
@Override
public void addLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) {
for (OspfLinkListener l : linkListener()) {
l.addLink(ospfRouter, ospfLinkTed);
}
}
@Override
public void deleteLink(OspfRouter ospfRouter) {
for (OspfLinkListener l : linkListener()) {
l.deleteLink(ospfRouter);
}
}
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onosproject.ospf.controller.OspfDeviceTed;
import java.util.List;
/**
* Representation of an OSPF device Traffic Engineering details.
*/
public class OspfDeviceTedImpl implements OspfDeviceTed {
List<Ip4Address> ipv4RouterIds;
List<Ip6Address> ipv6RouterIds;
List<Short> topologyIds;
Boolean asbr;
Boolean abr;
/**
* Gets list of IPv4 router id.
*
* @return list of IPv4 router id
*/
public List<Ip4Address> ipv4RouterIds() {
return ipv4RouterIds;
}
@Override
public void setIpv4RouterIds(List<Ip4Address> ipv4RouterIds) {
this.ipv4RouterIds = ipv4RouterIds;
}
/**
* Gets if router is area border router or not.
*
* @return true if it is area border router else false
*/
public Boolean abr() {
return abr;
}
@Override
public void setAbr(Boolean abr) {
this.abr = abr;
}
/**
* Gets if router is autonomous system border router or not.
*
* @return true or false
*/
public Boolean asbr() {
return asbr;
}
@Override
public void setAsbr(Boolean asbr) {
this.asbr = asbr;
}
/**
* Gets list of topology id's.
*
* @return list of topology id's
*/
public List<Short> topologyIds() {
return topologyIds;
}
@Override
public void setTopologyIds(List<Short> topologyIds) {
this.topologyIds = topologyIds;
}
/**
* Gets list of ipv6 router id's.
*
* @return list of ipv6 router id's
*/
public List<Ip6Address> ipv6RouterIds() {
return ipv6RouterIds;
}
@Override
public void setIpv6RouterIds(List<Ip6Address> ipv6RouterIds) {
this.ipv6RouterIds = ipv6RouterIds;
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onlab.util.Bandwidth;
import org.onosproject.ospf.controller.OspfLinkTed;
import java.util.ArrayList;
import java.util.List;
/**
* Implements OSPF Link Traffic engineering details.
*/
public class OspfLinkTedImpl implements OspfLinkTed {
Bandwidth maximumLink;
List<Bandwidth> maxUnResBandwidth = new ArrayList<>();
Bandwidth maxReserved;
Integer teMetric;
List<Ip4Address> ipv4LocRouterId = new ArrayList<>();
List<Ip6Address> ipv6LocRouterId = new ArrayList<>();
List<Ip4Address> ipv4RemRouterId = new ArrayList<>();
List<Ip6Address> ipv6RemRouterId = new ArrayList<>();
/**
* Gets maximum link.
*
* @return maximum link
*/
public Bandwidth maximumLink() {
return maximumLink;
}
/**
* Sets maximum link.
*
* @param maximumLink maximum link
*/
public void setMaximumLink(Bandwidth maximumLink) {
this.maximumLink = maximumLink;
}
/**
* Gets list of IPv6 remote router id.
*
* @return list of IPv6 remote router id
*/
public List<Ip6Address> ipv6RemRouterId() {
return ipv6RemRouterId;
}
/**
* Sets list of IPv6 remote router id.
*
* @param ipv6RemRouterId IPv6 remote router id
*/
public void setIpv6RemRouterId(List<Ip6Address> ipv6RemRouterId) {
this.ipv6RemRouterId = ipv6RemRouterId;
}
/**
* Gets list of IPv4 remote router id.
*
* @return list of IPv4 remote router id
*/
public List<Ip4Address> ipv4RemRouterId() {
return ipv4RemRouterId;
}
/**
* Sets IPv4 remote router id.
*
* @param ipv4RemRouterId IPv4 remote router id
*/
public void setIpv4RemRouterId(List<Ip4Address> ipv4RemRouterId) {
this.ipv4RemRouterId = ipv4RemRouterId;
}
/**
* Gets list of IPv6 local router id.
*
* @return list of IPv6 local router id
*/
public List<Ip6Address> ipv6LocRouterId() {
return ipv6LocRouterId;
}
/**
* Sets list of IPv6 local router id.
*
* @param ipv6LocRouterId IPv6 local router id
*/
public void setIpv6LocRouterId(List<Ip6Address> ipv6LocRouterId) {
this.ipv6LocRouterId = ipv6LocRouterId;
}
/**
* Gets list of IPv4 local router id.
*
* @return list of IPv4 local router id
*/
public List<Ip4Address> ipv4LocRouterId() {
return ipv4LocRouterId;
}
/**
* Sets list of IPv4 local router id.
*
* @param ipv4LocRouterId IPv4 local router id
*/
public void setIpv4LocRouterId(List<Ip4Address> ipv4LocRouterId) {
this.ipv4LocRouterId = ipv4LocRouterId;
}
/**
* Gets traffic engineering metric.
*
* @return traffic engineering metric
*/
public Integer teMetric() {
return teMetric;
}
/**
* Sets traffic engineering metric.
*
* @param teMetric Traffic engineering metric
*/
public void setTeMetric(Integer teMetric) {
this.teMetric = teMetric;
}
/**
* Gets maximum bandwidth reserved.
*
* @return maximum bandwidth reserved
*/
public Bandwidth maxReserved() {
return maxReserved;
}
/**
* Sets maximum bandwidth reserved.
*
* @param maxReserved maximum bandwidth reserved
*/
public void setMaxReserved(Bandwidth maxReserved) {
this.maxReserved = maxReserved;
}
/**
* Gets list of maximum unreserved bandwidth.
*
* @return list of maximum unreserved bandwidth
*/
public List<Bandwidth> maxUnResBandwidth() {
return maxUnResBandwidth;
}
/**
* Sets ist of maximum unreserved bandwidth.
*
* @param bandwidth maximum unreserved bandwidth
*/
public void setMaxUnResBandwidth(Bandwidth bandwidth) {
this.maxUnResBandwidth.add(bandwidth);
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
import org.onosproject.ospf.protocol.ospfpacket.OspfMessageReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedList;
import java.util.List;
/**
* Decodes an OSPF message from a Channel, for use in a netty pipeline.
*/
public class OspfMessageDecoder extends FrameDecoder {
private static final Logger log = LoggerFactory.getLogger(OspfMessageDecoder.class);
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer channelBuffer) throws Exception {
log.debug("OspfMessageDecoder::Message received <:> length {}", channelBuffer.readableBytes());
log.debug("channelBuffer.readableBytes - decode {}", channelBuffer.readableBytes());
if (!channel.isConnected()) {
log.info("Channel is not connected.");
return null;
}
OspfMessageReader messageReader = new OspfMessageReader();
List<OspfMessage> ospfMessageList = new LinkedList<>();
while (channelBuffer.readableBytes() > 0) {
OspfMessage message = messageReader.readFromBuffer(channelBuffer);
if (message != null) {
ospfMessageList.add(message);
}
}
return ospfMessageList;
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import org.onosproject.ospf.controller.OspfInterface;
import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
import org.onosproject.ospf.protocol.ospfpacket.OspfMessage;
import org.onosproject.ospf.protocol.ospfpacket.OspfMessageWriter;
import org.onosproject.ospf.protocol.util.OspfInterfaceState;
import org.onosproject.ospf.protocol.util.OspfUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Encodes an OSPF message for output into a ChannelBuffer, for use in a netty pipeline.
*/
public class OspfMessageEncoder extends OneToOneEncoder {
private static final Logger log = LoggerFactory.getLogger(OspfMessageEncoder.class);
private OspfInterface ospfInterface;
/**
* Constructor.
*/
OspfMessageEncoder() {
}
/**
* Constructor to initialize instance.
*/
OspfMessageEncoder(OspfInterface ospfInterface) {
this.ospfInterface = ospfInterface;
}
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
log.debug("Encoding ospfMessage...!!!");
if (!(msg instanceof OspfMessage)) {
log.debug("Invalid msg.");
return msg;
}
OspfMessage ospfMessage = (OspfMessage) msg;
OspfMessageWriter messageWriter = new OspfMessageWriter();
if (((OspfInterfaceImpl) ospfInterface).state().equals(OspfInterfaceState.POINT2POINT)) {
ospfMessage.setDestinationIp(OspfUtil.ALL_SPF_ROUTERS);
}
ChannelBuffer buf = messageWriter.writeToBuffer(ospfMessage,
((OspfInterfaceImpl) ospfInterface).state().value(),
ospfInterface.interfaceType());
log.info("OspfMessageEncoder sending packet of lenght {}", buf.readableBytes());
log.debug("OspfMessageEncoder sending packet of lenght {}", buf.readableBytes());
log.debug("Sending {} Message to {}, Length :: {}, <=> {}", ospfMessage.ospfMessageType(),
ospfMessage.destinationIp(), buf.readableBytes(), buf.array());
return buf;
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
import org.jboss.netty.util.ExternalResourceReleasable;
import org.jboss.netty.util.HashedWheelTimer;
import org.jboss.netty.util.Timer;
import org.onosproject.ospf.controller.OspfArea;
import org.onosproject.ospf.controller.OspfInterface;
/**
* Creates a ChannelPipeline for a server-side OSPF channel.
*/
public class OspfPipelineFactory implements ChannelPipelineFactory, ExternalResourceReleasable {
private static final Timer TIMER = new HashedWheelTimer();
private Controller controller;
private ReadTimeoutHandler readTimeoutHandler;
private OspfArea ospfArea;
private OspfInterface ospfInterface;
private int holdTime = 120 * 1000;
/**
* Creates an instance of OSPF pipeline factory.
*
* @param controller controller instance.
* @param ospfArea OSPF area instance.
* @param ospfInterface OSPF interface instance.
*/
public OspfPipelineFactory(Controller controller, OspfArea ospfArea, OspfInterface ospfInterface) {
super();
this.controller = controller;
this.ospfArea = ospfArea;
this.ospfInterface = ospfInterface;
readTimeoutHandler = new ReadTimeoutHandler(TIMER, holdTime);
}
@Override
public ChannelPipeline getPipeline() throws Exception {
OspfInterfaceChannelHandler interfaceHandler = new OspfInterfaceChannelHandler(
controller, ospfArea, ospfInterface);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("encoder", new OspfMessageEncoder(ospfInterface));
pipeline.addLast("decoder", new OspfMessageDecoder());
pipeline.addLast("holdTime", readTimeoutHandler);
pipeline.addLast("interfacehandler", interfaceHandler);
return pipeline;
}
@Override
public void releaseExternalResources() {
TIMER.stop();
}
}
\ No newline at end of file
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.onlab.packet.Ip4Address;
import org.onosproject.ospf.controller.OspfDeviceTed;
import org.onosproject.ospf.controller.OspfRouter;
/**
* Representation of an OSPF Router.
*/
public class OspfRouterImpl implements OspfRouter {
private Ip4Address routerIp;
private Ip4Address areaIdOfInterface;
private Ip4Address neighborRouterId;
private Ip4Address interfaceId;
private OspfDeviceTed deviceTed;
private boolean isOpaque;
private boolean isDr;
/**
* Gets IP address of the Router.
*
* @return IP address router
*/
public Ip4Address routerIp() {
return routerIp;
}
/**
* Sets IP address of the Router.
*/
public void setRouterIp(Ip4Address routerIp) {
this.routerIp = routerIp;
}
/**
* Gets the area id of this device.
*
* @return the area id od this device
*/
public Ip4Address areaIdOfInterface() {
return areaIdOfInterface;
}
/**
* Sets the area id for this device.
*/
public void setAreaIdOfInterface(Ip4Address areaIdOfInterface) {
this.areaIdOfInterface = areaIdOfInterface;
}
/**
* Gets IP address of the interface.
*
* @return IP address of the interface
*/
public Ip4Address interfaceId() {
return interfaceId;
}
/**
* Gets IP address of the interface.
*
* @param interfaceId IP address of the interface
*/
public void setInterfaceId(Ip4Address interfaceId) {
this.interfaceId = interfaceId;
}
/**
* Gets List of the device ted.
*
* @return List of the device ted.
*/
public OspfDeviceTed deviceTed() {
return deviceTed;
}
/**
* Sets List of the device TED.
*
* @param deviceTed of the device TED.
*/
public void setDeviceTed(OspfDeviceTed deviceTed) {
this.deviceTed = deviceTed;
}
/**
* Gets boolean value.
*
* @return boolean value.
*/
public boolean isOpaque() {
return isOpaque;
}
/**
* Sets boolean value.
*
* @param opaque true if opaque else false
*/
public void setOpaque(boolean opaque) {
isOpaque = opaque;
}
/**
* Gets neighbor's Router id.
*
* @return neighbor's Router id
*/
public Ip4Address neighborRouterId() {
return neighborRouterId;
}
/**
* Sets neighbor's Router id.
*
* @param advertisingRouterId neighbor's Router id
*/
public void setNeighborRouterId(Ip4Address advertisingRouterId) {
this.neighborRouterId = advertisingRouterId;
}
/**
* Gets if DR or not.
*
* @return true if DR else false
*/
public boolean isDr() {
return isDr;
}
/**
* Sets dr or not.
*
* @param dr true if DR else false
*/
public void setDr(boolean dr) {
isDr = dr;
}
}
\ No newline at end of file
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ospf.controller.impl;
import org.onlab.packet.Ip4Address;
import org.onlab.util.Bandwidth;
import org.onosproject.ospf.controller.DeviceInformation;
import org.onosproject.ospf.controller.LinkInformation;
import org.onosproject.ospf.controller.OspfArea;
import org.onosproject.ospf.controller.OspfInterface;
import org.onosproject.ospf.controller.OspfLinkTed;
import org.onosproject.ospf.controller.OspfLsa;
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.controller.TopologyForDeviceAndLink;
import org.onosproject.ospf.protocol.lsa.linksubtype.LinkSubType;
import org.onosproject.ospf.protocol.lsa.linksubtype.LocalInterfaceIpAddress;
import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumBandwidth;
import org.onosproject.ospf.protocol.lsa.linksubtype.MaximumReservableBandwidth;
import org.onosproject.ospf.protocol.lsa.linksubtype.RemoteInterfaceIpAddress;
import org.onosproject.ospf.protocol.lsa.linksubtype.TrafficEngineeringMetric;
import org.onosproject.ospf.protocol.lsa.linksubtype.UnreservedBandwidth;
import org.onosproject.ospf.protocol.lsa.subtypes.OspfLsaLink;
import org.onosproject.ospf.protocol.lsa.tlvtypes.LinkTlv;
import org.onosproject.ospf.protocol.lsa.types.NetworkLsa;
import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10;
import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
import org.onosproject.ospf.protocol.lsa.types.TopLevelTlv;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Represents device and link topology information.
*/
public class TopologyForDeviceAndLinkImpl implements TopologyForDeviceAndLink {
private static final Logger log = LoggerFactory.getLogger(TopologyForDeviceAndLinkImpl.class);
private Map<String, DeviceInformation> deviceInformationMap = new LinkedHashMap();
private Map<String, DeviceInformation> deviceInformationMapToDelete = new LinkedHashMap();
private HashMap<String, Set<OspfLsaLink>> deviceAndLinkInformation = new HashMap();
private HashMap<String, OspfLinkTed> ospfLinkTedHashMap = new LinkedHashMap();
private Ip4Address drRouter = Ip4Address.valueOf("0.0.0.0");
private Ip4Address drRouterOld = Ip4Address.valueOf("0.0.0.0");
private Ip4Address adRouterId = Ip4Address.valueOf("0.0.0.0");
private Map<String, LinkInformation> linkInformationMap = new LinkedHashMap();
private List<String> toRemove = new ArrayList<>();
/**
* Gets device information.
*
* @return device information
*/
public Map<String, DeviceInformation> deviceInformationMap() {
return deviceInformationMap;
}
/**
* Sets device information.
*
* @param key key used to add in map
* @param deviceInformationMap device information instance
*/
public void setDeviceInformationMap(String key, DeviceInformation deviceInformationMap) {
if (deviceInformationMap != null) {
this.deviceInformationMap.put(key, deviceInformationMap);
}
}
/**
* Gets device information.
*
* @return device information to delete from core
*/
public Map<String, DeviceInformation> deviceInformationMapToDelete() {
return deviceInformationMapToDelete;
}
/**
* Sets device information for removal.
*
* @param key ket used to add in map
* @param deviceInformationMapToDelete map from device information to remove
*/
public void setDeviceInformationMapToDelete(String key,
DeviceInformation deviceInformationMapToDelete) {
if (deviceInformationMapToDelete != null) {
this.deviceInformationMapToDelete.put(key, deviceInformationMapToDelete);
}
}
/**
* Removes Device Information.
*
* @param key ket used to remove from map
*/
public void removeDeviceInformationMapFromDeleteMap(String key) {
removeDeviceInformationMap(key);
if (this.deviceInformationMapToDelete.containsKey(key)) {
this.deviceInformationMapToDelete.remove(key);
}
}
/**
* Gets Device Information.
*
* @param key key to store in map
* @return Device Information
*/
public DeviceInformation deviceInformation(String key) {
DeviceInformation deviceInformation = this.deviceInformationMap.get(key);
return deviceInformation;
}
/**
* Removes Device Information from map.
*
* @param key key used to remove from map
*/
public void removeDeviceInformationMap(String key) {
if (this.deviceInformationMap.containsKey(key)) {
this.deviceInformationMap.remove(key);
}
}
/**
* Gets link information as map.
*
* @return link information as map
*/
public Map<String, LinkInformation> linkInformationMap() {
return linkInformationMap;
}
/**
* Sets link information in map.
*
* @param key key used to add in map
* @param linkInformationMap link information instance
*/
public void setLinkInformationMap(String key, LinkInformation linkInformationMap) {
if (!this.linkInformationMap.containsKey(key)) {
this.linkInformationMap.put(key, linkInformationMap);
}
}
/**
* Removes Link Information from map.
*
* @param key key used to remove from map
*/
public void removeLinkInformationMap(String key) {
if (this.linkInformationMap.containsKey(key)) {
this.linkInformationMap.remove(key);
}
}
/**
* Gets OSPF Link TED details from the map.
*
* @param key key used to retreive from map
* @return OSPF link ted instance
*/
public OspfLinkTed getOspfLinkTedHashMap(String key) {
OspfLinkTed ospfLinkTed = ospfLinkTedHashMap.get(key);
return ospfLinkTed;
}
/**
* Adds device information to map.
*
* @param ospfLsa OSPF LSA instance
* @param ospfInterface OSPF interface instance
* @param ospfArea OSPF area instance
*/
public void addLocalDevice(OspfLsa ospfLsa, OspfInterface ospfInterface, OspfArea ospfArea) {
if (ospfLsa.getOspfLsaType().equals(OspfLsaType.ROUTER)) {
createDeviceAndLinkFromRouterLsa(ospfLsa, ospfArea);
} else if (ospfLsa.getOspfLsaType().equals(OspfLsaType.NETWORK)) {
createDeviceAndLinkFromNetworkLsa(ospfLsa, ospfArea);
} else if (ospfLsa.getOspfLsaType().equals(OspfLsaType.AREA_LOCAL_OPAQUE_LSA)) {
createDeviceAndLinkFromOpaqueLsa(ospfLsa, ospfArea);
}
}
/**
* Creates device object from parameters.
*
* @param alreadyCreated device already created or not
* @param deviceId device id
* @param neighborId neighbor's id
* @param routerId router's id
* @param interfaceId interface id
* @param areaId area id
* @param isDr true if router is DR else false
*/
private DeviceInformation createDeviceInformation(boolean alreadyCreated, Ip4Address deviceId,
Ip4Address neighborId, Ip4Address routerId,
Ip4Address interfaceId, Ip4Address areaId,
boolean isDr) {
DeviceInformation deviceInformation = new DeviceInformationImpl();
deviceInformation.setAlreadyCreated(alreadyCreated);
deviceInformation.setDeviceId(deviceId);
deviceInformation.setNeighborId(neighborId);
deviceInformation.setRouterId(routerId);
deviceInformation.addInterfaceId(interfaceId);
deviceInformation.setAreaId(areaId);
deviceInformation.setDr(isDr);
return deviceInformation;
}
/**
* Creates Device and Link instance from the RouterLsa parameters.
*
* @param ospfLsa OSPF LSA instance
* @param ospfArea OSPF area
*/
private void createDeviceAndLinkFromRouterLsa(OspfLsa ospfLsa, OspfArea ospfArea) {
RouterLsa routerLsa = (RouterLsa) ospfLsa;
List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink();
Iterator iterator = ospfLsaLinkList.iterator();
Ip4Address advertisingRouterId = routerLsa.advertisingRouter();
adRouterId = advertisingRouterId;
while (iterator.hasNext()) {
OspfLsaLink ospfLsaLink = (OspfLsaLink) iterator.next();
Ip4Address linkId = Ip4Address.valueOf(ospfLsaLink.linkId());
Ip4Address linkData = Ip4Address.valueOf(ospfLsaLink.linkData());
if (ospfLsaLink.linkType() == 1) {
if ((advertisingRouterId.equals(ospfArea.routerId())) || (linkId.equals(ospfArea.routerId()))) {
System.out.println("OspfInterface information will not display in web ");
} else {
removeDevice(advertisingRouterId);
removeLinks(advertisingRouterId);
DeviceInformation deviceInformationPointToPoint =
createDeviceInformation(false, linkId, linkId, advertisingRouterId, linkData,
ospfArea.areaId(), false);
String key = "device:" + advertisingRouterId;
setDeviceInformationMap(key, deviceInformationPointToPoint);
String linkIdKey = "linkId:" + advertisingRouterId + "-" + linkId;
addLocalLink(linkIdKey, linkData, advertisingRouterId, linkId, true, false);
}
} else if (ospfLsaLink.linkType() == 2) {
if ((advertisingRouterId.equals(ospfArea.routerId())) || (linkId.equals(ospfArea.routerId()))) {
log.debug("OspfInterface information will not display in web ");
} else {
if (linkId.equals(linkData)) {
if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
log.debug("drRouter not elected {} ", drRouter.toString());
} else {
if (drRouterOld.equals(linkId)) {
log.debug("drRouterOld same as link id {} ", drRouterOld.toString());
} else {
String key = "device:" + drRouterOld;
DeviceInformation deviceInformation1 = deviceInformation(key);
if (deviceInformation1 != null) {
deviceInformation1.setAlreadyCreated(true);
setDeviceInformationMapToDelete(key, deviceInformation1);
String linkIdKey = "linkId:" + linkId + "-" + deviceInformation1.neighborId();
addLocalLink(linkIdKey, linkData, linkId, deviceInformation1.neighborId(),
true, false);
String linkIdKey1 = "linkId:" + linkId + "-" + advertisingRouterId;
addLocalLink(linkIdKey1, linkData, linkId, advertisingRouterId, true, false);
} else {
DeviceInformation deviceInformationToDelete =
createDeviceInformation(true, drRouterOld, drRouterOld,
drRouterOld, drRouterOld,
drRouterOld, true);
setDeviceInformationMapToDelete(key, deviceInformationToDelete);
String linkIdKey1 = "linkId:" + linkId + "-" + advertisingRouterId;
addLocalLink(linkIdKey1, linkData, linkId, advertisingRouterId, true, false);
}
}
}
drRouter = linkId;
drRouterOld = linkId;
DeviceInformation deviceInformationForDr =
createDeviceInformation(false, linkId, advertisingRouterId, linkId, linkData,
ospfArea.areaId(), true);
String key = "device:" + linkId;
setDeviceInformationMap(key, deviceInformationForDr);
DeviceInformation deviceInformationForAdvertisingRouter =
createDeviceInformation(false, linkId, advertisingRouterId, advertisingRouterId,
linkData, ospfArea.areaId(), false);
String key1 = "device:" + advertisingRouterId;
setDeviceInformationMap(key1, deviceInformationForAdvertisingRouter);
if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
System.out.println("Link will not get create since dr is not valid");
//Need to analysis since this place will not get Dr information
String linkIdKey = "linkId:" + linkId + "-" + advertisingRouterId;
addLocalLink(linkIdKey, linkData, linkId, advertisingRouterId, true, false);
} else {
String linkIdKey = "linkId:" + drRouter + "-" + advertisingRouterId;
addLocalLink(linkIdKey, linkData, drRouter, advertisingRouterId, true, false);
}
} else {
DeviceInformation deviceInformationDrOther =
createDeviceInformation(false, linkId, linkId, advertisingRouterId,
linkData, ospfArea.areaId(), false);
String key = "device:" + advertisingRouterId;
setDeviceInformationMap(key, deviceInformationDrOther);
if (drRouter.equals(Ip4Address.valueOf("0.0.0.0"))) {
String linkIdKey = "linkId:" + linkId + "-" + advertisingRouterId;
addLocalLink(linkIdKey, linkData, linkId, advertisingRouterId, true, false);
} else {
String linkIdKey = "linkId:" + drRouter + "-" + advertisingRouterId;
addLocalLink(linkIdKey, linkData, drRouter, advertisingRouterId, true, false);
}
}
}
}
}
}
/**
* Creates Device and Link instance from the NetworkLsa parameters.
*
* @param ospfLsa OSPF LSA instance
* @param ospfArea OSPF area instance
*/
private void createDeviceAndLinkFromNetworkLsa(OspfLsa ospfLsa, OspfArea ospfArea) {
NetworkLsa networkLsa = (NetworkLsa) ospfLsa;
Ip4Address advertisingRouterId = networkLsa.networkMask();
System.out.println("AdvertisingRouterId is : " + advertisingRouterId);
}
/**
* Creates Device and Link instance from the OpaqueLsa parameters.
*
* @param ospfLsa OSPF LSA instance
* @param ospfArea OSPF area instance
*/
private void createDeviceAndLinkFromOpaqueLsa(OspfLsa ospfLsa, OspfArea ospfArea) {
OspfLinkTed ospfLinkTed = new OspfLinkTedImpl();
OpaqueLsa10 opaqueLsa10 = (OpaqueLsa10) ospfLsa;
List<TopLevelTlv> topLevelTlvList = opaqueLsa10.topLevelValues();
for (TopLevelTlv topLevelTlv : topLevelTlvList) {
if (topLevelTlv instanceof LinkTlv) {
LinkTlv linkTlv = (LinkTlv) topLevelTlv;
List<LinkSubType> subTypes = linkTlv.subTlvList();
for (LinkSubType type : subTypes) {
if (type instanceof UnreservedBandwidth) {
UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) type;
List<Float> bandwidthFloatValues = unreservedBandwidth.getUnReservedBandwidthValue();
List<Bandwidth> bandwidthList = new ArrayList<>();
for (Float value : bandwidthFloatValues) {
Bandwidth bandwidth = Bandwidth.bps((double) value);
ospfLinkTed.setMaxUnResBandwidth(bandwidth);
bandwidthList.add(bandwidth);
}
}
if (type instanceof MaximumBandwidth) {
MaximumBandwidth maximumBandwidth = (MaximumBandwidth) type;
float maxBandValue = maximumBandwidth.getMaximumBandwidthValue();
Bandwidth bandwidth = Bandwidth.bps((double) maxBandValue);
ospfLinkTed.setMaximumLink(bandwidth);
}
if (type instanceof MaximumReservableBandwidth) {
MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) type;
float maxResBandValue = maximumReservableBandwidth.getMaximumBandwidthValue();
Bandwidth bandwidth = Bandwidth.bps((double) maxResBandValue);
ospfLinkTed.setMaxReserved(bandwidth);
}
if (type instanceof TrafficEngineeringMetric) {
TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) type;
long teMetric = trafficEngineeringMetric.getTrafficEngineeringMetricValue();
ospfLinkTed.setTeMetric((Integer) (int) teMetric);
}
if (type instanceof LocalInterfaceIpAddress) {
LocalInterfaceIpAddress localInterfaceIpAddress = (LocalInterfaceIpAddress) type;
List<String> stringValue = localInterfaceIpAddress.getLocalInterfaceIPAddress();
List<Ip4Address> localIp4Address = new ArrayList<>();
for (String value : stringValue) {
Ip4Address ip4Address = Ip4Address.valueOf(value);
localIp4Address.add(ip4Address);
}
ospfLinkTed.setIpv4LocRouterId(localIp4Address);
}
if (type instanceof RemoteInterfaceIpAddress) {
RemoteInterfaceIpAddress remoteInterfaceIpAddress = (RemoteInterfaceIpAddress) type;
List<String> stringValue = remoteInterfaceIpAddress.getRemoteInterfaceAddress();
List<Ip4Address> remoteIp4Address = new ArrayList<>();
for (String value : stringValue) {
Ip4Address ip4Address = Ip4Address.valueOf(value);
remoteIp4Address.add(ip4Address);
}
ospfLinkTed.setIpv4RemRouterId(remoteIp4Address);
}
}
}
}
ospfLinkTedHashMap.put(adRouterId.toString(), ospfLinkTed);
}
/**
* Adds link information to LinkInformationMap.
*
* @param advertisingRouter advertising router
* @param linkData link data address
* @param linkSrc link source address
* @param linkDest link destination address
* @param opaqueEnabled opaque enabled or not
* @param linkSrcIdNotRouterId link source id or not
*/
public void addLocalLink(String advertisingRouter, Ip4Address linkData, Ip4Address linkSrc, Ip4Address linkDest,
boolean opaqueEnabled, boolean linkSrcIdNotRouterId) {
String linkKey = "link:";
LinkInformation linkInformation = new LinkInformationImpl();
linkInformation.setLinkId(advertisingRouter);
linkInformation.setLinkSourceId(linkSrc);
linkInformation.setLinkDestinationId(linkDest);
linkInformation.setAlreadyCreated(false);
linkInformation.setLinkSrcIdNotRouterId(linkSrcIdNotRouterId);
linkInformation.setInterfaceIp(linkData);
if (linkDest != null) {
linkInformation.setLinkSrcIdNotRouterId(false);
}
linkKey = linkKey + "-" + linkSrc + "-" + linkDest;
setLinkInformationMap(linkKey, linkInformation);
}
/**
* Removes links from LinkInformationMap.
*
* @param routerId router id
*/
public void removeLinks(Ip4Address routerId) {
Map<String, LinkInformation> linkInformationMaplocal = linkInformationMap;
if (linkInformationMaplocal != null) {
for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) {
String key = entry.getKey();
boolean check = key.contains(routerId.toString());
LinkInformation linkInformation = linkInformationMap.get(key);
boolean check1 = (linkInformation.linkDestinationId() == routerId) ? true : false;
if (check || check1) {
toRemove.add(key);
}
}
removeLinkFromMap();
}
}
/**
* Removes Device from DeviceInformationMap.
*
* @param routerId router id
*/
public void removeDevice(Ip4Address routerId) {
String key = "device:" + routerId;
this.deviceInformationMap.remove(key);
}
/**
* Removes link information from Map.
*/
private void removeLinkFromMap() {
Iterator iterator = toRemove.iterator();
while (iterator.hasNext()) {
String key = (String) iterator.next();
removeLinkInformationMap(key);
}
}
/**
* Updates the deviceAndLinkInformation list for received OSPF LSA.
*
* @param ospfLsa OSPF LSA instance
* @param ospfArea OSPF area instance
*/
public void updateLinkInformation(OspfLsa ospfLsa, OspfArea ospfArea) {
if (ospfLsa.getOspfLsaType().equals(OspfLsaType.ROUTER)) {
RouterLsa routerLsa = (RouterLsa) ospfLsa;
routerLsa.lsType();
List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink();
for (OspfLsaLink link : ospfLsaLinkList) {
if (link.linkType == 1 || link.linkType == 2) {
if ((routerLsa.advertisingRouter().equals(ospfArea.routerId())) ||
(link.equals(ospfArea.routerId()))) {
log.debug("OspfInterface information will not display in web ");
} else {
String key = routerLsa.advertisingRouter() + "-" + link.linkData();
Set<OspfLsaLink> linkInformations = new HashSet<>();
if (deviceAndLinkInformation.containsKey(key)) {
linkInformations = deviceAndLinkInformation.get(key);
linkInformations.add(link);
deviceAndLinkInformation.put(key, linkInformations);
} else {
linkInformations.add(link);
deviceAndLinkInformation.put(key, linkInformations);
}
}
}
}
}
}
/**
* Gets all the router information which needs to delete from deviceList.
*
* @param ospfLsa OSPF LSA instance
* @param ospfArea OSPF area instance
* @return list of deleted router information
*/
public List<String> getDeleteRouterInformation(OspfLsa ospfLsa, OspfArea ospfArea) {
List<String> removedLinkList = new ArrayList<>();
if (ospfLsa.getOspfLsaType().equals(OspfLsaType.ROUTER)) {
RouterLsa routerLsa = (RouterLsa) ospfLsa;
List<OspfLsaLink> ospfLsaLinkList = routerLsa.routerLink();
for (OspfLsaLink link : ospfLsaLinkList) {
if (link.linkType == 1 || link.linkType == 2) {
if ((routerLsa.advertisingRouter().equals(ospfArea.routerId())) ||
(link.equals(ospfArea.routerId()))) {
log.debug("OspfInterface information will not display in web ");
} else {
String key = routerLsa.advertisingRouter() + "-" + link.linkData();
Set<OspfLsaLink> linkInformations = deviceAndLinkInformation.get(key);
if (linkInformations.contains(link)) {
linkInformations.remove(link);
deviceAndLinkInformation.put(key, linkInformations);
}
}
}
Set<String> keys = deviceAndLinkInformation.keySet();
for (String key : keys) {
Set<OspfLsaLink> linkInformations = deviceAndLinkInformation.get(key);
for (OspfLsaLink link1 : linkInformations) {
String removedLink = link1.linkId();
removedLinkList.add(removedLink);
}
}
}
}
return removedLinkList;
}
}
\ No newline at end of file