Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 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; |
Shashikanth VH | afb2e00 | 2016-02-12 14:48:29 +0530 | [diff] [blame] | 22 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; |
| 23 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; |
Priyanka B | c08e56d | 2015-11-27 15:28:33 +0530 | [diff] [blame] | 24 | import org.onosproject.bgpio.types.BgpValueType; |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 25 | |
| 26 | /** |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 27 | * Represents the peer side of an BGP peer. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 28 | * |
| 29 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 30 | public interface BgpPeer { |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 31 | |
Shashikanth VH | afb2e00 | 2016-02-12 14:48:29 +0530 | [diff] [blame] | 32 | enum FlowSpecOperation { |
| 33 | |
| 34 | /** |
| 35 | * Signifies addition of flow specification rule. |
| 36 | */ |
| 37 | ADD, |
| 38 | |
| 39 | /** |
| 40 | * Signifies updation of flow specification rule. |
| 41 | */ |
| 42 | UPDATE, |
| 43 | |
| 44 | /** |
| 45 | * Signifies deletion of flow specification rule. |
| 46 | */ |
| 47 | DELETE |
| 48 | } |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 49 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 50 | * Sets the associated Netty channel for this bgp peer. |
| 51 | * |
| 52 | * @param channel the Netty channel |
| 53 | */ |
| 54 | void setChannel(Channel channel); |
| 55 | |
| 56 | /** |
| 57 | * Gets the associated Netty channel handler for this bgp peer. |
| 58 | * |
| 59 | * @return Channel channel connected. |
| 60 | */ |
| 61 | Channel getChannel(); |
| 62 | |
| 63 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 64 | * Sets whether the bgp peer is connected. |
| 65 | * |
| 66 | * @param connected whether the bgp peer is connected |
| 67 | */ |
| 68 | void setConnected(boolean connected); |
| 69 | |
| 70 | /** |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 71 | * Checks whether the handshake is complete. |
| 72 | * |
| 73 | * @return true is finished, false if not. |
| 74 | */ |
| 75 | boolean isHandshakeComplete(); |
| 76 | |
| 77 | /** |
| 78 | * Writes the message to the peer. |
| 79 | * |
| 80 | * @param msg the message to write |
| 81 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 82 | void sendMessage(BgpMessage msg); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Writes the BGPMessage list to the peer. |
| 86 | * |
| 87 | * @param msgs the messages to be written |
| 88 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 89 | void sendMessage(List<BgpMessage> msgs); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 90 | |
| 91 | /** |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 92 | * Provides the factory for BGP version. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 93 | * |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 94 | * @return BGP version specific factory. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 95 | */ |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 96 | BgpFactory factory(); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Checks if the bgp peer is still connected. |
| 100 | * |
| 101 | * @return whether the bgp peer is still connected |
| 102 | */ |
| 103 | boolean isConnected(); |
| 104 | |
| 105 | /** |
| 106 | * Disconnects the bgp peer by closing the TCP connection. Results in a call to the channel handler's |
| 107 | * channelDisconnected method for cleanup |
| 108 | */ |
| 109 | void disconnectPeer(); |
| 110 | |
| 111 | /** |
| 112 | * Identifies the channel used to communicate with the bgp peer. |
| 113 | * |
| 114 | * @return string representation of the connection to the peer |
| 115 | */ |
| 116 | String channelId(); |
| 117 | |
| 118 | /** |
Priyanka B | c08e56d | 2015-11-27 15:28:33 +0530 | [diff] [blame] | 119 | * Maintaining Adj-RIB-In separately for each peer. |
| 120 | * |
| 121 | * @param pathAttr list of Bgp path attributes |
| 122 | * @throws BgpParseException while building Adj-Rib-In |
| 123 | */ |
| 124 | void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException; |
| 125 | |
| 126 | /** |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 127 | * Update flow specification RIB for each peer. |
| 128 | * |
| 129 | * @param pathAttr list of Bgp path attributes |
| 130 | * @throws BgpParseException while building flow spec RIB |
| 131 | */ |
| 132 | void buildFlowSpecRib(List<BgpValueType> pathAttr) throws BgpParseException; |
| 133 | |
| 134 | /** |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 135 | * Return the BGP session info. |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 136 | * |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 137 | * @return sessionInfo bgp session info |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 138 | */ |
Shashikanth VH | 9f8afb4 | 2015-11-04 18:00:30 +0530 | [diff] [blame] | 139 | BgpSessionInfo sessionInfo(); |
Shashikanth VH | afb2e00 | 2016-02-12 14:48:29 +0530 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * Updates flow specification rule. |
| 143 | * |
| 144 | * @param operType operation type add or delete or update |
| 145 | * @param prefix prefix for the flow rule |
| 146 | * @param flowSpec BGP flow specification components |
| 147 | */ |
| 148 | void updateFlowSpec(FlowSpecOperation operType, BgpFlowSpecPrefix prefix, |
| 149 | BgpFlowSpecDetails flowSpec); |
Shashikanth VH | 6de20d3 | 2015-10-09 12:04:13 +0530 | [diff] [blame] | 150 | } |