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
|
/* -*- 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
*/
#include "VppIdGen.hpp"
#include <modelgbp/gbp/BridgeDomain.hpp>
#include <modelgbp/gbp/Contract.hpp>
#include <modelgbp/gbp/FloodDomain.hpp>
#include <modelgbp/gbp/L3ExternalNetwork.hpp>
#include <modelgbp/gbp/RoutingDomain.hpp>
namespace VPP
{
static const char *ID_NAMESPACES[] = {"floodDomain",
"bridgeDomain",
"routingDomain",
"contract",
"externalNetwork",
"secGroup",
"secGroupSet"};
static const char *ID_NMSPC_FD = ID_NAMESPACES[0];
static const char *ID_NMSPC_BD = ID_NAMESPACES[1];
static const char *ID_NMSPC_RD = ID_NAMESPACES[2];
static const char *ID_NMSPC_CON = ID_NAMESPACES[3];
static const char *ID_NMSPC_EXTNET = ID_NAMESPACES[4];
static const char *ID_NMSPC_SECGROUP = ID_NAMESPACES[5];
static const char *ID_NMSPC_SECGROUP_SET = ID_NAMESPACES[6];
IdGen::IdGen(opflexagent::IdGenerator &id_gen)
: m_id_gen(id_gen)
{
for (size_t i = 0; i < sizeof(ID_NAMESPACES) / sizeof(char *); i++)
{
/*
* start the namespace ID's at a non-zero offset so the
* default tables are never used.
*/
m_id_gen.initNamespace(ID_NAMESPACES[i], 100);
}
}
uint32_t
IdGen::get(opflex::modb::class_id_t cid, const opflex::modb::URI &uri)
{
return m_id_gen.getId(get_namespace(cid), uri.toString());
}
void
IdGen::erase(opflex::modb::class_id_t cid, const opflex::modb::URI &uri)
{
m_id_gen.erase(get_namespace(cid), uri.toString());
}
const char *
IdGen::get_namespace(opflex::modb::class_id_t cid)
{
const char *nmspc = NULL;
switch (cid)
{
case modelgbp::gbp::RoutingDomain::CLASS_ID:
nmspc = ID_NMSPC_RD;
break;
case modelgbp::gbp::BridgeDomain::CLASS_ID:
nmspc = ID_NMSPC_BD;
break;
case modelgbp::gbp::FloodDomain::CLASS_ID:
nmspc = ID_NMSPC_FD;
break;
case modelgbp::gbp::Contract::CLASS_ID:
nmspc = ID_NMSPC_CON;
break;
case modelgbp::gbp::L3ExternalNetwork::CLASS_ID:
nmspc = ID_NMSPC_EXTNET;
break;
default:
assert(false);
}
return nmspc;
}
} // namespace VPP
/*
* Local Variables:
* eval: (c-set-style "llvm.org")
* End:
*/
|