Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.bgp.controller; |
| 17 | import java.util.List; |
| 18 | import org.jboss.netty.channel.Channel; |
Priyanka B | c08e56d | 2015-11-27 15:28:33 +0530 | [diff] [blame] | 19 | import org.onosproject.bgpio.exceptions.BgpParseException; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 20 | import org.onosproject.bgpio.protocol.BgpFactory; |
| 21 | import org.onosproject.bgpio.protocol.BgpMessage; |
Priyanka B | c08e56d | 2015-11-27 15:28:33 +0530 | [diff] [blame] | 22 | import org.onosproject.bgpio.types.BgpValueType; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 23 | |
| 24 | /** |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 25 | * Represents the peer side of an BGP peer. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 26 | * |
| 27 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 28 | public interface BgpPeer { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 29 | |
| 30 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 31 | * Sets the associated Netty channel for this bgp peer. |
| 32 | * |
| 33 | * @param channel the Netty channel |
| 34 | */ |
| 35 | void setChannel(Channel channel); |
| 36 | |
| 37 | /** |
| 38 | * Gets the associated Netty channel handler for this bgp peer. |
| 39 | * |
| 40 | * @return Channel channel connected. |
| 41 | */ |
| 42 | Channel getChannel(); |
| 43 | |
| 44 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 45 | * Sets whether the bgp peer is connected. |
| 46 | * |
| 47 | * @param connected whether the bgp peer is connected |
| 48 | */ |
| 49 | void setConnected(boolean connected); |
| 50 | |
| 51 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 52 | * Checks whether the handshake is complete. |
| 53 | * |
| 54 | * @return true is finished, false if not. |
| 55 | */ |
| 56 | boolean isHandshakeComplete(); |
| 57 | |
| 58 | /** |
| 59 | * Writes the message to the peer. |
| 60 | * |
| 61 | * @param msg the message to write |
| 62 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 63 | void sendMessage(BgpMessage msg); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Writes the BGPMessage list to the peer. |
| 67 | * |
| 68 | * @param msgs the messages to be written |
| 69 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 70 | void sendMessage(List<BgpMessage> msgs); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 71 | |
| 72 | /** |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 73 | * Provides the factory for BGP version. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 74 | * |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 75 | * @return BGP version specific factory. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 76 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 77 | BgpFactory factory(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Checks if the bgp peer is still connected. |
| 81 | * |
| 82 | * @return whether the bgp peer is still connected |
| 83 | */ |
| 84 | boolean isConnected(); |
| 85 | |
| 86 | /** |
| 87 | * Disconnects the bgp peer by closing the TCP connection. Results in a call to the channel handler's |
| 88 | * channelDisconnected method for cleanup |
| 89 | */ |
| 90 | void disconnectPeer(); |
| 91 | |
| 92 | /** |
| 93 | * Identifies the channel used to communicate with the bgp peer. |
| 94 | * |
| 95 | * @return string representation of the connection to the peer |
| 96 | */ |
| 97 | String channelId(); |
| 98 | |
| 99 | /** |
Priyanka B | c08e56d | 2015-11-27 15:28:33 +0530 | [diff] [blame] | 100 | * Maintaining Adj-RIB-In separately for each peer. |
| 101 | * |
| 102 | * @param pathAttr list of Bgp path attributes |
| 103 | * @throws BgpParseException while building Adj-Rib-In |
| 104 | */ |
| 105 | void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException; |
| 106 | |
| 107 | /** |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 108 | * Return the BGP session info. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 109 | * |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 110 | * @return sessionInfo bgp session info |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 111 | */ |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 112 | BgpSessionInfo sessionInfo(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 113 | } |