aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/bgp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/bgp')
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPConnectPeer.java28
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java71
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java74
-rwxr-xr-xframework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java14
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java6
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java7
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java9
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java21
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java5
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java51
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java11
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java10
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java10
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java9
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java13
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java12
-rw-r--r--framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java32
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java21
-rwxr-xr-xframework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java33
-rw-r--r--framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java26
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java400
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java185
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java12
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java84
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java25
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPSessionInfo.java149
-rwxr-xr-xframework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java100
27 files changed, 778 insertions, 640 deletions
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPConnectPeer.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPConnectPeer.java
deleted file mode 100755
index a2a66438..00000000
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPConnectPeer.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.bgp.controller;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * Abstraction of an BGP connect peer, initiate remote connection to BGP peer on configuration.
- */
-public interface BGPConnectPeer {
-
- /**
- * Returns the executor initialized to connect peer.
- *
- * @return connectExecutor the connection executor
- */
- ExecutorService connectExecutor();
-}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java
index 49432aab..9d44041e 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java
@@ -16,11 +16,15 @@
package org.onosproject.bgp.controller;
+import java.util.Map;
+import java.util.Set;
+
+import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.protocol.BGPMessage;
/**
- * Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners
- * on bgp events
+ * Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners on
+ * bgp events
*/
public interface BGPController {
@@ -40,6 +44,34 @@ public interface BGPController {
BGPPeer getPeer(BGPId bgpId);
/**
+ * Register a listener for BGP message events.
+ *
+ * @param listener the listener to notify
+ */
+ void addListener(BgpNodeListener listener);
+
+ /**
+ * Unregister a listener.
+ *
+ * @param listener the listener to unregister
+ */
+ void removeListener(BgpNodeListener listener);
+
+ /**
+ * Register a listener for BGP message events.
+ *
+ * @param listener the listener to notify
+ */
+ void addLinkListener(BgpLinkListener listener);
+
+ /**
+ * Unregister a listener.
+ *
+ * @param listener the listener to unregister
+ */
+ void removeLinkListener(BgpLinkListener listener);
+
+ /**
* Send a message to a particular bgp peer.
*
* @param bgpId the id of the peer to send message.
@@ -52,8 +84,9 @@ public interface BGPController {
*
* @param bgpId id of the peer the message arrived on
* @param msg the message to process.
+ * @throws BGPParseException on data processing error
*/
- void processBGPPacket(BGPId bgpId, BGPMessage msg);
+ void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException;
/**
* Close all connected BGP peers.
@@ -73,5 +106,33 @@ public interface BGPController {
*
* @return the integer number
*/
- int getBGPConnNumber();
-} \ No newline at end of file
+ int connectedPeerCount();
+
+ /**
+ * Return BGP peer manager.
+ *
+ * @return BGPPeerManager peer manager instance
+ */
+ BgpPeerManager peerManager();
+
+ /**
+ * Return BGP connected peers.
+ *
+ * @return connectedPeers connected peers
+ */
+ Map<BGPId, BGPPeer> connectedPeers();
+
+ /**
+ * Return BGP node listener.
+ *
+ * @return node listener
+ */
+ Set<BgpNodeListener> listener();
+
+ /**
+ * Return BGP link listener.
+ *
+ * @return link listener
+ */
+ Set<BgpLinkListener> linkListener();
+}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java
index 1b022c76..aafaf06e 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java
@@ -16,30 +16,16 @@
package org.onosproject.bgp.controller;
import java.util.List;
import org.jboss.netty.channel.Channel;
+import org.onosproject.bgpio.protocol.BGPFactory;
import org.onosproject.bgpio.protocol.BGPMessage;
-import org.onosproject.bgpio.protocol.BGPVersion;
/**
- * Represents the peer side of an bgp peer.
+ * Represents the peer side of an BGP peer.
*
*/
public interface BGPPeer {
/**
- * Sets the BGP version for this bgp peer.
- *
- * @param bgpVersion the version to set.
- */
- void setBgpPeerVersion(BGPVersion bgpVersion);
-
- /**
- * Gets the BGP version for this bgp peer.
- *
- * @return bgp identifier.
- */
- int getBgpPeerIdentifier();
-
- /**
* Sets the associated Netty channel for this bgp peer.
*
* @param channel the Netty channel
@@ -54,27 +40,6 @@ public interface BGPPeer {
Channel getChannel();
/**
- * Sets the AS Number for this bgp peer.
- *
- * @param peerASNum the autonomous system number value to set.
- */
- void setBgpPeerASNum(short peerASNum);
-
- /**
- * Sets the hold time for this bgp peer.
- *
- * @param peerHoldTime the hold timer value to set.
- */
- void setBgpPeerHoldTime(short peerHoldTime);
-
- /**
- * Sets the peer identifier value.
- *
- * @param peerIdentifier the bgp peer identifier value.
- */
- void setBgpPeerIdentifier(int peerIdentifier);
-
- /**
* Sets whether the bgp peer is connected.
*
* @param connected whether the bgp peer is connected
@@ -82,15 +47,6 @@ public interface BGPPeer {
void setConnected(boolean connected);
/**
- * Initialises the behaviour.
- *
- * @param bgpId id of bgp peer
- * @param bgpVersion BGP version
- * @param pktStats packet statistics
- */
- void init(BGPId bgpId, BGPVersion bgpVersion, BGPPacketStats pktStats);
-
- /**
* Checks whether the handshake is complete.
*
* @return true is finished, false if not.
@@ -112,18 +68,11 @@ public interface BGPPeer {
void sendMessage(List<BGPMessage> msgs);
/**
- * Gets a string version of the ID for this bgp peer.
+ * Provides the factory for BGP version.
*
- * @return string version of the ID
+ * @return BGP version specific factory.
*/
- String getStringId();
-
- /**
- * Gets the ipAddress of the peer.
- *
- * @return the peer bgpId in IPAddress format
- */
- BGPId getBGPId();
+ BGPFactory factory();
/**
* Checks if the bgp peer is still connected.
@@ -146,16 +95,9 @@ public interface BGPPeer {
String channelId();
/**
- * Gets the negotiated hold time.
- *
- * @return the negotiated hold time
- */
- int getNegotiatedHoldTime();
-
- /**
- * Sets negotiated hold time for the peer.
+ * Return the BGP session info.
*
- * @param negotiatedHoldTime negotiated hold time
+ * @return sessionInfo bgp session info
*/
- void setNegotiatedHoldTime(short negotiatedHoldTime);
+ BgpSessionInfo sessionInfo();
}
diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java
index 87ec031f..e7c5d9b4 100755
--- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java
+++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java
@@ -163,4 +163,18 @@ public interface BGPPeerCfg {
* AS number
*/
void setPeerRouterId(String peerId, int asNumber);
+
+ /**
+ * Set the peer connect instance.
+ *
+ * @param connectpeer connect peer instance
+ */
+ void setConnectPeer(BgpConnectPeer connectpeer);
+
+ /**
+ * Get the peer connect instance.
+ *
+ * @return peer connect instance
+ */
+ BgpConnectPeer connectPeer();
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
index 1445c763..dab7a3d2 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java
@@ -29,19 +29,19 @@ public interface BgpLinkLsNlri extends BGPLSNlri {
*
* @return local node descriptors
*/
- NodeDescriptors getLocalNodeDescriptors();
+ NodeDescriptors localNodeDescriptors();
/**
* Returns remote node descriptors.
*
* @return remote node descriptors
*/
- NodeDescriptors getRemoteNodeDescriptors();
+ NodeDescriptors remoteNodeDescriptors();
/**
* Returns link descriptors.
*
* @return link descriptors
*/
- List<BGPValueType> getLinkDescriptors();
+ List<BGPValueType> linkDescriptors();
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
index 90e94e88..e9df3999 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java
@@ -21,6 +21,7 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,8 +35,6 @@ public class As4Path implements BGPValueType {
private static final Logger log = LoggerFactory.getLogger(AsPath.class);
public static final byte AS4PATH_TYPE = 17;
public static final byte ASNUM_SIZE = 4;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private List<Integer> as4pathSet;
private List<Integer> as4pathSeq;
@@ -77,8 +76,8 @@ public class As4Path implements BGPValueType {
validation.getLength());
}
//if fourth bit is set length is read as short otherwise as byte , len includes type, length and value
- int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
index 100e14d7..e3eb2c51 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java
@@ -22,6 +22,7 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,7 +54,7 @@ public class AsPath implements BGPValueType {
*
* @return AS type
*/
- public byte getType() {
+ public byte type() {
return (byte) value;
}
}
@@ -63,8 +64,6 @@ public class AsPath implements BGPValueType {
public static final byte ASPATH_SET_TYPE = 1;
public static final byte ASPATH_SEQ_TYPE = 2;
public static final byte ASNUM_SIZE = 2;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private boolean isAsPath = false;
private List<Short> aspathSet;
@@ -108,8 +107,8 @@ public class AsPath implements BGPValueType {
validation.getLength());
}
//if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value
- int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java
index f643ae00..dfcfc9dc 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java
@@ -28,8 +28,8 @@ public final class BGPErrorType {
public static final byte OPEN_MESSAGE_ERROR = 2;
public static final byte UPDATE_MESSAGE_ERROR = 3;
public static final byte HOLD_TIMER_EXPIRED = 4;
- public static final byte FINITE_STATE_MACHINE_ERROR = 4;
- public static final byte CEASE = 5;
+ public static final byte FINITE_STATE_MACHINE_ERROR = 5;
+ public static final byte CEASE = 6;
//Message Header Error subcodes
public static final byte CONNECTION_NOT_SYNCHRONIZED = 1;
@@ -42,6 +42,7 @@ public final class BGPErrorType {
public static final byte BAD_BGP_IDENTIFIER = 3;
public static final byte UNSUPPORTED_OPTIONAL_PARAMETER = 4;
public static final byte UNACCEPTABLE_HOLD_TIME = 5;
+ public static final byte UNSUPPORTED_CAPABILITY = 7;
//UPDATE Message Error subcodes
public static final byte MALFORMED_ATTRIBUTE_LIST = 1;
@@ -54,4 +55,20 @@ public final class BGPErrorType {
public static final byte OPTIONAL_ATTRIBUTE_ERROR = 9;
public static final byte INVALID_NETWORK_FIELD = 10;
public static final byte MALFORMED_ASPATH = 11;
+
+ //FSM Error subcodes
+ public static final byte UNSPECIFIED_ERROR = 0;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE = 1;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE = 2;
+ public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_ESTABLISHED_STATE = 3;
+
+ //Cease Error subcodes
+ public static final byte MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1;
+ public static final byte ADMINISTRATIVE_SHUTDOWN = 2;
+ public static final byte PEER_DECONFIGURED = 3;
+ public static final byte ADMINISTRATIVE_RESET = 4;
+ public static final byte CONNECTION_REJECTED = 5;
+ public static final byte OTHER_CONFIGURATION_CHANGE = 6;
+ public static final byte CONNECTION_COLLISION_RESOLUTION = 7;
+ public static final byte OUT_OF_RESOURCES = 8;
} \ No newline at end of file
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
index 85fb748b..59afbed6 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.bgpio.types;
+import java.util.Arrays;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -86,7 +87,7 @@ public class IPReachabilityInformationTlv implements BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(ipPrefix, prefixLen);
+ return Objects.hash(Arrays.hashCode(ipPrefix), prefixLen);
}
@Override
@@ -97,7 +98,7 @@ public class IPReachabilityInformationTlv implements BGPValueType {
if (obj instanceof IPReachabilityInformationTlv) {
IPReachabilityInformationTlv other = (IPReachabilityInformationTlv) obj;
- return Objects.equals(prefixLen, other.prefixLen) && Objects.equals(ipPrefix, other.ipPrefix);
+ return Objects.equals(prefixLen, other.prefixLen) && Arrays.equals(ipPrefix, other.ipPrefix);
}
return false;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
index 5c742d0f..35fd2493 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java
@@ -15,6 +15,9 @@
*/
package org.onosproject.bgpio.types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -28,12 +31,12 @@ import com.google.common.base.MoreObjects;
* Provides implementation of IsIsPseudonode Tlv.
*/
public class IsIsPseudonode implements IGPRouterID, BGPValueType {
- protected static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class);
+ private static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class);
public static final short TYPE = 515;
public static final short LENGTH = 7;
- private final byte[] isoNodeID;
+ private final List<Byte> isoNodeID;
private byte psnIdentifier;
/**
@@ -42,7 +45,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @param isoNodeID ISO system-ID
* @param psnIdentifier PSN identifier
*/
- public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) {
+ public IsIsPseudonode(List<Byte> isoNodeID, byte psnIdentifier) {
this.isoNodeID = isoNodeID;
this.psnIdentifier = psnIdentifier;
}
@@ -54,7 +57,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @param psnIdentifier PSN identifier
* @return object of IsIsPseudonode
*/
- public static IsIsPseudonode of(final byte[] isoNodeID, final byte psnIdentifier) {
+ public static IsIsPseudonode of(final List<Byte> isoNodeID,
+ final byte psnIdentifier) {
return new IsIsPseudonode(isoNodeID, psnIdentifier);
}
@@ -63,7 +67,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
*
* @return ISO NodeID
*/
- public byte[] getISONodeID() {
+ public List<Byte> getISONodeID() {
return isoNodeID;
}
@@ -78,7 +82,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(isoNodeID, psnIdentifier);
+ return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier);
}
@Override
@@ -87,8 +91,27 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
return true;
}
if (obj instanceof IsIsPseudonode) {
+ int countObjSubTlv = 0;
+ int countOtherSubTlv = 0;
+ boolean isCommonSubTlv = true;
IsIsPseudonode other = (IsIsPseudonode) obj;
- return Objects.equals(isoNodeID, other.isoNodeID) && Objects.equals(psnIdentifier, other.psnIdentifier);
+ Iterator<Byte> objListIterator = other.isoNodeID.iterator();
+ countOtherSubTlv = other.isoNodeID.size();
+ countObjSubTlv = isoNodeID.size();
+ if (countObjSubTlv != countOtherSubTlv) {
+ return false;
+ } else {
+ while (objListIterator.hasNext() && isCommonSubTlv) {
+ Byte subTlv = objListIterator.next();
+ if (isoNodeID.contains(subTlv) && other.isoNodeID.contains(subTlv)) {
+ isCommonSubTlv = Objects.equals(isoNodeID.get(isoNodeID.indexOf(subTlv)),
+ other.isoNodeID.get(other.isoNodeID.indexOf(subTlv)));
+ } else {
+ isCommonSubTlv = false;
+ }
+ }
+ return isCommonSubTlv && Objects.equals(psnIdentifier, other.psnIdentifier);
+ }
}
return false;
}
@@ -98,7 +121,11 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
int iLenStartIndex = c.writerIndex();
c.writeShort(TYPE);
c.writeShort(LENGTH);
- c.writeBytes(isoNodeID);
+ Iterator<Byte> objListIterator = isoNodeID.iterator();
+ while (objListIterator.hasNext()) {
+ byte value = objListIterator.next();
+ c.writeByte(value);
+ }
c.writeByte(psnIdentifier);
return c.writerIndex() - iLenStartIndex;
}
@@ -110,8 +137,12 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType {
* @return object of IsIsPseudonode
*/
public static IsIsPseudonode read(ChannelBuffer cb) {
- byte[] isoNodeID = new byte[LENGTH - 1];
- cb.readBytes(isoNodeID, 0, LENGTH - 1);
+ List<Byte> isoNodeID = new ArrayList<Byte>();
+ byte value;
+ for (int i = 0; i < LENGTH; i++) {
+ value = cb.readByte();
+ isoNodeID.add(value);
+ }
byte psnIdentifier = cb.readByte();
return IsIsPseudonode.of(isoNodeID, psnIdentifier);
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
index 048d81ee..0f78ab77 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java
@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
@@ -29,11 +28,7 @@ import com.google.common.base.MoreObjects;
* Provides implementation of LocalPref BGP Path Attribute.
*/
public class LocalPref implements BGPValueType {
-
- private static final Logger log = LoggerFactory.getLogger(LocalPref.class);
public static final byte LOCAL_PREF_TYPE = 5;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
public static final byte LOCAL_PREF_MAX_LEN = 4;
private int localPref;
@@ -72,8 +67,8 @@ public class LocalPref implements BGPValueType {
parseFlags.getLength());
}
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags.getLength()
- + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() +
+ Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
index 49e1fc5a..23402c26 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java
@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
@@ -29,10 +28,7 @@ import com.google.common.base.MoreObjects;
* Provides Implementation of Med BGP Path Attribute.
*/
public class Med implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(Med.class);
public static final byte MED_TYPE = 4;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
public static final byte MED_MAX_LEN = 4;
private int med;
@@ -71,8 +67,8 @@ public class Med implements BGPValueType {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
index 90a1cc6b..fe99d28d 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java
@@ -26,6 +26,7 @@ import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.protocol.BGPLSNlri;
import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4;
import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
@@ -39,7 +40,6 @@ import com.google.common.base.MoreObjects;
public class MpReachNlri implements BGPValueType {
private static final Logger log = LoggerFactory.getLogger(MpReachNlri.class);
-
public static final byte MPREACHNLRI_TYPE = 14;
public static final byte LINK_NLRITYPE = 2;
@@ -131,8 +131,7 @@ public class MpReachNlri implements BGPValueType {
if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE)
&& (safi == Constants.VPN_SAFI_VALUE)) {
byte nextHopLen = tempCb.readByte();
- //TODO: use Validation.toInetAddress once Validation is merged
- InetAddress ipAddress = (InetAddress) cb.readBytes(nextHopLen);
+ InetAddress ipAddress = Validation.toInetAddress(nextHopLen, cb);
if (ipAddress.isMulticastAddress()) {
throw new BGPParseException("Multicast not supported");
}
@@ -151,8 +150,8 @@ public class MpReachNlri implements BGPValueType {
case BGPNodeLSNlriVer4.NODE_NLRITYPE:
bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi);
break;
- case LINK_NLRITYPE:
- //TODO: To be merged later
+ case BgpLinkLsNlriVer4.LINK_NLRITYPE:
+ bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
break;
case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi);
@@ -163,7 +162,6 @@ public class MpReachNlri implements BGPValueType {
mpReachNlri.add(bgpLSNlri);
}
} else {
- //TODO: check with the values got from capability
throw new BGPParseException("Not Supporting afi " + afi + "safi " + safi);
}
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
index 3efed95c..8763ec59 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java
@@ -24,6 +24,7 @@ import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.protocol.BGPLSNlri;
import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4;
+import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
import org.slf4j.Logger;
@@ -36,10 +37,10 @@ import com.google.common.base.MoreObjects;
*/
public class MpUnReachNlri implements BGPValueType {
- protected static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class);
-
+ private static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class);
public static final byte MPUNREACHNLRI_TYPE = 15;
public static final byte LINK_NLRITYPE = 2;
+
private boolean isMpUnReachNlri = false;
private final short afi;
private final byte safi;
@@ -113,8 +114,8 @@ public class MpUnReachNlri implements BGPValueType {
case BGPNodeLSNlriVer4.NODE_NLRITYPE:
bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi);
break;
- case LINK_NLRITYPE:
- //TODO: to be merged later
+ case BgpLinkLsNlriVer4.LINK_NLRITYPE:
+ bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi);
break;
case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE:
bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi,
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
index 353ec3d5..1d083b72 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java
@@ -21,9 +21,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onlab.packet.Ip4Address;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
@@ -32,10 +31,7 @@ import com.google.common.base.Preconditions;
* Implementation of NextHop BGP Path Attribute.
*/
public class NextHop implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(NextHop.class);
public static final byte NEXTHOP_TYPE = 3;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private boolean isNextHop = false;
private Ip4Address nextHop;
@@ -75,15 +71,14 @@ public class NextHop implements BGPValueType {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
parseFlags.getLength());
}
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data);
}
- //TODO: use Validation.toInetAddress once Validation is merged
- InetAddress ipAddress = (InetAddress) cb.readBytes(parseFlags.getLength());
+ InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
if (ipAddress.isMulticastAddress()) {
throw new BGPParseException("Multicast address is not supported");
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
index 3b2070de..2052e965 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java
@@ -19,9 +19,8 @@ import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.util.Constants;
import org.onosproject.bgpio.util.Validation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import com.google.common.base.MoreObjects;
@@ -29,7 +28,6 @@ import com.google.common.base.MoreObjects;
* Provides Implementation of mandatory BGP Origin path attribute.
*/
public class Origin implements BGPValueType {
- private static final Logger log = LoggerFactory.getLogger(Origin.class);
/**
* Enum to provide ORIGIN types.
@@ -58,8 +56,6 @@ public class Origin implements BGPValueType {
public static final byte ORIGIN_TYPE = 1;
public static final byte ORIGIN_VALUE_LEN = 1;
- public static final int TYPE_AND_LEN_AS_SHORT = 4;
- public static final int TYPE_AND_LEN_AS_BYTE = 3;
private boolean isOrigin = false;
private byte origin;
@@ -109,8 +105,8 @@ public class Origin implements BGPValueType {
ChannelBuffer tempCb = cb.copy();
Validation parseFlags = Validation.parseAttributeHeader(cb);
- int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags
- .getLength() + TYPE_AND_LEN_AS_BYTE;
+ int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags
+ .getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
ChannelBuffer data = tempCb.readBytes(len);
if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
@@ -122,7 +118,7 @@ public class Origin implements BGPValueType {
byte originValue;
originValue = cb.readByte();
- if ((originValue != ORIGINTYPE.INCOMPLETE.value) || (originValue != ORIGINTYPE.IGP.value) ||
+ if ((originValue != ORIGINTYPE.INCOMPLETE.value) && (originValue != ORIGINTYPE.IGP.value) &&
(originValue != ORIGINTYPE.EGP.value)) {
throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.INVALID_ORIGIN_ATTRIBUTE, data);
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
index 194d6dac..4b704fb0 100644
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java
@@ -13,9 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.onosproject.bgpio.types.attr;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -39,18 +40,28 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
public static final int ATTRNODE_MULTITOPOLOGY = 263;
/* Opaque Node Attribute */
- private short[] multiTopologyId;
+ private List<Short> multiTopologyId = new ArrayList<Short>();
/**
* Constructor to initialize the Node attribute multi-topology ID.
*
* @param multiTopologyId multi-topology ID
*/
- BgpAttrNodeMultiTopologyId(short[] multiTopologyId) {
+ public BgpAttrNodeMultiTopologyId(List<Short> multiTopologyId) {
this.multiTopologyId = multiTopologyId;
}
/**
+ * Returns object of this class with specified values.
+ *
+ * @param multiTopologyId Prefix Metric
+ * @return object of BgpAttrNodeMultiTopologyId
+ */
+ public static BgpAttrNodeMultiTopologyId of(ArrayList<Short> multiTopologyId) {
+ return new BgpAttrNodeMultiTopologyId(multiTopologyId);
+ }
+
+ /**
* Reads the Multi-topology ID of Node attribute.
*
* @param cb ChannelBuffer
@@ -59,21 +70,20 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
*/
public static BgpAttrNodeMultiTopologyId read(ChannelBuffer cb)
throws BGPParseException {
-
- log.debug("BgpAttrNodeMultiTopologyId");
+ ArrayList<Short> multiTopologyId = new ArrayList<Short>();
+ short tempMultiTopologyId;
short lsAttrLength = cb.readShort();
int len = lsAttrLength / 2; // Length is 2*n and n is the number of MT-IDs
if (cb.readableBytes() < lsAttrLength) {
Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR,
BGPErrorType.ATTRIBUTE_LENGTH_ERROR,
- cb.readableBytes());
+ lsAttrLength);
}
- short[] multiTopologyId;
- multiTopologyId = new short[len];
for (int i = 0; i < len; i++) {
- multiTopologyId[i] = cb.readShort();
+ tempMultiTopologyId = cb.readShort();
+ multiTopologyId.add(new Short(tempMultiTopologyId));
}
return new BgpAttrNodeMultiTopologyId(multiTopologyId);
@@ -84,7 +94,7 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
*
* @return multitopology ID
*/
- short[] getAttrMultiTopologyId() {
+ public List<Short> attrMultiTopologyId() {
return multiTopologyId;
}
@@ -113,7 +123,7 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType {
@Override
public int write(ChannelBuffer cb) {
- // TODO Auto-generated method stub
+ // TODO This will be implemented in the next version
return 0;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
index 50591ecf..e44ba7e1 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java
@@ -16,7 +16,6 @@
package org.onosproject.bgpio.types.attr;
import java.util.Arrays;
-import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BGPParseException;
@@ -46,11 +45,21 @@ public class BgpLinkAttrName implements BGPValueType {
*
* @param linkName link name
*/
- BgpLinkAttrName(byte[] linkName) {
+ public BgpLinkAttrName(byte[] linkName) {
this.linkName = Arrays.copyOf(linkName, linkName.length);
}
/**
+ * Returns object of this class with specified values.
+ *
+ * @param linkName Prefix Metric
+ * @return object of BgpLinkAttrName
+ */
+ public static BgpLinkAttrName of(byte[] linkName) {
+ return new BgpLinkAttrName(linkName);
+ }
+
+ /**
* Reads the BGP link attributes Name.
*
* @param cb Channel buffer
@@ -70,7 +79,7 @@ public class BgpLinkAttrName implements BGPValueType {
linkName = new byte[lsAttrLength];
cb.readBytes(linkName);
- return new BgpLinkAttrName(linkName);
+ return BgpLinkAttrName.of(linkName);
}
/**
@@ -78,7 +87,7 @@ public class BgpLinkAttrName implements BGPValueType {
*
* @return link name
*/
- byte[] getAttrLinkName() {
+ public byte[] attrLinkName() {
return linkName;
}
@@ -89,7 +98,7 @@ public class BgpLinkAttrName implements BGPValueType {
@Override
public int hashCode() {
- return Objects.hash(linkName);
+ return Arrays.hashCode(linkName);
}
@Override
@@ -100,7 +109,7 @@ public class BgpLinkAttrName implements BGPValueType {
if (obj instanceof BgpLinkAttrName) {
BgpLinkAttrName other = (BgpLinkAttrName) obj;
- return Objects.equals(linkName, other.linkName);
+ return Arrays.equals(linkName, other.linkName);
}
return false;
}
diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
index 0cf02386..426eb274 100755
--- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
+++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java
@@ -15,7 +15,8 @@
*/
package org.onosproject.bgpio.types.attr;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Objects;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -36,18 +37,28 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
protected static final Logger log = LoggerFactory
.getLogger(BgpPrefixAttrRouteTag.class);
- public static final int ATTR_PREFIX_ROUTETAG = 1153;
+ public static final short ATTR_PREFIX_ROUTETAG = 1153;
/* Prefix Route Tag */
- private int[] pfxRouteTag;
+ private List<Integer> pfxRouteTag = new ArrayList<Integer>();
/**
* Constructor to initialize the values.
*
* @param pfxRouteTag prefix route tag
*/
- BgpPrefixAttrRouteTag(int[] pfxRouteTag) {
- this.pfxRouteTag = Arrays.copyOf(pfxRouteTag, pfxRouteTag.length);
+ public BgpPrefixAttrRouteTag(List<Integer> pfxRouteTag) {
+ this.pfxRouteTag = pfxRouteTag;
+ }
+
+ /**
+ * Returns object of this class with specified values.
+ *
+ * @param pfxRouteTag Prefix Metric
+ * @return object of BgpPrefixAttrRouteTag
+ */
+ public static BgpPrefixAttrRouteTag of(ArrayList<Integer> pfxRouteTag) {
+ return new BgpPrefixAttrRouteTag(pfxRouteTag);
}
/**
@@ -59,7 +70,8 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
*/
public static BgpPrefixAttrRouteTag read(ChannelBuffer cb)
throws BGPParseException {
- int[] pfxRouteTag;
+ int tmp;
+ ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>();
short lsAttrLength = cb.readShort();
int len = lsAttrLength / Integer.SIZE;
@@ -70,13 +82,12 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
lsAttrLength);
}
- pfxRouteTag = new int[lsAttrLength];
-
for (int i = 0; i < len; i++) {
- pfxRouteTag[i] = cb.readInt();
+ tmp = cb.readInt();
+ pfxRouteTag.add(new Integer(tmp));
}
- return new BgpPrefixAttrRouteTag(pfxRouteTag);
+ return BgpPrefixAttrRouteTag.of(pfxRouteTag);
}
/**
@@ -84,7 +95,7 @@ public class BgpPrefixAttrRouteTag implements BGPValueType {
*
* @return route tag
*/
- int[] getPfxRouteTag() {
+ public List<Integer> getPfxRouteTag() {
return pfxRouteTag;
}
diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
index a2a7c2b5..00e85dcf 100644
--- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
+++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java
@@ -15,6 +15,11 @@
*/
package org.onosproject.bgpio.types;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
@@ -24,13 +29,28 @@ import com.google.common.testing.EqualsTester;
*/
public class IsIsPseudonodeTest {
private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02};
+ byte value;
+ List<Byte> isoNodeID1 = new ArrayList<Byte>();
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03};
- private final IsIsPseudonode tlv1 = IsIsPseudonode.of(value1, (byte) 1);
- private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(value1, (byte) 1);
- private final IsIsPseudonode tlv2 = IsIsPseudonode.of(value2, (byte) 1);
+ List<Byte> isoNodeID2 = new ArrayList<Byte>();
+ ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer();
+ private final IsIsPseudonode tlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1);
+ private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1);
+ private final IsIsPseudonode tlv2 = IsIsPseudonode.of(isoNodeID2, (byte) 1);
@Test
public void testEquality() {
+ buffer.writeBytes(value1);
+ for (int i = 0; i < 6; i++) {
+ value = buffer.readByte();
+ isoNodeID1.add(value);
+ }
+ buffer1.writeBytes(value2);
+ for (int i = 0; i < 6; i++) {
+ value = buffer1.readByte();
+ isoNodeID1.add(value);
+ }
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java
index c17736ed..f21c311c 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java
@@ -17,13 +17,19 @@
package org.onosproject.bgp.controller.impl;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
+import java.net.UnknownHostException;
import java.nio.channels.ClosedChannelException;
-import java.util.Date;
+import java.util.Collections;
import java.util.List;
+import java.util.LinkedList;
+import java.util.ListIterator;
import java.util.concurrent.RejectedExecutionException;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
@@ -32,17 +38,24 @@ import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler;
import org.jboss.netty.handler.timeout.ReadTimeoutException;
import org.jboss.netty.handler.timeout.ReadTimeoutHandler;
+import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onosproject.bgp.controller.BGPCfg;
+import org.onosproject.bgp.controller.BGPController;
import org.onosproject.bgp.controller.BGPId;
import org.onosproject.bgp.controller.BGPPeer;
import org.onosproject.bgp.controller.BGPPeerCfg;
-import org.onosproject.bgp.controller.impl.BGPControllerImpl.BGPPeerManager;
+import org.onosproject.bgp.controller.impl.BGPControllerImpl.BGPPeerManagerImpl;
import org.onosproject.bgpio.exceptions.BGPParseException;
+import org.onosproject.bgpio.protocol.BGPFactory;
import org.onosproject.bgpio.protocol.BGPMessage;
-//import org.onosproject.bgpio.protocol.BGPOpenMsg;
+import org.onosproject.bgpio.protocol.BGPOpenMsg;
import org.onosproject.bgpio.protocol.BGPType;
import org.onosproject.bgpio.protocol.BGPVersion;
+import org.onosproject.bgpio.types.BGPErrorType;
+import org.onosproject.bgpio.types.BGPValueType;
+import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv;
+import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,18 +65,25 @@ import org.slf4j.LoggerFactory;
class BGPChannelHandler extends IdleStateAwareChannelHandler {
private static final Logger log = LoggerFactory.getLogger(BGPChannelHandler.class);
-
+ static final int BGP_MIN_HOLDTIME = 3;
static final int BGP_MAX_KEEPALIVE_INTERVAL = 3;
private BGPPeer bgpPeer;
private BGPId thisbgpId;
- Channel channel;
+ private Channel channel;
private BGPKeepAliveTimer keepAliveTimer = null;
private short peerHoldTime = 0;
private short negotiatedHoldTime = 0;
- private short peerAsNum;
+ private long peerAsNum;
private int peerIdentifier;
private BGPPacketStatsImpl bgpPacketStats;
static final int MAX_WRONG_COUNT_PACKET = 5;
+ static final byte MULTI_PROTOCOL_EXTN_CAPA_TYPE = 1;
+ static final byte FOUR_OCTET_AS_NUM_CAPA_TYPE = 65;
+ static final int AS_TRANS = 23456;
+ static final int MAX_AS2_NUM = 65535;
+ static final short AFI = 16388;
+ static final byte RES = 0;
+ static final byte SAFI = 71;
// State needs to be volatile because the HandshakeTimeoutHandler
// needs to check if the handshake is complete
@@ -72,13 +92,17 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
// When a bgp peer with a ip addresss is found (i.e we already have a
// connected peer with the same ip), the new peer is immediately
// disconnected. At that point netty callsback channelDisconnected() which
- // proceeds to cleaup peer state - we need to ensure that it does not cleanup
+ // proceeds to cleaup peer state - we need to ensure that it does not
+ // cleanup
// peer state for the older (still connected) peer
private volatile Boolean duplicateBGPIdFound;
// Indicates the bgp version used by this bgp peer
protected BGPVersion bgpVersion;
- private BGPControllerImpl bgpControllerImpl;
- private BGPPeerManager peerManager;
+ private BGPController bgpController;
+ protected BGPFactory factory4;
+ private boolean isIbgpSession;
+ private BgpSessionInfoImpl sessionInfo;
+ private BGPPeerManagerImpl peerManager;
private InetSocketAddress inetAddress;
private IpAddress ipAddress;
private SocketAddress address;
@@ -88,15 +112,16 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
/**
* Create a new unconnected BGPChannelHandler.
*
- * @param bgpCtrlImpl bgp controller implementation object
+ * @param bgpController bgp controller
*/
- BGPChannelHandler(BGPControllerImpl bgpCtrlImpl) {
- this.bgpControllerImpl = bgpCtrlImpl;
- this.peerManager = bgpCtrlImpl.getPeerManager();
+ BGPChannelHandler(BGPController bgpController) {
+ this.bgpController = bgpController;
+ this.peerManager = (BGPPeerManagerImpl) bgpController.peerManager();
this.state = ChannelState.IDLE;
+ this.factory4 = Controller.getBGPMessageFactory4();
this.duplicateBGPIdFound = Boolean.FALSE;
this.bgpPacketStats = new BGPPacketStatsImpl();
- this.bgpconfig = bgpCtrlImpl.getConfig();
+ this.bgpconfig = bgpController.getConfig();
}
// To disconnect peer session.
@@ -127,17 +152,19 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
// check for OPEN message
if (m.getType() != BGPType.OPEN) {
// When the message type is not keep alive message increment the wrong packet statistics
- h.processUnknownMsg();
+ h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR,
+ BGPErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE, m.getType()
+ .getType());
log.debug("Message is not OPEN message");
} else {
log.debug("Sending keep alive message in OPENSENT state");
h.bgpPacketStats.addInPacket();
- // TODO: initialize openmessage BGPOpenMsg pOpenmsg = (BGPOpenMsg) m;
- // TODO: initialize identifier from open messgae h.peerIdentifier = pOpenmsg.getBgpId();
+ BGPOpenMsg pOpenmsg = (BGPOpenMsg) m;
+ h.peerIdentifier = pOpenmsg.getBgpId();
// validate capabilities and open msg
- if (h.openMsgValidation(h)) {
+ if (h.openMsgValidation(h, pOpenmsg)) {
log.debug("Sending handshake OPEN message");
/*
@@ -145,7 +172,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time
* received in the OPEN message
*/
- // TODO: initialize holdtime from open message h.peerHoldTime = pOpenmsg.getHoldTime();
+ h.peerHoldTime = pOpenmsg.getHoldTime();
if (h.peerHoldTime < h.bgpconfig.getHoldTime()) {
h.channel.getPipeline().replace("holdTime",
"holdTime",
@@ -155,7 +182,8 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
log.info("Hold Time : " + h.peerHoldTime);
- // TODO: get AS number for open message update AS number
+ // update AS number
+ h.peerAsNum = pOpenmsg.getAsNumber();
}
// Send keepalive message to peer.
@@ -175,15 +203,17 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
// check for open message
if (m.getType() != BGPType.OPEN) {
// When the message type is not open message increment the wrong packet statistics
- h.processUnknownMsg();
+ h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR, BGPErrorType.UNSPECIFIED_ERROR, m
+ .getType().getType());
log.debug("Message is not OPEN message");
} else {
h.bgpPacketStats.addInPacket();
- // TODO: initialize open message BGPOpenMsg pOpenmsg = (BGPOpenMsg) m;
+ BGPOpenMsg pOpenmsg = (BGPOpenMsg) m;
+ h.peerIdentifier = pOpenmsg.getBgpId();
// Validate open message
- if (h.openMsgValidation(h)) {
+ if (h.openMsgValidation(h, pOpenmsg)) {
log.debug("Sending handshake OPEN message");
/*
@@ -191,7 +221,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
* value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time
* received in the OPEN message
*/
- // TODO: get hold time from open message h.peerHoldTime = pOpenmsg.getHoldTime();
+ h.peerHoldTime = pOpenmsg.getHoldTime();
if (h.peerHoldTime < h.bgpconfig.getHoldTime()) {
h.channel.getPipeline().replace("holdTime",
"holdTime",
@@ -201,7 +231,8 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
log.debug("Hold Time : " + h.peerHoldTime);
- //TODO: update AS number form open messsage update AS number
+ // update AS number
+ h.peerAsNum = pOpenmsg.getAsNumber();
h.sendHandshakeOpenMessage();
h.bgpPacketStats.addOutPacket();
@@ -218,7 +249,9 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
// check for keep alive message
if (m.getType() != BGPType.KEEP_ALIVE) {
// When the message type is not keep alive message handle the wrong packet
- h.processUnknownMsg();
+ h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR,
+ BGPErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE, m.getType()
+ .getType());
log.debug("Message is not KEEPALIVE message");
} else {
@@ -229,30 +262,28 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
final InetSocketAddress inetAddress = (InetSocketAddress) h.address;
h.thisbgpId = BGPId.bgpId(IpAddress.valueOf(inetAddress.getAddress()));
- h.bgpPeer = h.peerManager.getBGPPeerInstance(h.thisbgpId, h.bgpVersion, h.bgpPacketStats);
- // set the status fo bgp as connected
+ // set session parameters
+ h.negotiatedHoldTime = (h.peerHoldTime < h.bgpconfig.getHoldTime()) ? h.peerHoldTime
+ : h.bgpconfig.getHoldTime();
+ h.sessionInfo = new BgpSessionInfoImpl(h.thisbgpId, h.bgpVersion, h.peerAsNum, h.peerHoldTime,
+ h.peerIdentifier, h.negotiatedHoldTime, h.isIbgpSession);
+
+ h.bgpPeer = h.peerManager.getBGPPeerInstance(h.bgpController, h.sessionInfo, h.bgpPacketStats);
+ // set the status of bgp as connected
h.bgpPeer.setConnected(true);
h.bgpPeer.setChannel(h.channel);
- // set specific parameters to bgp peer
- h.bgpPeer.setBgpPeerVersion(h.bgpVersion);
- h.bgpPeer.setBgpPeerASNum(h.peerAsNum);
- h.bgpPeer.setBgpPeerHoldTime(h.peerHoldTime);
- h.bgpPeer.setBgpPeerIdentifier(h.peerIdentifier);
-
- h.negotiatedHoldTime = (h.peerHoldTime < h.bgpconfig.getHoldTime()) ? h.peerHoldTime : h.bgpconfig
- .getHoldTime();
- h.bgpPeer.setNegotiatedHoldTime(h.negotiatedHoldTime);
/*
* RFC 4271, When an OPEN message is received, sends a KEEPALIVE message, If the negotiated hold
* time value is zero, then the HoldTimer and KeepaliveTimer are not started. A reasonable maximum
* time between KEEPALIVE messages would be one third of the Hold Time interval.
*/
- h.sendKeepAliveMessage();
if (h.negotiatedHoldTime != 0) {
- h.keepAliveTimer
- = new BGPKeepAliveTimer(h, (h.negotiatedHoldTime / BGP_MAX_KEEPALIVE_INTERVAL));
+ h.keepAliveTimer = new BGPKeepAliveTimer(h,
+ (h.negotiatedHoldTime / BGP_MAX_KEEPALIVE_INTERVAL));
+ } else {
+ h.sendKeepAliveMessage();
}
h.bgpPacketStats.addOutPacket();
@@ -349,8 +380,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
}
inetAddress = (InetSocketAddress) address;
- ipAddress = IpAddress.valueOf(inetAddress.getAddress());
- peerAddr = ipAddress.toString();
+ peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString();
// if peer is not configured disconnect session
if (!bgpconfig.isPeerConfigured(peerAddr)) {
@@ -360,7 +390,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
}
// if connection is already established close channel
- if (peerManager.isPeerConnected(peerAddr)) {
+ if (peerManager.isPeerConnected(BGPId.bgpId(IpAddress.valueOf(peerAddr)))) {
log.debug("Duplicate connection received, peer {}", peerAddr);
channel.close();
return;
@@ -392,8 +422,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
}
inetAddress = (InetSocketAddress) address;
- ipAddress = IpAddress.valueOf(inetAddress.getAddress());
- peerAddr = ipAddress.toString();
+ peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString();
if (thisbgpId != null) {
if (!duplicateBGPIdFound) {
@@ -432,14 +461,14 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
if ((ChannelState.OPENWAIT == state) || (ChannelState.OPENSENT == state)) {
// When ReadTimeout timer is expired in OPENWAIT/OPENSENT state, it is considered
- // TODO: Send notification
+ sendNotification(BGPErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null);
channel.close();
state = ChannelState.IDLE;
return;
} else if (ChannelState.OPENCONFIRM == state) {
// When ReadTimeout timer is expired in OPENCONFIRM state.
- // TODO: Send Notification
+ sendNotification(BGPErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null);
channel.close();
state = ChannelState.IDLE;
return;
@@ -454,8 +483,17 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
}
channel.close();
} else if (e.getCause() instanceof BGPParseException) {
- // TODO: SEND NOTIFICATION
- log.debug("BGP Parse Exception: ", e.getCause());
+ byte[] data = new byte[] {};
+ BGPParseException errMsg = (BGPParseException) e.getCause();
+ byte errorCode = errMsg.getErrorCode();
+ byte errorSubCode = errMsg.getErrorSubCode();
+ ChannelBuffer tempCb = errMsg.getData();
+ if (tempCb != null) {
+ int dataLength = tempCb.capacity();
+ data = new byte[dataLength];
+ tempCb.readBytes(data, 0, dataLength);
+ }
+ sendNotification(errorCode, errorSubCode, data);
} else if (e.getCause() instanceof RejectedExecutionException) {
log.warn("Could not process message: queue full");
} else {
@@ -507,11 +545,12 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
/**
* To handle the BGP message.
*
- * @param m BGP message
+ * @param m bgp message
+ * @throws BGPParseException throw exception
*/
private void dispatchMessage(BGPMessage m) throws BGPParseException {
bgpPacketStats.addInPacket();
- bgpControllerImpl.processBGPPacket(thisbgpId, m);
+ bgpController.processBGPPacket(thisbgpId, m);
}
/**
@@ -557,14 +596,39 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
/**
* Send handshake open message to the peer.
*
- * @throws IOException ,BGPParseException
+ * @throws IOException, BGPParseException
*/
private void sendHandshakeOpenMessage() throws IOException, BGPParseException {
- // TODO: send open message.
+ int bgpId;
+
+ bgpId = Ip4Address.valueOf(bgpconfig.getRouterId()).toInt();
+ BGPMessage msg = factory4.openMessageBuilder().setAsNumber((short) bgpconfig.getAsNumber())
+ .setHoldTime(bgpconfig.getHoldTime()).setBgpId(bgpId)
+ .setLsCapabilityTlv(bgpconfig.getLsCapability())
+ .setLargeAsCapabilityTlv(bgpconfig.getLargeASCapability())
+ .build();
+ log.debug("Sending open message to {}", channel.getRemoteAddress());
+ channel.write(Collections.singletonList(msg));
}
/**
+ * Send notification message to peer.
+ *
+ * @param errorCode error code send in notification
+ * @param errorSubCode sub error code send in notification
+ * @param data data to send in notification
+ * @throws IOException, BGPParseException while building message
+ */
+ private void sendNotification(byte errorCode, byte errorSubCode, byte[] data)
+ throws IOException, BGPParseException {
+ BGPMessage msg = factory4.notificationMessageBuilder().setErrorCode(errorCode).setErrorSubCode(errorSubCode)
+ .setData(data).build();
+ log.debug("Sending notification message to {}", channel.getRemoteAddress());
+ channel.write(Collections.singletonList(msg));
+ }
+
+ /**
* Send keep alive message.
*
* @throws IOException when channel is disconnected
@@ -572,60 +636,220 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler {
*/
synchronized void sendKeepAliveMessage() throws IOException, BGPParseException {
- // TODO: send keep alive message.
+ BGPMessage msg = factory4.keepaliveMessageBuilder().build();
+ log.debug("Sending keepalive message to {}", channel.getRemoteAddress());
+ channel.write(Collections.singletonList(msg));
}
/**
- * Send notification and close channel with peer.
+ * Process unknown BGP message received.
+ *
+ * @param errorCode error code
+ * @param errorSubCode error sub code
+ * @param data message type
+ * @throws BGPParseException while processing error messsage
+ * @throws IOException while processing error message
*/
- private void sendErrNotificationAndCloseChannel() {
- // TODO: send notification
+ public void processUnknownMsg(byte errorCode, byte errorSubCode, byte data) throws BGPParseException, IOException {
+ log.debug("UNKNOWN message received");
+ byte[] byteArray = new byte[1];
+ byteArray[0] = data;
+ sendNotification(errorCode, errorSubCode, byteArray);
channel.close();
}
/**
- * Process unknown BGP message received.
+ * BGP open message validation.
*
- * @throws BGPParseException when received invalid message
+ * @param h channel handler
+ * @param openMsg open message
+ * @return true if valid message, otherwise false
+ * @throws BGPParseException throw exception
*/
- public void processUnknownMsg() throws BGPParseException {
- log.debug("UNKNOWN message received");
- Date now = null;
- if (bgpPacketStats.wrongPacketCount() == 0) {
- now = new Date();
- bgpPacketStats.setTime(now.getTime());
- bgpPacketStats.addWrongPacket();
- sendErrNotificationAndCloseChannel();
+ public boolean openMsgValidation(BGPChannelHandler h, BGPOpenMsg openMsg) throws BGPParseException {
+ boolean result;
+
+ // Validate BGP ID
+ result = bgpIdValidation(openMsg);
+ if (!result) {
+ throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_BGP_IDENTIFIER, null);
+ }
+
+ // Validate AS number
+ result = asNumberValidation(h, openMsg);
+ if (!result) {
+ throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null);
+ }
+
+ // Validate hold timer
+ if ((openMsg.getHoldTime() != 0) && (openMsg.getHoldTime() < BGP_MIN_HOLDTIME)) {
+ throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.UNACCEPTABLE_HOLD_TIME, null);
+ }
+
+ // Validate capabilities
+ result = capabilityValidation(h, openMsg);
+ return result;
+ }
+
+ /**
+ * Capability Validation.
+ *
+ * @param h channel handler
+ * @param openmsg open message
+ * @return success or failure
+ * @throws BGPParseException
+ */
+ private boolean capabilityValidation(BGPChannelHandler h, BGPOpenMsg openmsg) throws BGPParseException {
+ log.debug("capabilityValidation");
+
+ boolean isMultiProtocolcapabilityExists = false;
+ boolean isFourOctetCapabilityExits = false;
+ int capAsNum = 0;
+
+ List<BGPValueType> capabilityTlv = openmsg.getCapabilityTlv();
+ ListIterator<BGPValueType> listIterator = capabilityTlv.listIterator();
+ List<BGPValueType> unSupportedCapabilityTlv = new LinkedList<>();
+ ListIterator<BGPValueType> unSupportedCaplistIterator = unSupportedCapabilityTlv.listIterator();
+ BGPValueType tempTlv;
+ boolean isLargeAsCapabilityCfg = h.bgpconfig.getLargeASCapability();
+ boolean isLsCapabilityCfg = h.bgpconfig.getLsCapability();
+
+ while (listIterator.hasNext()) {
+ BGPValueType tlv = listIterator.next();
+ if (tlv.getType() == MULTI_PROTOCOL_EXTN_CAPA_TYPE) {
+ isMultiProtocolcapabilityExists = true;
+ }
+ if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
+ isFourOctetCapabilityExits = true;
+ capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
+ }
}
- if (bgpPacketStats.wrongPacketCount() > 1) {
- Date lastest = new Date();
- bgpPacketStats.addWrongPacket();
- // converting to seconds
- if (((lastest.getTime() - bgpPacketStats.getTime()) / 1000) > 60) {
- now = lastest;
- bgpPacketStats.setTime(now.getTime());
- bgpPacketStats.resetWrongPacket();
- bgpPacketStats.addWrongPacket();
- } else if (((int) (lastest.getTime() - now.getTime()) / 1000) < 60) {
- if (MAX_WRONG_COUNT_PACKET <= bgpPacketStats.wrongPacketCount()) {
- // reset once wrong packet count reaches MAX_WRONG_COUNT_PACKET
- bgpPacketStats.resetWrongPacket();
- // max wrong packets received send error message and close the session
- sendErrNotificationAndCloseChannel();
+
+ if (isFourOctetCapabilityExits) {
+ if (capAsNum > MAX_AS2_NUM) {
+ if (openmsg.getAsNumber() != AS_TRANS) {
+ throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null);
+ }
+ } else {
+ if (capAsNum != openmsg.getAsNumber()) {
+ throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null);
}
}
}
+
+ if ((isLsCapabilityCfg)) {
+ if (!isMultiProtocolcapabilityExists) {
+ tempTlv = new MultiProtocolExtnCapabilityTlv(AFI, RES, SAFI);
+ unSupportedCapabilityTlv.add(tempTlv);
+ }
+ }
+
+ if ((isLargeAsCapabilityCfg)) {
+ if (!isFourOctetCapabilityExits) {
+ tempTlv = new FourOctetAsNumCapabilityTlv(h.bgpconfig.getAsNumber());
+ unSupportedCapabilityTlv.add(tempTlv);
+ }
+ }
+
+ if (unSupportedCaplistIterator.hasNext()) {
+ ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
+ while (unSupportedCaplistIterator.hasNext()) {
+ BGPValueType tlv = unSupportedCaplistIterator.next();
+ tlv.write(buffer);
+ }
+ throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR,
+ BGPErrorType.UNSUPPORTED_CAPABILITY, buffer);
+ } else {
+ return true;
+ }
}
/**
- * Open message validation.
+ * AS Number Validation.
*
- * @param h channel handler
- * @return true if validation succeed, otherwise false
- * @throws BGPParseException when received invalid message
+ * @param h channel Handler
+ * @param openMsg open message
+ * @return true or false
*/
- public boolean openMsgValidation(BGPChannelHandler h) throws BGPParseException {
- // TODO: Open message validation.
+ private boolean asNumberValidation(BGPChannelHandler h, BGPOpenMsg openMsg) {
+ log.debug("AS Num validation");
+
+ int capAsNum = 0;
+ boolean isFourOctetCapabilityExits = false;
+
+ BGPPeerCfg peerCfg = h.bgpconfig.displayPeers(peerAddr);
+ List<BGPValueType> capabilityTlv = openMsg.getCapabilityTlv();
+ ListIterator<BGPValueType> listIterator = capabilityTlv.listIterator();
+
+ while (listIterator.hasNext()) {
+ BGPValueType tlv = listIterator.next();
+ if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
+ isFourOctetCapabilityExits = true;
+ capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
+ }
+ }
+
+ if (peerCfg.getAsNumber() > MAX_AS2_NUM) {
+ if (openMsg.getAsNumber() != AS_TRANS) {
+ return false;
+ }
+
+ if (!isFourOctetCapabilityExits) {
+ return false;
+ }
+
+ if (peerCfg.getAsNumber() != capAsNum) {
+ return false;
+ }
+
+ isIbgpSession = peerCfg.getIsIBgp();
+ if (isIbgpSession) {
+ // IBGP - AS number should be same for Peer and local if it is IBGP
+ if (h.bgpconfig.getAsNumber() != capAsNum) {
+ return false;
+ }
+ }
+ } else {
+
+ if (openMsg.getAsNumber() != peerCfg.getAsNumber()) {
+ return false;
+ }
+
+ if (isFourOctetCapabilityExits) {
+ if (capAsNum != peerCfg.getAsNumber()) {
+ return false;
+ }
+ }
+
+ isIbgpSession = peerCfg.getIsIBgp();
+ if (isIbgpSession) {
+ // IBGP - AS number should be same for Peer and local if it is IBGP
+ if (openMsg.getAsNumber() != h.bgpconfig.getAsNumber()) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Validates BGP ID.
+ *
+ * @param openMsg open message
+ * @return true or false
+ */
+ private boolean bgpIdValidation(BGPOpenMsg openMsg) {
+ String openMsgBgpId = Ip4Address.valueOf(openMsg.getBgpId()).toString();
+
+ InetAddress ipAddress;
+ try {
+ ipAddress = InetAddress.getByName(openMsgBgpId);
+ if (ipAddress.isMulticastAddress()) {
+ return false;
+ }
+ } catch (UnknownHostException e) {
+ log.debug("InetAddress convertion failed");
+ }
return true;
}
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java
index d8378e31..35c31ab7 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java
@@ -16,25 +16,25 @@
package org.onosproject.bgp.controller.impl;
-import static org.onlab.util.Tools.groupedThreads;
-
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+
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.Service;
-import org.onlab.packet.IpAddress;
import org.onosproject.bgp.controller.BGPCfg;
import org.onosproject.bgp.controller.BGPController;
import org.onosproject.bgp.controller.BGPId;
-import org.onosproject.bgp.controller.BGPPacketStats;
import org.onosproject.bgp.controller.BGPPeer;
+import org.onosproject.bgp.controller.BgpLinkListener;
+import org.onosproject.bgp.controller.BgpNodeListener;
+import org.onosproject.bgp.controller.BgpPeerManager;
+import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.protocol.BGPMessage;
-import org.onosproject.bgpio.protocol.BGPVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,16 +44,13 @@ public class BGPControllerImpl implements BGPController {
private static final Logger log = LoggerFactory.getLogger(BGPControllerImpl.class);
- private final ExecutorService executorMsgs = Executors.newFixedThreadPool(32,
- groupedThreads("onos/bgp",
- "event-stats-%d"));
-
- private final ExecutorService executorBarrier = Executors.newFixedThreadPool(4,
- groupedThreads("onos/bgp",
- "event-barrier-%d"));
protected ConcurrentHashMap<BGPId, BGPPeer> connectedPeers = new ConcurrentHashMap<BGPId, BGPPeer>();
- protected BGPPeerManager peerManager = new BGPPeerManager();
+ protected BGPPeerManagerImpl peerManager = new BGPPeerManagerImpl();
+
+ protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>();
+ protected Set<BgpLinkListener> bgpLinkListener = new CopyOnWriteArraySet<>();
+
final Controller ctrl = new Controller(this);
private BGPConfig bgpconfig = new BGPConfig();
@@ -83,12 +80,42 @@ public class BGPControllerImpl implements BGPController {
}
@Override
+ public void addListener(BgpNodeListener listener) {
+ this.bgpNodeListener.add(listener);
+ }
+
+ @Override
+ public void removeListener(BgpNodeListener listener) {
+ this.bgpNodeListener.remove(listener);
+ }
+
+ @Override
+ public Set<BgpNodeListener> listener() {
+ return bgpNodeListener;
+ }
+
+ @Override
+ public void addLinkListener(BgpLinkListener listener) {
+ this.bgpLinkListener.add(listener);
+ }
+
+ @Override
+ public void removeLinkListener(BgpLinkListener listener) {
+ this.bgpLinkListener.remove(listener);
+ }
+
+ @Override
+ public Set<BgpLinkListener> linkListener() {
+ return bgpLinkListener;
+ }
+
+ @Override
public void writeMsg(BGPId bgpId, BGPMessage msg) {
- // TODO: Send message
+ this.getPeer(bgpId).sendMessage(msg);
}
@Override
- public void processBGPPacket(BGPId bgpId, BGPMessage msg) {
+ public void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException {
switch (msg.getType()) {
case OPEN:
@@ -122,18 +149,12 @@ public class BGPControllerImpl implements BGPController {
* Implementation of an BGP Peer which is responsible for keeping track of connected peers and the state in which
* they are.
*/
- public class BGPPeerManager {
+ public class BGPPeerManagerImpl implements BgpPeerManager {
- private final Logger log = LoggerFactory.getLogger(BGPPeerManager.class);
+ private final Logger log = LoggerFactory.getLogger(BGPPeerManagerImpl.class);
private final Lock peerLock = new ReentrantLock();
- /**
- * Add a BGP peer that has just connected to the system.
- *
- * @param bgpId the id of bgp peer to add
- * @param bgpPeer the actual bgp peer object.
- * @return true if added, false otherwise.
- */
+ @Override
public boolean addConnectedPeer(BGPId bgpId, BGPPeer bgpPeer) {
if (connectedPeers.get(bgpId) != null) {
@@ -147,119 +168,49 @@ public class BGPControllerImpl implements BGPController {
}
}
- /**
- * Checks if the activation for this bgp peer is valid.
- *
- * @param bgpId the id of bgp peer to check
- * @return true if valid, false otherwise
- */
+ @Override
public boolean isPeerConnected(BGPId bgpId) {
if (connectedPeers.get(bgpId) == null) {
- this.log.error("Trying to activate peer but is not in " + "connected peer: bgpIp {}. Aborting ..",
- bgpId.toString());
+ this.log.error("Is peer connected: bgpIp {}.", bgpId.toString());
return false;
}
return true;
}
- /**
- * Checks if the activation for this bgp peer is valid.
- *
- * @param routerid the routerid of bgp peer to check
- * @return true if valid, false otherwise
- */
- public boolean isPeerConnected(String routerid) {
-
- final BGPId bgpId;
- bgpId = BGPId.bgpId(IpAddress.valueOf(routerid));
-
- if (connectedPeers.get(bgpId) != null) {
- this.log.info("Peer connection exist ");
- return true;
- }
- this.log.info("Initiate connect request to " + "peer: bgpIp {}", bgpId.toString());
-
- return false;
- }
-
- /**
- * Clear all state in controller peer maps for a bgp peer that has
- * disconnected from the local controller.
- *
- * @param bgpId the id of bgp peer to remove.
- */
+ @Override
public void removeConnectedPeer(BGPId bgpId) {
connectedPeers.remove(bgpId);
}
- /**
- * Clear all state in controller peer maps for a bgp peer that has
- * disconnected from the local controller.
- *
- * @param routerid the router id of bgp peer to remove.
- */
- public void removeConnectedPeer(String routerid) {
- final BGPId bgpId;
-
- bgpId = BGPId.bgpId(IpAddress.valueOf(routerid));
-
- connectedPeers.remove(bgpId);
- }
-
- /**
- * Gets bgp peer for connected peer map.
- *
- * @param routerid router id
- * @return peer if available, null otherwise
- */
- public BGPPeer getPeer(String routerid) {
- final BGPId bgpId;
- bgpId = BGPId.bgpId(IpAddress.valueOf(routerid));
-
+ @Override
+ public BGPPeer getPeer(BGPId bgpId) {
return connectedPeers.get(bgpId);
}
/**
- * Gets bgp peer instance.
- *
- * @param bgpId bgp identifier.
- * @param pv bgp version.
- * @param pktStats packet statistics.
- * @return BGPPeer peer instance.
- */
- public BGPPeer getBGPPeerInstance(BGPId bgpId, BGPVersion pv, BGPPacketStats pktStats) {
- BGPPeer bgpPeer = new BGPPeerImpl();
- bgpPeer.init(bgpId, pv, pktStats);
+ * Gets bgp peer instance.
+ *
+ * @param bgpController controller instance.
+ * @param sessionInfo bgp session info.
+ * @param pktStats packet statistics.
+ * @return BGPPeer peer instance.
+ */
+ public BGPPeer getBGPPeerInstance(BGPController bgpController, BgpSessionInfoImpl sessionInfo,
+ BGPPacketStatsImpl pktStats) {
+ BGPPeer bgpPeer = new BGPPeerImpl(bgpController, sessionInfo, pktStats);
return bgpPeer;
}
}
- /**
- * Gets controller instance.
- *
- * @return Controller instance.
- */
- public Controller getController() {
- return ctrl;
- }
-
- /**
- * Gets connected peers.
- *
- * @return connectedPeers from connected Peers Map.
- */
- public ConcurrentHashMap<BGPId, BGPPeer> getConnectedPeers() {
+ @Override
+ public ConcurrentHashMap<BGPId, BGPPeer> connectedPeers() {
return connectedPeers;
}
- /**
- * Gets peer manager.
- *
- * @return peerManager.
- */
- public BGPPeerManager getPeerManager() {
+ @Override
+ public BGPPeerManagerImpl peerManager() {
return peerManager;
}
@@ -269,7 +220,7 @@ public class BGPControllerImpl implements BGPController {
}
@Override
- public int getBGPConnNumber() {
+ public int connectedPeerCount() {
return connectedPeers.size();
}
-} \ No newline at end of file
+}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java
index 51b95a4b..14a68cf6 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java
@@ -16,6 +16,7 @@
package org.onosproject.bgp.controller.impl;
import org.onlab.packet.Ip4Address;
+import org.onosproject.bgp.controller.BgpConnectPeer;
import org.onosproject.bgp.controller.BGPPeerCfg;
/**
@@ -28,6 +29,7 @@ public class BGPPeerConfig implements BGPPeerCfg {
private Ip4Address peerId = null;
private State state;
private boolean selfInitiated;
+ private BgpConnectPeer connectPeer;
/**
* Constructor to initialize the values.
@@ -106,4 +108,14 @@ public class BGPPeerConfig implements BGPPeerCfg {
public void setSelfInnitConnection(boolean selfInit) {
this.selfInitiated = selfInit;
}
+
+ @Override
+ public BgpConnectPeer connectPeer() {
+ return this.connectPeer;
+ }
+
+ @Override
+ public void setConnectPeer(BgpConnectPeer connectPeer) {
+ this.connectPeer = connectPeer;
+ }
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java
index 212b24d3..45f74634 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java
@@ -24,11 +24,12 @@ import java.util.concurrent.RejectedExecutionException;
import org.jboss.netty.channel.Channel;
import org.onlab.packet.IpAddress;
-import org.onosproject.bgp.controller.BGPId;
-import org.onosproject.bgp.controller.BGPPacketStats;
+import org.onosproject.bgp.controller.BGPController;
import org.onosproject.bgp.controller.BGPPeer;
+import org.onosproject.bgp.controller.BgpSessionInfo;
+import org.onosproject.bgpio.protocol.BGPFactories;
+import org.onosproject.bgpio.protocol.BGPFactory;
import org.onosproject.bgpio.protocol.BGPMessage;
-import org.onosproject.bgpio.protocol.BGPVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,19 +44,31 @@ public class BGPPeerImpl implements BGPPeer {
private static final String SHUTDOWN_MSG = "Worker has already been shutdown";
+ private BGPController bgpController;
private Channel channel;
protected String channelId;
private boolean connected;
protected boolean isHandShakeComplete = false;
- public BGPSessionInfo sessionInfo;
+ private BgpSessionInfo sessionInfo;
private BGPPacketStatsImpl pktStats;
+
@Override
- public void init(BGPId bgpId, BGPVersion bgpVersion, BGPPacketStats pktStats) {
- this.sessionInfo.setRemoteBgpId(bgpId);
- this.sessionInfo.setRemoteBgpVersion(bgpVersion);
- this.pktStats = (BGPPacketStatsImpl) pktStats;
- this.sessionInfo = new BGPSessionInfo();
+ public BgpSessionInfo sessionInfo() {
+ return sessionInfo;
+ }
+
+ /**
+ * Initialize peer.
+ *
+ *@param bgpController controller instance
+ *@param sessionInfo bgp session info
+ *@param pktStats packet statistics
+ */
+ public BGPPeerImpl(BGPController bgpController, BgpSessionInfo sessionInfo, BGPPacketStatsImpl pktStats) {
+ this.bgpController = bgpController;
+ this.sessionInfo = sessionInfo;
+ this.pktStats = pktStats;
}
// ************************
@@ -129,53 +142,9 @@ public class BGPPeerImpl implements BGPPeer {
return channelId;
}
- // ************************
- // BGP Peer features related
- // ************************
-
- @Override
- public final BGPId getBGPId() {
- return this.sessionInfo.getRemoteBgpId();
- };
-
- @Override
- public final String getStringId() {
- return this.sessionInfo.getRemoteBgpId().toString();
- }
-
- @Override
- public final void setBgpPeerVersion(BGPVersion peerVersion) {
- this.sessionInfo.setRemoteBgpVersion(peerVersion);
- }
-
- @Override
- public void setBgpPeerASNum(short peerASNum) {
- this.sessionInfo.setRemoteBgpASNum(peerASNum);
- }
-
- @Override
- public void setBgpPeerHoldTime(short peerHoldTime) {
- this.sessionInfo.setRemoteBgpHoldTime(peerHoldTime);
- }
-
- @Override
- public void setBgpPeerIdentifier(int peerIdentifier) {
- this.sessionInfo.setRemoteBgpIdentifier(peerIdentifier);
- }
-
- @Override
- public int getBgpPeerIdentifier() {
- return this.sessionInfo.getRemoteBgpIdentifier();
- }
-
- @Override
- public int getNegotiatedHoldTime() {
- return this.sessionInfo.getNegotiatedholdTime();
- }
-
@Override
- public void setNegotiatedHoldTime(short negotiatedHoldTime) {
- this.sessionInfo.setNegotiatedholdTime(negotiatedHoldTime);
+ public BGPFactory factory() {
+ return BGPFactories.getFactory(sessionInfo.remoteBgpVersion());
}
@Override
@@ -185,7 +154,8 @@ public class BGPPeerImpl implements BGPPeer {
@Override
public String toString() {
- return MoreObjects.toStringHelper(getClass()).omitNullValues().add("channel", channelId())
- .add("bgpId", getBGPId()).toString();
+ return MoreObjects.toStringHelper(getClass()).omitNullValues()
+ .add("channel", channelId())
+ .add("bgpId", sessionInfo().remoteBgpId()).toString();
}
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java
index b2ca5077..e6f09f20 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java
@@ -23,6 +23,7 @@ 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.bgp.controller.BGPController;
/**
* Creates a ChannelPipeline for a server-side bgp channel.
@@ -32,30 +33,36 @@ public class BGPPipelineFactory
static final Timer TIMER = new HashedWheelTimer();
protected ReadTimeoutHandler readTimeoutHandler;
- BGPControllerImpl bgpCtrlImpl;
+ private boolean isBgpServ;
+ private BGPController bgpController;
/**
* Constructor to initialize the values.
*
- * @param ctrlImpl parent ctrlImpl
- * @param isServBgp if it is a server or not
+ * @param bgpController parent controller
+ * @param isBgpServ if it is a server or remote peer
*/
- public BGPPipelineFactory(BGPControllerImpl ctrlImpl, boolean isServBgp) {
+ public BGPPipelineFactory(BGPController bgpController, boolean isBgpServ) {
super();
- bgpCtrlImpl = ctrlImpl;
- /* hold time*/
- readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpCtrlImpl.getConfig().getHoldTime());
+ this.isBgpServ = isBgpServ;
+ this.bgpController = bgpController;
+ /* hold time */
+ this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpController.getConfig().getHoldTime());
}
@Override
public ChannelPipeline getPipeline() throws Exception {
- BGPChannelHandler handler = new BGPChannelHandler(bgpCtrlImpl);
+ BGPChannelHandler handler = new BGPChannelHandler(bgpController);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("bgpmessagedecoder", new BGPMessageDecoder());
pipeline.addLast("bgpmessageencoder", new BGPMessageEncoder());
pipeline.addLast("holdTime", readTimeoutHandler);
- pipeline.addLast("PassiveHandler", handler);
+ if (isBgpServ) {
+ pipeline.addLast("PassiveHandler", handler);
+ } else {
+ pipeline.addLast("ActiveHandler", handler);
+ }
return pipeline;
}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPSessionInfo.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPSessionInfo.java
deleted file mode 100755
index 207d7831..00000000
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPSessionInfo.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * 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.bgp.controller.impl;
-
-import org.onosproject.bgp.controller.BGPId;
-import org.onosproject.bgpio.protocol.BGPVersion;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Class maintains BGP peer session info.
- */
-public class BGPSessionInfo {
-
- protected final Logger log = LoggerFactory.getLogger(BGPSessionInfo.class);
- private BGPId remoteBgpId;
- private BGPVersion remoteBgpVersion;
- private short remoteBgpASNum;
- private short remoteBgpholdTime;
- private int remoteBgpIdentifier;
- private short negotiatedholdTime;
-
- /**
- * Gets the negotiated hold time for the session.
- *
- * @return negotiated hold time.
- */
- public short getNegotiatedholdTime() {
- return negotiatedholdTime;
- }
-
- /**
- * Sets the negotiated hold time for the session.
- *
- * @param negotiatedholdTime negotiated hold time.
- */
- public void setNegotiatedholdTime(short negotiatedholdTime) {
- this.negotiatedholdTime = negotiatedholdTime;
- }
-
- /**
- * Gets the BGP ID of BGP peer.
- *
- * @return bgp ID.
- */
- public BGPId getRemoteBgpId() {
- return remoteBgpId;
- }
-
- /**
- * Sets the BGP ID of bgp peer.
- *
- * @param bgpId BGP ID to set.
- */
- public void setRemoteBgpId(BGPId bgpId) {
- log.debug("Remote BGP ID {}", bgpId);
- this.remoteBgpId = bgpId;
- }
-
- /**
- * Gets the BGP version of peer.
- *
- * @return bgp version.
- */
- public BGPVersion getRemoteBgpVersion() {
- return remoteBgpVersion;
- }
-
- /**
- * Sets the BGP version for this bgp peer.
- *
- * @param bgpVersion bgp version to set.
- */
- public void setRemoteBgpVersion(BGPVersion bgpVersion) {
- log.debug("Remote BGP version {}", bgpVersion);
- this.remoteBgpVersion = bgpVersion;
- }
-
- /**
- * Gets the BGP remote bgp AS number.
- *
- * @return remoteBgpASNum peer AS number.
- */
- public short getRemoteBgpASNum() {
- return remoteBgpASNum;
- }
-
- /**
- * Sets the AS Number for this bgp peer.
- *
- * @param bgpASNum the autonomous system number value to set.
- */
- public void setRemoteBgpASNum(short bgpASNum) {
- log.debug("Remote BGP AS number {}", bgpASNum);
- this.remoteBgpASNum = bgpASNum;
- }
-
- /**
- * Gets the BGP peer hold time.
- *
- * @return bgp hold time.
- */
- public short getRemoteBgpHoldTime() {
- return remoteBgpholdTime;
- }
-
- /**
- * Sets the hold time for this bgp peer.
- *
- * @param holdTime the hold timer value to set.
- */
- public void setRemoteBgpHoldTime(short holdTime) {
- log.debug("Remote BGP HoldTime {}", holdTime);
- this.remoteBgpholdTime = holdTime;
- }
-
- /**
- * Gets the BGP version for this bgp peer.
- *
- * @return bgp identifier.
- */
- public int getRemoteBgpIdentifier() {
- return remoteBgpIdentifier;
- }
-
- /**
- * Sets the peer identifier value.
- *
- * @param bgpIdentifier the bgp peer identifier value.
- */
- public void setRemoteBgpIdentifier(int bgpIdentifier) {
- log.debug("Remote BGP Identifier {}", bgpIdentifier);
- this.remoteBgpIdentifier = bgpIdentifier;
- }
-}
diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java
index 402e8c94..017c39e5 100755
--- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java
+++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java
@@ -24,11 +24,17 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
+import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+import org.onosproject.bgp.controller.BGPController;
+import org.onosproject.bgpio.protocol.BGPFactories;
+import org.onosproject.bgpio.protocol.BGPFactory;
+import org.onosproject.bgpio.protocol.BGPVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,36 +44,45 @@ import org.slf4j.LoggerFactory;
*/
public class Controller {
- protected static final Logger log = LoggerFactory.getLogger(Controller.class);
+ private static final Logger log = LoggerFactory.getLogger(Controller.class);
+
+ private static final BGPFactory FACTORY4 = BGPFactories.getFactory(BGPVersion.BGP_4);
private ChannelGroup cg;
// Configuration options
private static final short BGP_PORT_NUM = 179;
- private int workerThreads = 16;
+ private final int workerThreads = 16;
+ private final int peerWorkerThreads = 16;
// Start time of the controller
- protected long systemStartTime;
+ private long systemStartTime;
private NioServerSocketChannelFactory serverExecFactory;
+ private NioClientSocketChannelFactory peerExecFactory;
+ private static ClientBootstrap peerBootstrap;
+ private BGPController bgpController;
// Perf. related configuration
- protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024;
-
- BGPControllerImpl bgpCtrlImpl;
+ private static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024;
/**
- * Constructor to initialize parameter.
+ * Constructor to initialize the values.
*
- * @param bgpCtrlImpl BGP controller Impl instance
+ * @param bgpController bgp controller instance
*/
- public Controller(BGPControllerImpl bgpCtrlImpl) {
- this.bgpCtrlImpl = bgpCtrlImpl;
+ public Controller(BGPController bgpController) {
+ this.bgpController = bgpController;
}
- // ***************
- // Getters/Setters
- // ***************
+ /**
+ * Returns factory version for processing BGP messages.
+ *
+ * @return instance of factory version
+ */
+ static BGPFactory getBGPMessageFactory4() {
+ return FACTORY4;
+ }
/**
* To get system start time.
@@ -78,16 +93,20 @@ public class Controller {
return (this.systemStartTime);
}
- // **************
- // Initialization
- // **************
-
/**
* Tell controller that we're ready to accept bgp peer connections.
*/
public void run() {
try {
+
+ peerBootstrap = createPeerBootStrap();
+
+ peerBootstrap.setOption("reuseAddr", true);
+ peerBootstrap.setOption("child.keepAlive", true);
+ peerBootstrap.setOption("child.tcpNoDelay", true);
+ peerBootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
+
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
@@ -95,7 +114,7 @@ public class Controller {
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
- ChannelPipelineFactory pfact = new BGPPipelineFactory(bgpCtrlImpl, true);
+ ChannelPipelineFactory pfact = new BGPPipelineFactory(bgpController, true);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(getBgpPortNum());
@@ -129,6 +148,36 @@ public class Controller {
}
/**
+ * Creates peer boot strap.
+ *
+ * @return ClientBootstrap
+ */
+ private ClientBootstrap createPeerBootStrap() {
+
+ if (peerWorkerThreads == 0) {
+ peerExecFactory = new NioClientSocketChannelFactory(
+ Executors.newCachedThreadPool(groupedThreads("onos/bgp", "boss-%d")),
+ Executors.newCachedThreadPool(groupedThreads("onos/bgp", "worker-%d")));
+ return new ClientBootstrap(peerExecFactory);
+ } else {
+ peerExecFactory = new NioClientSocketChannelFactory(
+ Executors.newCachedThreadPool(groupedThreads("onos/bgp", "boss-%d")),
+ Executors.newCachedThreadPool(groupedThreads("onos/bgp", "worker-%d")),
+ peerWorkerThreads);
+ return new ClientBootstrap(peerExecFactory);
+ }
+ }
+
+ /**
+ * Gets peer bootstrap.
+ *
+ * @return peer bootstrap
+ */
+ public static ClientBootstrap peerBootstrap() {
+ return peerBootstrap;
+ }
+
+ /**
* Initialize internal data structures.
*/
public void init() {
@@ -137,10 +186,11 @@ public class Controller {
this.systemStartTime = System.currentTimeMillis();
}
- // **************
- // Utility methods
- // **************
-
+ /**
+ * Gets run time memory.
+ *
+ * @return m run time memory
+ */
public Map<String, Long> getMemory() {
Map<String, Long> m = new HashMap<>();
Runtime runtime = Runtime.getRuntime();
@@ -149,6 +199,11 @@ public class Controller {
return m;
}
+ /**
+ * Gets UP time.
+ *
+ * @return UP time
+ */
public Long getUptime() {
RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
return rb.getUptime();
@@ -169,6 +224,7 @@ public class Controller {
public void stop() {
log.info("Stopped");
serverExecFactory.shutdown();
+ peerExecFactory.shutdown();
cg.close();
}