GBP: per-group EP retention policy
[vpp.git] / extras / vom / vom / gbp_endpoint_group_cmds.cpp
1 /*
2  * Copyright (c) 2018 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 "vom/gbp_endpoint_group_cmds.hpp"
17
18 namespace VOM {
19 namespace gbp_endpoint_group_cmds {
20
21 create_cmd::create_cmd(HW::item<bool>& item,
22                        epg_id_t epg_id,
23                        uint16_t sclass,
24                        uint32_t bd_id,
25                        route::table_id_t rd_id,
26                        const gbp_endpoint_group::retention_t& retention,
27                        const handle_t& itf)
28   : rpc_cmd(item)
29   , m_epg_id(epg_id)
30   , m_sclass(sclass)
31   , m_bd_id(bd_id)
32   , m_rd_id(rd_id)
33   , m_itf(itf)
34   , m_retention(retention)
35 {
36 }
37
38 bool
39 create_cmd::operator==(const create_cmd& other) const
40 {
41   return ((m_itf == other.m_itf) && (m_bd_id == other.m_bd_id) &&
42           (m_rd_id == other.m_rd_id) && (m_epg_id == other.m_epg_id) &&
43           (m_retention == other.m_retention));
44 }
45
46 rc_t
47 create_cmd::issue(connection& con)
48 {
49   msg_t req(con.ctx(), std::ref(*this));
50
51   auto& payload = req.get_request().get_payload();
52   payload.epg.uplink_sw_if_index = m_itf.value();
53   payload.epg.epg_id = m_epg_id;
54   payload.epg.sclass = m_sclass;
55   payload.epg.bd_id = m_bd_id;
56   payload.epg.rd_id = m_rd_id;
57   payload.epg.retention.remote_ep_timeout = m_retention.remote_ep_timeout;
58
59   VAPI_CALL(req.execute());
60
61   return (wait());
62 }
63
64 std::string
65 create_cmd::to_string() const
66 {
67   std::ostringstream s;
68   s << "gbp-endpoint-group-create: " << m_hw_item.to_string()
69     << " epg-id:" << m_epg_id << " bd-id:" << m_bd_id << " rd-id:" << m_rd_id
70     << " itf:" << m_itf;
71
72   return (s.str());
73 }
74
75 delete_cmd::delete_cmd(HW::item<bool>& item, epg_id_t epg_id)
76   : rpc_cmd(item)
77   , m_epg_id(epg_id)
78 {
79 }
80
81 bool
82 delete_cmd::operator==(const delete_cmd& other) const
83 {
84   return (m_epg_id == other.m_epg_id);
85 }
86
87 rc_t
88 delete_cmd::issue(connection& con)
89 {
90   msg_t req(con.ctx(), std::ref(*this));
91
92   auto& payload = req.get_request().get_payload();
93   payload.epg_id = m_epg_id;
94
95   VAPI_CALL(req.execute());
96
97   return (wait());
98 }
99
100 std::string
101 delete_cmd::to_string() const
102 {
103   std::ostringstream s;
104   s << "gbp-endpoint-group-delete: " << m_hw_item.to_string()
105     << " epg:" << m_epg_id;
106
107   return (s.str());
108 }
109
110 dump_cmd::dump_cmd()
111 {
112 }
113
114 bool
115 dump_cmd::operator==(const dump_cmd& other) const
116 {
117   return (true);
118 }
119
120 rc_t
121 dump_cmd::issue(connection& con)
122 {
123   m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
124
125   VAPI_CALL(m_dump->execute());
126
127   wait();
128
129   return rc_t::OK;
130 }
131
132 std::string
133 dump_cmd::to_string() const
134 {
135   return ("gbp-endpoint-group-dump");
136 }
137
138 }; // namespace gbp_endpoint_group_cmds
139 }; // namespace VOM
140
141 /*
142  * fd.io coding-style-patch-verification: ON
143  *
144  * Local Variables:
145  * eval: (c-set-style "mozilla")
146  * End:
147  */