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