FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
om.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <algorithm>
17 
18 #include "vom/om.hpp"
19 
20 namespace VOM {
21 client_db* OM::m_db;
22 
23 std::unique_ptr<OM::listener_list> OM::m_listeners;
24 
25 /**
26  * Initialse the connection to VPP
27  */
28 void
30 {
31  m_db = new client_db();
32 }
33 
34 void
36 {
37  /*
38  * Find if the object already stored on behalf of this key.
39  * and mark them stale
40  */
41  object_ref_list& objs = m_db->find(key);
42 
43  auto mark_obj = [](const object_ref& oref) { oref.mark(); };
44 
45  std::for_each(objs.begin(), objs.end(), mark_obj);
46 }
47 
48 void
50 {
51  /*
52  * Find if the object already stored on behalf of this key.
53  * and mark them stale
54  */
55  object_ref_list& objs = m_db->find(key);
56 
57  for (auto it = objs.begin(); it != objs.end();) {
58  if (it->stale()) {
59  it = objs.erase(it);
60  } else {
61  ++it;
62  }
63  }
64 
65  HW::write();
66 }
67 
68 void
70 {
71  /*
72  * Simply reset the list for this key. This will desctruct the
73  * object list and shared_ptrs therein. When the last shared_ptr
74  * goes the objects desctructor is called and the object is
75  * removed from OM
76  */
77  m_db->flush(key);
78 
79  HW::write();
80 }
81 
82 void
84 {
85  /*
86  * the listeners are sorted in dependency order
87  */
88  for (listener* l : *m_listeners) {
89  l->handle_replay();
90  }
91 
92  HW::write();
93 }
94 
95 void
96 OM::dump(const client_db::key_t& key, std::ostream& os)
97 {
98  m_db->dump(key, os);
99 }
100 
101 void
102 OM::dump(std::ostream& os)
103 {
104  m_db->dump(os);
105 }
106 
107 void
109 {
110  /*
111  * the listeners are sorted in dependency order
112  */
113  for (listener* l : *m_listeners) {
114  l->handle_populate(key);
115  }
116 
117  /*
118  * once we have it all, mark it stale.
119  */
120  mark(key);
121 }
122 
123 bool
125 {
126  if (!m_listeners) {
127  m_listeners.reset(new listener_list);
128  }
129 
130  m_listeners->insert(listener);
131 
132  return (true);
133 }
134 
136  : m_key(key)
137 {
138  OM::mark(m_key);
139 }
140 
142 {
143  OM::sweep(m_key);
144 }
145 }
146 
147 /*
148  * fd.io coding-style-patch-verification: ON
149  *
150  * Local Variables:
151  * eval: (c-set-style "mozilla")
152  * End:
153  */
static void init()
Init.
Definition: om.cpp:29
void dump(const key_t &key, std::ostream &os)
Print each of the object in the DB into the stream provided.
Definition: client_db.cpp:35
std::set< object_ref > object_ref_list
A convenitent typedef for set of objects owned.
Definition: client_db.hpp:32
object_ref_list & find(const key_t &k)
Find the objects owned by the key.
Definition: client_db.cpp:20
const std::string key_t
In the opflex world each entity is known by a URI which can be converted into a string.
Definition: client_db.hpp:51
void flush(const key_t &k)
flush, i.e.
Definition: client_db.cpp:26
static rc_t write()
Write/Execute all commands hitherto enqueued.
Definition: hw.cpp:225
A DB storing the objects that each owner/key owns.
Definition: client_db.hpp:39
A represenation of a reference to a VPP object.
Definition: object_base.hpp:86
static void remove(const client_db::key_t &key)
Remove all object in the OM referenced by the key.
Definition: om.cpp:69
static void mark(const client_db::key_t &key)
Mark all state owned by this key as stale.
Definition: om.cpp:35
Class definition for listeners to OM events.
Definition: om.hpp:284
static void sweep(const client_db::key_t &key)
Sweep all the key&#39;s objects that are stale.
Definition: om.cpp:49
mark_n_sweep(const client_db::key_t &key)
Constructor - will call mark on the key.
Definition: om.cpp:135
~mark_n_sweep()
Destructor - will call sweep on the key.
Definition: om.cpp:141
The VPP Object Model (VOM) library.
Definition: acl_binding.cpp:19
static void replay(void)
Replay all of the objects to HW.
Definition: om.cpp:83
static void dump(const client_db::key_t &key, std::ostream &os)
Print each of the object in the DB into the stream provided.
Definition: om.cpp:96
static void populate(const client_db::key_t &key)
populate the OM with state read from HW.
Definition: om.cpp:108
static bool register_listener(listener *listener)
Register a listener of events.
Definition: om.cpp:124