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