blob: 337decc230b762ca7320dc60796927d4e89a25c1 [file] [log] [blame]
Shashikanth VH6de20d32015-10-09 12:04:13 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Shashikanth VH6de20d32015-10-09 12:04:13 +05303 *
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 */
16package org.onosproject.bgp.controller;
17import java.util.List;
18import org.jboss.netty.channel.Channel;
Priyanka Bc08e56d2015-11-27 15:28:33 +053019import org.onosproject.bgpio.exceptions.BgpParseException;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053020import org.onosproject.bgpio.protocol.BgpFactory;
21import org.onosproject.bgpio.protocol.BgpMessage;
Shashikanth VHafb2e002016-02-12 14:48:29 +053022import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails;
23import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix;
Priyanka Bc08e56d2015-11-27 15:28:33 +053024import org.onosproject.bgpio.types.BgpValueType;
Shashikanth VH6de20d32015-10-09 12:04:13 +053025
26/**
Shashikanth VH9f8afb42015-11-04 18:00:30 +053027 * Represents the peer side of an BGP peer.
Shashikanth VH6de20d32015-10-09 12:04:13 +053028 *
29 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053030public interface BgpPeer {
Shashikanth VH6de20d32015-10-09 12:04:13 +053031
Shashikanth VHafb2e002016-02-12 14:48:29 +053032 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 VH6de20d32015-10-09 12:04:13 +053049 /**
Shashikanth VH6de20d32015-10-09 12:04:13 +053050 * 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 VH6de20d32015-10-09 12:04:13 +053064 * 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 VH6de20d32015-10-09 12:04:13 +053071 * 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 VH5dd8dbe2015-11-26 13:22:18 +053082 void sendMessage(BgpMessage msg);
Shashikanth VH6de20d32015-10-09 12:04:13 +053083
84 /**
85 * Writes the BGPMessage list to the peer.
86 *
87 * @param msgs the messages to be written
88 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053089 void sendMessage(List<BgpMessage> msgs);
Shashikanth VH6de20d32015-10-09 12:04:13 +053090
91 /**
Shashikanth VH9f8afb42015-11-04 18:00:30 +053092 * Provides the factory for BGP version.
Shashikanth VH6de20d32015-10-09 12:04:13 +053093 *
Shashikanth VH9f8afb42015-11-04 18:00:30 +053094 * @return BGP version specific factory.
Shashikanth VH6de20d32015-10-09 12:04:13 +053095 */
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053096 BgpFactory factory();
Shashikanth VH6de20d32015-10-09 12:04:13 +053097
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 Bc08e56d2015-11-27 15:28:33 +0530119 * 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 VHe3a73bc2016-02-22 20:11:31 +0530127 * 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 VH9f8afb42015-11-04 18:00:30 +0530135 * Return the BGP session info.
Shashikanth VH6de20d32015-10-09 12:04:13 +0530136 *
Shashikanth VH9f8afb42015-11-04 18:00:30 +0530137 * @return sessionInfo bgp session info
Shashikanth VH6de20d32015-10-09 12:04:13 +0530138 */
Shashikanth VH9f8afb42015-11-04 18:00:30 +0530139 BgpSessionInfo sessionInfo();
Shashikanth VHafb2e002016-02-12 14:48:29 +0530140
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 VH6de20d32015-10-09 12:04:13 +0530150}