From 6a07d2d622eaa06953f3353e39c080984076e8de Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Fri, 9 Oct 2015 18:32:44 -0700 Subject: Updated master to commit id 6ee8aa3e67ce89908a8c93aa9445c6f71a18f986 Change-Id: I94b055ee2f298daf71e2ec794fd0f2495bd8081f --- framework/src/onos/bgp/api/pom.xml | 95 +++++++ .../org/onosproject/bgp/controller/BGPCfg.java | 297 +++++++++++++++++++++ .../onosproject/bgp/controller/BGPController.java | 49 ++++ .../java/org/onosproject/bgp/controller/BGPId.java | 121 +++++++++ .../onosproject/bgp/controller/BGPPacketStats.java | 52 ++++ .../org/onosproject/bgp/controller/BGPPeerCfg.java | 166 ++++++++++++ .../onosproject/bgp/controller/package-info.java | 20 ++ 7 files changed, 800 insertions(+) create mode 100755 framework/src/onos/bgp/api/pom.xml create mode 100755 framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPCfg.java create mode 100755 framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java create mode 100755 framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPId.java create mode 100755 framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPacketStats.java create mode 100755 framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java create mode 100755 framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/package-info.java (limited to 'framework/src/onos/bgp/api') diff --git a/framework/src/onos/bgp/api/pom.xml b/framework/src/onos/bgp/api/pom.xml new file mode 100755 index 00000000..6fa1cc7b --- /dev/null +++ b/framework/src/onos/bgp/api/pom.xml @@ -0,0 +1,95 @@ + + + + 4.0.0 + + + org.onosproject + onos-bgp + 1.4.0-SNAPSHOT + ../pom.xml + + + onos-bgp-api + bundle + + ONOS BGP controller subsystem API + + + + org.onosproject + onos-bgpio + + + io.netty + netty + + + org.onosproject + onos-api + + + org.onosproject + onlab-misc + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + + io.netty:netty + com.google.guava:guava + org.slf4j:slfj-api + ch.qos.logback:logback-core + ch.qos.logback:logback-classic + com.google.code.findbugs:annotations + + + + + + package + + shade + + + + + + org.apache.felix + maven-bundle-plugin + + + + org.onosproject.bgp.*,org.onosproject.bgpio.*,org.onosproject.bgp.controller + + + + + + + + diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPCfg.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPCfg.java new file mode 100755 index 00000000..46165d87 --- /dev/null +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPCfg.java @@ -0,0 +1,297 @@ +/* + * 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.TreeMap; + +/** + * Abstraction of an BGP configuration. Manages the BGP configuration from CLI to the BGP controller. + */ +public interface BGPCfg { + + enum State { + /** + * Signifies that its just created. + */ + INIT, + + /** + * Signifies that only IP Address is configured. + */ + IP_CONFIGURED, + + /** + * Signifies that only Autonomous System is configured. + */ + AS_CONFIGURED, + + /** + * Signifies that both IP and Autonomous System is configured. + */ + IP_AS_CONFIGURED + } + + /** + * Returns the status of the configuration based on this state certain operations like connection is handled. + * + * @return State of the configuration + */ + State getState(); + + /** + * To set the current state of the configuration. + * + * @param state Configuration State enum + */ + void setState(State state); + + /** + * Get the status of the link state support for this BGP speaker. + * + * @return true if the link state is supported else false + */ + boolean getLsCapability(); + + /** + * Set the link state support to this BGP speaker. + * + * @param lscapability true value if link state is supported else false + */ + void setLsCapability(boolean lscapability); + + /** + * Get the status of the 32 bit AS support for this BGP speaker. + * + * @return true if the 32 bit AS number is supported else false + */ + boolean getLargeASCapability(); + + /** + * Set the 32 bit AS support capability to this BGP speaker. + * + * @param largeAs true value if the 32 bit AS is supported else false + */ + void setLargeASCapability(boolean largeAs); + + /** + * Set the AS number to which this BGP speaker belongs. + * + * @param localAs 16 or 32 bit AS number, length is dependent on the capability + */ + void setAsNumber(int localAs); + + /** + * Get the AS number to which this BGP speaker belongs. + * + * @return 16 or 32 bit AS number, length is dependent on the capability + */ + int getAsNumber(); + + /** + * Get the connection retry count number. + * + * @return connection retry count if there is a connection error + */ + int getMaxConnRetryCount(); + + /** + * Set the connection retry count. + * + * @param retryCount number of times to try to connect if there is any error + */ + void setMaxConnRetryCout(int retryCount); + + /** + * Get the connection retry time in seconds. + * + * @return connection retry time in seconds + */ + int getMaxConnRetryTime(); + + /** + * Set the connection retry time in seconds. + * + * @param retryTime connection retry times in seconds + */ + void setMaxConnRetryTime(int retryTime); + + /** + * Set the keep alive timer for the connection. + * + * @param holdTime connection hold timer in seconds + */ + void setHoldTime(short holdTime); + + /** + * Returns the connection hold timer in seconds. + * + * @return connection hold timer in seconds + */ + short getHoldTime(); + + /** + * Returns the maximum number of session supported. + * + * @return maximum number of session supported + */ + int getMaxSession(); + + /** + * Set the maximum number of sessions to support. + * + * @param maxsession maximum number of session + */ + void setMaxSession(int maxsession); + + /** + * Returns the Router ID of this BGP speaker. + * + * @return IP address in string format + */ + String getRouterId(); + + /** + * Set the Router ID of this BGP speaker. + * + * @param routerid IP address in string format + */ + void setRouterId(String routerid); + + /** + * Add the BGP peer IP address and the AS number to which it belongs. + * + * @param routerid IP address in string format + * @param remoteAs AS number to which it belongs + * + * @return true if added successfully else false + */ + boolean addPeer(String routerid, int remoteAs); + + /** + * Add the BGP peer IP address and the keep alive time. + * + * @param routerid IP address in string format + * @param holdTime keep alive time for the connection + * + * @return true if added successfully else false + */ + boolean addPeer(String routerid, short holdTime); + + /** + * Add the BGP peer IP address, the AS number to which it belongs and keep alive time. + * + * @param routerid IP address in string format + * @param remoteAs AS number to which it belongs + * @param holdTime keep alive time for the connection + * + * @return true if added successfully else false + */ + boolean addPeer(String routerid, int remoteAs, short holdTime); + + /** + * Remove the BGP peer with this IP address. + * + * @param routerid router IP address + * + * @return true if removed successfully else false + */ + boolean removePeer(String routerid); + + /** + * Connect to BGP peer with this IP address. + * + * @param routerid router IP address + * + * @return true of the configuration is found and able to connect else false + */ + boolean connectPeer(String routerid); + + /** + * Disconnect this BGP peer with this IP address. + * + * @param routerid router IP address in string format + * + * @return true if the configuration is found and able to disconnect else false + */ + boolean disconnectPeer(String routerid); + + /** + * Returns the peer tree information. + * + * @return return the tree map with IP as key and BGPPeerCfg as object + */ + TreeMap displayPeers(); + + /** + * Return the BGP Peer information with this matching IP. + * + * @param routerid router IP address in string format + * + * @return BGPPeerCfg object + */ + BGPPeerCfg displayPeers(String routerid); + + /** + * Check if this BGP peer is configured. + * + * @param routerid router IP address in string format + * + * @return true if configured exists else false + */ + boolean isPeerConfigured(String routerid); + + /** + * Check if this BGP speaker is having connection with the peer. + * + * @param routerid router IP address in string format + * + * @return true if the connection exists else false + */ + boolean isPeerConnected(String routerid); + + /** + * Return the peer tree map. + * + * @return return the tree map with IP as key and BGPPeerCfg as object + */ + TreeMap getPeerTree(); + + /** + * Set the current connection state information. + * + * @param routerid router IP address in string format + * @param state state information + */ + void setPeerConnState(String routerid, BGPPeerCfg.State state); + + /** + * Check if the peer can be connected or not. + * + * @param routerid router IP address in string format + * + * @return true if the peer can be connected else false + */ + boolean isPeerConnectable(String routerid); + + /** + * Get the current peer connection state information. + * + * @param routerid router IP address in string format + * + * @return state information + */ + BGPPeerCfg.State getPeerConnState(String routerid); +} 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 new file mode 100755 index 00000000..6d758122 --- /dev/null +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java @@ -0,0 +1,49 @@ +/* + * 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 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 + */ +public interface BGPController { + + /** + * Send a message to a particular bgp peer. + * + * @param bgpId the id of the peer to send message. + * @param msg the message to send + */ + void writeMsg(BGPId bgpId, BGPMessage msg); + + /** + * Process a message and notify the appropriate listeners. + * + * @param bgpId id of the peer the message arrived on + * @param msg the message to process. + */ + void processBGPPacket(BGPId bgpId, BGPMessage msg); + + /** + * Get the BGPConfig class to the caller. + * + * @return configuration object + */ + BGPCfg getConfig(); +} \ No newline at end of file diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPId.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPId.java new file mode 100755 index 00000000..636e72f3 --- /dev/null +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPId.java @@ -0,0 +1,121 @@ +/* + * 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 org.onlab.packet.IpAddress; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkArgument; + +/** + * The class representing a network peer bgp ip. + * This class is immutable. + */ +public final class BGPId { + + private static final String SCHEME = "bgp"; + private static final long UNKNOWN = 0; + private final IpAddress ipAddress; + + /** + * Private constructor. + */ + private BGPId(IpAddress ipAddress) { + this.ipAddress = ipAddress; + } + + /** + * Create a BGPId from ip address. + * + * @param ipAddress IP address + * @return object of BGPId + */ + public static BGPId bgpId(IpAddress ipAddress) { + return new BGPId(ipAddress); + } + + /** + * Returns the ip address. + * + * @return ipAddress + */ + public IpAddress ipAddress() { + return ipAddress; + } + + /** + * Convert the BGPId value to a ':' separated hexadecimal string. + * + * @return the BGPId value as a ':' separated hexadecimal string. + */ + @Override + public String toString() { + return ipAddress.toString(); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof BGPId)) { + return false; + } + + BGPId otherBGPid = (BGPId) other; + return Objects.equals(ipAddress, otherBGPid.ipAddress); + } + + @Override + public int hashCode() { + return Objects.hash(ipAddress); + } + + /** + * Returns BGPId created from the given device URI. + * + * @param uri device URI + * @return object of BGPId + */ + public static BGPId bgpId(URI uri) { + checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme"); + return new BGPId(IpAddress.valueOf(uri.getSchemeSpecificPart())); + } + + /** + * Produces device URI from the given DPID. + * + * @param bgpId device bgpId + * @return device URI + */ + public static URI uri(BGPId bgpId) { + return uri(bgpId.ipAddress()); + } + + /** + * Produces device URI from the given DPID long. + * + * @param ipAddress device ip address + * @return device URI + */ + public static URI uri(IpAddress ipAddress) { + try { + return new URI(SCHEME, ipAddress.toString(), null); + } catch (URISyntaxException e) { + return null; + } + } +} \ No newline at end of file diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPacketStats.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPacketStats.java new file mode 100755 index 00000000..95f83a2d --- /dev/null +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPacketStats.java @@ -0,0 +1,52 @@ +/* + * 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; + +/** + * A representation of a packet context which allows any provider to view a packet in event, but may block the response + * to the event if blocked has been called. This packet context can be used to react to the packet in event with a + * packet out. + */ +public interface BGPPacketStats { + /** + * Returns the count for no of packets sent out. + * + * @return int value of no of packets sent + */ + int outPacketCount(); + + /** + * Returns the count for no of packets received. + * + * @return int value of no of packets sent + */ + int inPacketCount(); + + /** + * Returns the count for no of wrong packets received. + * + * @return int value of no of wrong packets received + */ + int wrongPacketCount(); + + /** + * Returns the time. + * + * @return the time + */ + long getTime(); +} \ No newline at end of file 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 new file mode 100755 index 00000000..87ec031f --- /dev/null +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java @@ -0,0 +1,166 @@ +/* + * 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; + +/** + * BGP Peer configuration information. + */ +public interface BGPPeerCfg { + + enum State { + + /** + * Signifies that peer connection is idle. + */ + IDLE, + + /** + * Signifies that connection is initiated. + */ + CONNECT, + + /** + * Signifies that state is active and connection can be established. + */ + ACTIVE, + + /** + * Signifies that open is sent and anticipating reply. + */ + OPENSENT, + + /** + * Signifies that peer sent the open message as reply. + */ + OPENCONFIRM, + + /** + * Signifies that all the negotiation is successful and ready to exchange other messages. + */ + ESTABLISHED, + + /** + * Signifies that invalid state. + */ + INVALID + } + + /** + * Returns the connection State information of the peer. + * + * @return + * enum state is returned + */ + State getState(); + + /** + * Set the connection state information of the peer. + * + * @param state + * enum state + */ + void setState(State state); + + /** + * Returns the connection is initiated from us or not. + * + * @return + * true if the connection is initiated by this peer, false if it has been received. + */ + boolean getSelfInnitConnection(); + + /** + * Set the connection is initiated from us or not. + * + * @param selfInit + * true if the connection is initiated by this peer, false if it has been received. + */ + void setSelfInnitConnection(boolean selfInit); + + /** + * Returns the AS number to which this peer belongs. + * + * @return + * AS number + */ + int getAsNumber(); + + /** + * Set the AS number to which this peer belongs. + * + * @param asNumber + * AS number + */ + void setAsNumber(int asNumber); + + /** + * Get the keep alive timer value configured. + * + * @return + * keep alive timer value in seconds + */ + short getHoldtime(); + + /** + * Set the keep alive timer value. + * + * @param holdTime + * keep alive timer value in seconds + */ + void setHoldtime(short holdTime); + + /** + * Return the connection type eBGP or iBGP. + * + * @return + * true if iBGP, false if it is eBGP + */ + boolean getIsIBgp(); + + /** + * Set the connection type eBGP or iBGP. + * + * @param isIBgp + * true if iBGP, false if it is eBGP + */ + void setIsIBgp(boolean isIBgp); + + /** + * Return the peer router IP address. + * + * @return + * IP address in string format + */ + String getPeerRouterId(); + + /** + * Set the peer router IP address. + * + * @param peerId + * IP address in string format + */ + void setPeerRouterId(String peerId); + + /** + * Set the peer router IP address and AS number. + * + * @param peerId + * IP address in string format + * @param asNumber + * AS number + */ + void setPeerRouterId(String peerId, int asNumber); +} diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/package-info.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/package-info.java new file mode 100755 index 00000000..4dd775b8 --- /dev/null +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * BGP controller API. + */ +package org.onosproject.bgp.controller; -- cgit 1.2.3-korg