aboutsummaryrefslogtreecommitdiffstats
path: root/src/include/VppRenderer.hpp
blob: e9182f46af7b181f518757c0b20900ccc1db7c33 (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
/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
 * Include file for VppRenderer
 *
 * Copyright (c) 2018 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
 */

#pragma once
#ifndef __VPP_RENDERER_H__
#define __VPP_RENDERER_H__

#include <boost/property_tree/ptree.hpp>

#include <opflex/ofcore/OFFramework.h>
#include <opflexagent/IdGenerator.h>
#include <opflexagent/Renderer.h>
#include <opflexagent/TunnelEpManager.h>

#include <vom/hw.hpp>

#include "VppInspect.hpp"
#include "VppManager.hpp"

using namespace opflexagent;

namespace VPP
{
/**
 * The vpp renderer demonstrates how to create a renderer plugin
 * for OpFlex agent.
 */
class VppRenderer : public opflexagent::Renderer
{
  public:
    /**
     * Instantiate a vpp renderer
     *
     * @param agent the agent object
     */
    VppRenderer(opflexagent::Agent &agent,
                IdGenerator &idGen,
                VppManager *vppManager);

    /**
     * Destroy the renderer and clean up all state
     */
    virtual ~VppRenderer();

    // ********
    // Renderer
    // ********

    virtual void setProperties(const boost::property_tree::ptree &properties);
    virtual void start();
    virtual void stop();

    /**
     * Is uplink address owned by renderer
     */
    virtual bool
    isUplinkAddressImplemented()
    {
        return true;
    }

    /**
     * Get uplink address from renderer
     */
    virtual boost::asio::ip::address getUplinkAddress();

    /**
     * Get uplink l2 address from renderer
     */
    virtual std::string getUplinkMac();

  private:
    /**
     * The socket used for inspecting the state built in VPP-manager
     */
    std::unique_ptr<VppInspect> inspector;

    /**
     * ID generator
     */
    IdGenerator &idGen;

    /**
     * Single instance of the VPP manager
     */
    VppManager *vppManager;

    /**
     * Opflex Tunnel EP Manager
     */
    TunnelEpManager tunnelEpManager;

    std::string uplinkIface;
    uint16_t uplinkVlan;

    enum EncapType
    {
        encapTypeNone,
        encapTypeVlan,
        encapTypeVxlan,
        encapTypeIvxlan
    };
    EncapType encapType;

    /**
     * has this party started.
     */
    bool started;
};

/**
 * Plugin implementation for dynamically loading vpp
 * renderer.
 */
class VppRendererPlugin : public opflexagent::RendererPlugin
{
  public:
    VppRendererPlugin();

    // **************
    // RendererPlugin
    // **************
    virtual std::unordered_set<std::string> getNames() const;
    virtual opflexagent::Renderer *create(opflexagent::Agent &agent) const;
};

} /* namespace vpprenderer */

/**
 * Return a non-owning pointer to the renderer plugin instance.
 */
extern "C" const opflexagent::RendererPlugin *init_renderer_plugin();

#endif /* __VPP__RENDERER_H__ */