aboutsummaryrefslogtreecommitdiffstats
path: root/src/include/VppManager.hpp
blob: 3a692b8a0d15b39644d25245131fba289fd5c0ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
 * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

#ifndef __VPP_MANAGER_H__
#define __VPP_MANAGER_H__

#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/ip/address.hpp>
#include <boost/noncopyable.hpp>
#include <boost/optional.hpp>

#include <vom/hw.hpp>
#include <vom/interface.hpp>

#include <opflex/ofcore/PeerStatusListener.h>

#include <utility>

#include "opflexagent/Agent.h"
#include "opflexagent/EndpointManager.h"
#include "opflexagent/RDConfig.h"
#include "opflexagent/TaskQueue.h"

#include "VppCrossConnect.hpp"
#include "VppRuntime.hpp"

namespace VOM
{
class stat_reader;
};
namespace VPP
{
class EndPointManager;
class EndPointGroupManager;
class SecurityGroupManager;
class ContractManager;
class RouteManager;
class ExtItfManager;

/**
 * @brief Makes changes to VPP to be in sync with state of MOs.
 * Main function is to handling change notifications, generate a set
 * of config modifications that represent the changes and apply these
 * modifications.
 */
class VppManager : public opflexagent::EndpointListener,
                   public opflexagent::ServiceListener,
                   public opflexagent::ExtraConfigListener,
                   public opflexagent::PolicyListener,
                   public opflex::ofcore::PeerStatusListener,
                   public interface::event_listener,
                   private boost::noncopyable
{
  public:
    /**
     * Construct a new Vpp manager for the agent
     * @param agent the agent object
     * @param idGen the flow ID generator
     */
    VppManager(opflexagent::Agent &agent,
               opflexagent::IdGenerator &idGen,
               VOM::HW::cmd_q *q,
               VOM::stat_reader *sr);

    ~VppManager();

    /**
     * Module start
     */
    virtual void start();

    /**
     * Installs listeners for receiving updates to MODB state.
     */
    virtual void registerModbListeners();

    /**
     * Module stop
     */
    virtual void stop();

    /**
     * Enable or disable the virtual routing
     *
     * @param virtualRouterEnabled true to enable the router
     * @param routerAdv true to enable IPv6 router advertisements
     * @param mac the MAC address to use as the router MAC formatted
     * as a colon-separated string of 6 hex-encoded bytes.
     */
    void setVirtualRouter(bool virtualRouterEnabled,
                          bool routerAdv,
                          const std::string &mac);

    /* Interface: EndpointListener */
    virtual void endpointUpdated(const std::string &uuid);
    virtual void externalEndpointUpdated(const std::string &uuid);
    virtual void remoteEndpointUpdated(const std::string &uuid);
    virtual void secGroupSetUpdated(const EndpointListener::uri_set_t &secGrps);

    /* Interface: ServiceListener */
    virtual void serviceUpdated(const std::string &uuid);

    /* Interface: ExtraConfigListener */
    virtual void rdConfigUpdated(const opflex::modb::URI &rdURI);

    /* Interface: PolicyListener */
    virtual void egDomainUpdated(const opflex::modb::URI &egURI);
    virtual void domainUpdated(opflex::modb::class_id_t cid,
                               const opflex::modb::URI &domURI);
    virtual void contractUpdated(const opflex::modb::URI &contractURI);
    virtual void configUpdated(const opflex::modb::URI &configURI);
    virtual void externalInterfaceUpdated(const opflex::modb::URI &);
    virtual void localRouteUpdated(const opflex::modb::URI &);
    virtual void secGroupUpdated(const opflex::modb::URI &);

    /* Interface: PortStatusListener */
    virtual void portStatusUpdate(const std::string &portName,
                                  uint32_t portNo,
                                  bool fromDesc);

    /**
     * Implementation for PeerStatusListener::peerStatusUpdated
     *
     * @param peerHostname the host name for the connection
     * @param peerPort the port number for the connection
     * @param peerStatus the new status for the connection
     */
    virtual void peerStatusUpdated(const std::string &peerHostname,
                                   int peerPort,
                                   PeerStatus peerStatus);

    /**
     * Return the uplink object
     */
    VPP::Uplink &uplink();

    /**
     * Return the cross connect object
     */
    VPP::CrossConnect &crossConnect();

  private:
    /**
     * Handle changes to a forwarding domain; only deals with
     * cleaning up when these objects are removed.
     *
     * @param cid Class of the forwarding domain
     * @param domURI URI of the changed forwarding domain
     */
    void handleDomainUpdate(opflex::modb::class_id_t cid,
                            const opflex::modb::URI &domURI);

    /**
     * Compare and update changes in platform config
     *
     * @param configURI URI of the changed contract
     */
    void handleConfigUpdate(const opflex::modb::URI &configURI);

    /**
     * Handle changes to port-status for endpoints and endpoint groups.
     *
     * @param portName Name of the port that changed
     * @param portNo Port number of the port that changed
     */
    void handlePortStatusUpdate(const std::string &portName, uint32_t portNo);

    /**
     * Event listener override to get Interface events
     */
    void handle_interface_event(std::vector<VOM::interface::event> e);

    /**
     * Handle interface event in the task-queue context
     */
    void handleInterfaceEvent(std::vector<VOM::interface::event> e);

    /**
     * Handle the connect request to VPP
     */
    void handleInitConnection();

    /**
     * Handle a disconnect from VPP request
     */
    void handleCloseConnection();

    /**
     * Handle the connect request to VPP
     */
    void handleUplinkConfigure();

    /**
     * Handle the cross connect requests to VPP
     */
    void handleXConnectConfigure();

    /**
     * Handle the Vpp Boot request
     */
    void handleBoot();

    /**
     * Handle the Vpp sweep timeout
     */
    void handleSweepTimer(const boost::system::error_code &ec);

    /**
     * Handle the HW poll timeout
     */
    void handleHWPollTimer(const boost::system::error_code &ec);

    /**
     * Pull the HW stats
     */
    void handleHWStatsTimer(const boost::system::error_code &ec);

    /*
     * A collection of runtime data that is available to the other managers
     */
    Runtime m_runtime;

    /**
     * The internal task-queue for handling the async upates
     */
    opflexagent::TaskQueue m_task_queue;

    /**
     * The sweep boot state timer.
     *  This is a member here so it has access to the taskQ
     */
    std::unique_ptr<boost::asio::deadline_timer> m_sweep_timer;

    /**
     * CrossConnect interface manager
     */
    VPP::CrossConnect m_xconnect;

    /**
     * The HW poll timer
     */
    std::unique_ptr<boost::asio::deadline_timer> m_poll_timer;

    /**
     * The HW stats timer
     */
    std::unique_ptr<boost::asio::deadline_timer> m_stats_timer;

    /**
     * indicator this manager is stopping
     */
    volatile bool stopping;

    /**
     * indicator for hw liveness
     */
    bool hw_connected;

    void initPlatformConfig();

    /**
     * objects to delegate task queue events to
     */
    std::shared_ptr<EndPointManager> m_epm;
    std::shared_ptr<EndPointGroupManager> m_epgm;
    std::shared_ptr<SecurityGroupManager> m_sgm;
    std::shared_ptr<ContractManager> m_cm;
    std::shared_ptr<RouteManager> m_rdm;
    std::shared_ptr<ExtItfManager> m_eim;
};

} // namespace opflexagent

/*
 * Local Variables:
 * eval: (c-set-style "llvm.org")
 * End:
 */

#endif // VPPAGENT_VPPMANAGER_H_