blob: fa9ecdafe80d1563ed10dc2adf7a1e6d597533b4 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
2 * Test suite for class VppOM
3 *
4 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
5 *
6 * This program and the accompanying materials are made available under the
7 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 */
10#define BOOST_TEST_MODULE "VPP OBJECT MODEL"
11#define BOOST_TEST_DYN_LINK
12
13#include <boost/test/unit_test.hpp>
14#include <boost/assign/list_inserter.hpp>
15
16
17#include <iostream>
18#include <deque>
19
20#include "vom/om.hpp"
21#include "vom/interface.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070022#include "vom/interface_cmds.hpp"
Mohsin Kazmied76ee22018-03-02 12:31:37 +010023#include "vom/bond_interface_cmds.hpp"
24#include "vom/bond_group_binding.hpp"
25#include "vom/bond_group_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070026#include "vom/l2_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070027#include "vom/l2_binding_cmds.hpp"
Neale Ranns53322002019-02-22 02:48:25 -080028#include "vom/l2_vtr_cmds.hpp"
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +020029#include "vom/l2_xconnect.hpp"
30#include "vom/l2_xconnect_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070031#include "vom/l3_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070032#include "vom/l3_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070033#include "vom/bridge_domain.hpp"
34#include "vom/bridge_domain_entry.hpp"
35#include "vom/bridge_domain_arp_entry.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070036#include "vom/bridge_domain_cmds.hpp"
37#include "vom/bridge_domain_entry_cmds.hpp"
38#include "vom/bridge_domain_arp_entry_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070039#include "vom/prefix.hpp"
40#include "vom/route.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070041#include "vom/route_cmds.hpp"
Neale Ranns7c03ed42018-12-27 03:21:28 -080042#include "vom/mroute_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070043#include "vom/route_domain.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070044#include "vom/route_domain_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070045#include "vom/vxlan_tunnel.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070046#include "vom/vxlan_tunnel_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070047#include "vom/sub_interface.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070048#include "vom/sub_interface_cmds.hpp"
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +010049#include "vom/acl_ethertype.hpp"
50#include "vom/acl_ethertype_cmds.hpp"
Neale Ranns5637e652019-02-22 00:44:40 -080051#include "vom/acl_l2_list.hpp"
52#include "vom/acl_l3_list.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070053#include "vom/acl_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070054#include "vom/acl_list_cmds.hpp"
55#include "vom/acl_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070056#include "vom/acl_l3_rule.hpp"
57#include "vom/acl_l2_rule.hpp"
58#include "vom/arp_proxy_config.hpp"
59#include "vom/arp_proxy_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070060#include "vom/arp_proxy_config_cmds.hpp"
61#include "vom/arp_proxy_binding_cmds.hpp"
Mohsin Kazmi12fe8782018-10-30 19:24:34 +010062#include "vom/igmp_binding.hpp"
63#include "vom/igmp_binding_cmds.hpp"
64#include "vom/igmp_listen.hpp"
65#include "vom/igmp_listen_cmds.hpp"
Mohsin Kazmie23edac2018-09-25 18:26:52 +020066#include "vom/ip_punt_redirect.hpp"
67#include "vom/ip_punt_redirect_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070068#include "vom/ip_unnumbered.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070069#include "vom/ip_unnumbered_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070070#include "vom/interface_ip6_nd.hpp"
71#include "vom/interface_span.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070072#include "vom/interface_span_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070073#include "vom/neighbour.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070074#include "vom/neighbour_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070075#include "vom/nat_static.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070076#include "vom/nat_static_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070077#include "vom/nat_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070078#include "vom/nat_binding_cmds.hpp"
Neale Ranns208c29a2018-04-11 08:08:30 -070079#include "vom/pipe.hpp"
80#include "vom/pipe_cmds.hpp"
Neale Rannsc17c1872019-07-23 01:48:55 -070081#include "vom/qos_mark.hpp"
82#include "vom/qos_mark_cmds.hpp"
83#include "vom/qos_map.hpp"
84#include "vom/qos_map_cmds.hpp"
85#include "vom/qos_record.hpp"
86#include "vom/qos_record_cmds.hpp"
Neale Ranns83832e72019-07-31 02:48:02 -070087#include "vom/qos_store.hpp"
88#include "vom/qos_store_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070089
90using namespace boost;
91using namespace VOM;
92
93/**
94 * An expectation exception
95 */
96class ExpException
97{
98public:
99 ExpException(unsigned int number)
100 {
101 // a neat place to add a break point
Neale Rannsb02d2302019-06-07 03:54:21 -0400102 // std::cout << " ExpException here: " << number << std::endl;
Neale Ranns812ed392017-10-16 04:20:13 -0700103 }
104};
105
106class MockListener : public interface::event_listener,
107 public interface::stat_listener
108{
Mohsin Kazmi51edc3a2018-11-21 19:00:46 +0100109 void handle_interface_stat(const interface& itf)
Neale Ranns812ed392017-10-16 04:20:13 -0700110 {
111 }
Neale Ranns193c47d2018-12-10 06:01:46 -0800112 void handle_interface_event(std::vector<VOM::interface::event> events)
Neale Ranns812ed392017-10-16 04:20:13 -0700113 {
114 }
115};
116
117class MockCmdQ : public HW::cmd_q
118{
119public:
120 MockCmdQ():
121 m_strict_order(true)
122 {
123 }
124 virtual ~MockCmdQ()
125 {
126 }
127 void expect(cmd *f)
128 {
129 m_exp_queue.push_back(f);
130 }
131 void enqueue(cmd *f)
132 {
133 m_act_queue.push_back(f);
134 }
135 void enqueue(std::queue<cmd*> &cmds)
136 {
137 while (cmds.size())
138 {
139 m_act_queue.push_back(cmds.front());
140 cmds.pop();
141 }
142 }
143 void enqueue(std::shared_ptr<cmd> f)
144 {
145 m_act_queue.push_back(f.get());
146 }
147
148 void dequeue(cmd *f)
149 {
150 }
151
152 void dequeue(std::shared_ptr<cmd> cmd)
153 {
154 }
155
156 void strict_order(bool on)
157 {
158 m_strict_order = on;
159 }
160
161 bool is_empty()
162 {
163 return ((0 == m_exp_queue.size()) &&
164 (0 == m_act_queue.size()));
165 }
166
167 rc_t write()
168 {
169 cmd *f_exp, *f_act;
170 rc_t rc = rc_t::OK;
171
172 while (m_act_queue.size())
173 {
174 bool matched = false;
175 auto it_exp = m_exp_queue.begin();
176 auto it_act = m_act_queue.begin();
177
178 f_act = *it_act;
179
180 std::cout << " Act: " << f_act->to_string() << std::endl;
181 while (it_exp != m_exp_queue.end())
182 {
183 f_exp = *it_exp;
184 try
185 {
186 std::cout << " Exp: " << f_exp->to_string() << std::endl;
187
188 if (typeid(*f_exp) != typeid(*f_act))
189 {
190 throw ExpException(1);
191 }
192
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700193 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700194 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700195 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700196 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700197 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700198 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700199 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700200 }
Neale Rannsb02d2302019-06-07 03:54:21 -0400201 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_create_cmd))
202 {
203 rc = handle_derived<interface_cmds::bvi_create_cmd>(f_exp, f_act);
204 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800205 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
206 {
207 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
208 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100209 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
210 {
211 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
212 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700213 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700214 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700215 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700216 }
Neale Rannsb02d2302019-06-07 03:54:21 -0400217 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_delete_cmd))
218 {
219 rc = handle_derived<interface_cmds::bvi_delete_cmd>(f_exp, f_act);
220 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700221 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700222 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700223 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700224 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800225 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
226 {
227 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
228 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100229 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
230 {
231 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
232 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700233 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700234 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700235 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700236 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700237 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700238 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700239 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700240 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700241 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700242 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700243 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700244 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700245 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
Neale Ranns812ed392017-10-16 04:20:13 -0700246 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700247 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700248 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100249 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
250 {
251 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
252 }
253 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
254 {
255 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
256 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700257 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700258 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700259 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700260 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700261 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700262 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700263 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700264 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700265 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700266 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700267 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700268 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700269 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700270 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700271 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700272 }
Neale Ranns7c03ed42018-12-27 03:21:28 -0800273 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
274 {
275 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
276 }
277 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
278 {
279 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
280 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700281 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700282 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700283 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700284 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700285 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700286 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700287 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700288 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700289 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700290 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700291 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700292 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700293 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700294 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700295 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700296 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700297 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700298 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700299 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700300 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700301 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700302 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700303 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700304 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700305 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700306 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700307 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700308 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700309 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700310 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700311 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700312 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700313 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700314 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700315 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700316 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700317 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700318 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700319 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700320 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700321 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700322 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700323 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700324 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700325 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700326 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700327 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700328 }
Neale Ranns53322002019-02-22 02:48:25 -0800329 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700330 {
Neale Ranns53322002019-02-22 02:48:25 -0800331 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700332 }
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +0200333 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
334 {
335 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
336 }
337 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
338 {
339 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
340 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700341 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700342 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700343 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700344 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700345 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700346 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700347 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700348 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700349 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700350 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700351 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700352 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700353 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700354 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700355 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700356 }
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +0100357 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
358 {
359 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
360 }
Mohsin Kazmi04def742018-03-07 19:53:51 +0100361 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
362 {
363 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
364 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700365 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700366 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700367 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700368 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700369 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700370 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700371 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700372 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700373 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700374 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700375 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700376 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700377 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700378 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700379 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700380 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700381 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700382 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700383 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700384 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700385 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700386 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700387 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700388 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700389 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700390 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700391 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700392 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700393 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700394 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700395 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700396 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700397 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700398 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700399 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700400 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700401 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700402 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700403 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700404 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700405 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700406 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700407 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700408 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700409 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700410 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700411 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700412 }
Mohsin Kazmi12fe8782018-10-30 19:24:34 +0100413 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
414 {
415 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
416 }
417 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
418 {
419 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
420 }
421 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
422 {
423 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
424 }
425 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
426 {
427 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
428 }
Mohsin Kazmie23edac2018-09-25 18:26:52 +0200429 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
430 {
431 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
432 }
433 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
434 {
435 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
436 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700437 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700438 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700439 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700440 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700441 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700442 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700443 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700444 }
445 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
446 {
447 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
448 }
449 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
450 {
451 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
452 }
453 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
454 {
455 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
456 }
457 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
458 {
459 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
460 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700461 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700462 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700463 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700464 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700465 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700466 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700467 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700468 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700469 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700470 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700471 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700472 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700473 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700474 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700475 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700476 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700477 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700478 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700479 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700480 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700481 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700482 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700483 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700484 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700485 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700486 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700487 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700488 }
Neale Ranns208c29a2018-04-11 08:08:30 -0700489 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
490 {
491 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
492 }
493 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
494 {
495 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
496 }
Neale Rannsc17c1872019-07-23 01:48:55 -0700497 else if (typeid(*f_exp) == typeid(QoS::mark_cmds::create_cmd))
498 {
499 rc = handle_derived<QoS::mark_cmds::create_cmd>(f_exp, f_act);
500 }
501 else if (typeid(*f_exp) == typeid(QoS::mark_cmds::delete_cmd))
502 {
503 rc = handle_derived<QoS::mark_cmds::delete_cmd>(f_exp, f_act);
504 }
505 else if (typeid(*f_exp) == typeid(QoS::record_cmds::create_cmd))
506 {
507 rc = handle_derived<QoS::record_cmds::create_cmd>(f_exp, f_act);
508 }
509 else if (typeid(*f_exp) == typeid(QoS::record_cmds::delete_cmd))
510 {
511 rc = handle_derived<QoS::record_cmds::delete_cmd>(f_exp, f_act);
512 }
Neale Ranns83832e72019-07-31 02:48:02 -0700513 else if (typeid(*f_exp) == typeid(QoS::store_cmds::create_cmd))
514 {
515 rc = handle_derived<QoS::store_cmds::create_cmd>(f_exp, f_act);
516 }
517 else if (typeid(*f_exp) == typeid(QoS::store_cmds::delete_cmd))
518 {
519 rc = handle_derived<QoS::store_cmds::delete_cmd>(f_exp, f_act);
520 }
Neale Rannsc17c1872019-07-23 01:48:55 -0700521 else if (typeid(*f_exp) == typeid(QoS::map_cmds::create_cmd))
522 {
523 rc = handle_derived<QoS::map_cmds::create_cmd>(f_exp, f_act);
524 }
525 else if (typeid(*f_exp) == typeid(QoS::map_cmds::delete_cmd))
526 {
527 rc = handle_derived<QoS::map_cmds::delete_cmd>(f_exp, f_act);
528 }
Neale Ranns812ed392017-10-16 04:20:13 -0700529 else
530 {
531 throw ExpException(2);
532 }
533
534 // if we get here then we found the match.
535 m_exp_queue.erase(it_exp);
536 m_act_queue.erase(it_act);
537 delete f_exp;
538 delete f_act;
539
540 // return any injected failures to the agent
541 if (rc_t::OK != rc && rc_t::NOOP != rc)
542 {
543 return (rc);
544 }
545
546 matched = true;
547 break;
548 }
549 catch (ExpException &e)
550 {
551 // The expected and actual do not match
552 if (m_strict_order)
553 {
554 // in strict ordering mode this is fatal, so rethrow
555 throw e;
556 }
557 else
558 {
559 // move the iterator onto the next in the expected list and
560 // check for a match
561 ++it_exp;
562 }
563 }
564 }
565
566 if (!matched)
567 throw ExpException(3);
568 }
569
570 return (rc);
571 }
572private:
573
574 template <typename T>
575 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
576 {
577 const T *i_exp;
578 T *i_act;
579
580 i_exp = dynamic_cast<const T*>(f_exp);
581 i_act = dynamic_cast<T*>(f_act);
582 if (!(*i_exp == *i_act))
583 {
584 throw ExpException(4);
585 }
586 // pass the data and return code to the agent
587 i_act->item() = i_exp->item();
588
589 return (i_act->item().rc());
590 }
591
592 // The Q to push the expectations on
593 std::deque<cmd*> m_exp_queue;
594
595 // the queue to push the actual events on
596 std::deque<cmd*> m_act_queue;
597
598 // control whether the expected queue is strictly ordered.
599 bool m_strict_order;
600};
601
602class VppInit {
603public:
604 std::string name;
605 MockCmdQ *f;
606
607 VppInit()
608 : name("vpp-ut"),
609 f(new MockCmdQ())
610 {
611 HW::init(f);
612 OM::init();
613 logger().set(log_level_t::DEBUG);
614 }
615
616 ~VppInit() {
617 delete f;
618 }
619};
620
Neale Rannsd3464b52017-12-07 08:48:02 -0800621BOOST_AUTO_TEST_SUITE(vom)
Neale Ranns812ed392017-10-16 04:20:13 -0700622
623#define TRY_CHECK_RC(stmt) \
624{ \
625 try { \
626 BOOST_CHECK(rc_t::OK == stmt); \
627 } \
628 catch (ExpException &e) \
629 { \
630 BOOST_CHECK(false); \
631 } \
632 BOOST_CHECK(vi.f->is_empty()); \
633}
634
635#define TRY_CHECK(stmt) \
636{ \
637 try { \
638 stmt; \
639 } \
640 catch (ExpException &e) \
641 { \
642 BOOST_CHECK(false); \
643 } \
644 BOOST_CHECK(vi.f->is_empty()); \
645}
646
647#define ADD_EXPECT(stmt) \
648 vi.f->expect(new stmt)
649
650#define STRICT_ORDER_OFF() \
651 vi.f->strict_order(false)
652
653BOOST_AUTO_TEST_CASE(test_interface) {
654 VppInit vi;
655 const std::string go = "GeorgeOrwell";
656 const std::string js = "JohnSteinbeck";
657 rc_t rc = rc_t::OK;
658
659 /*
660 * George creates and deletes the interface
661 */
662 std::string itf1_name = "afpacket1";
663 interface itf1(itf1_name,
664 interface::type_t::AFPACKET,
665 interface::admin_state_t::UP);
666
667 /*
668 * set the expectation for a afpacket interface create.
669 * 2 is the interface handle VPP [mock] assigns
670 */
671 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700672 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700673
674 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700675 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700676
677 TRY_CHECK_RC(OM::write(go, itf1));
678
679 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700680 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
681 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700682
683 TRY_CHECK(OM::remove(go));
684
685 /*
686 * George creates the interface, then John brings it down.
687 * George's remove is a no-op, sice John also owns the interface
688 */
689 interface itf1b(itf1_name,
690 interface::type_t::AFPACKET,
691 interface::admin_state_t::DOWN);
692
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700693 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
694 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700695 TRY_CHECK_RC(OM::write(go, itf1));
696
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700697 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700698 TRY_CHECK_RC(OM::write(js, itf1b));
699
700 TRY_CHECK(OM::remove(go));
701
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700702 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700703 TRY_CHECK(OM::remove(js));
704
705 /*
706 * George adds an interface, then we flush all of Geroge's state
707 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700708 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
709 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700710 TRY_CHECK_RC(OM::write(go, itf1));
711
712 TRY_CHECK(OM::mark(go));
713
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700714 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
715 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700716 TRY_CHECK(OM::sweep(go));
717
718 /*
719 * George adds an interface. mark stale. update the same interface. sweep
720 * and expect no delete
721 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700722 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
723 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700724 TRY_CHECK_RC(OM::write(go, itf1b));
725
726 TRY_CHECK(OM::mark(go));
727
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700728 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700729 TRY_CHECK_RC(OM::write(go, itf1));
730
731 TRY_CHECK(OM::sweep(go));
732
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700733 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
734 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700735 TRY_CHECK(OM::remove(go));
736
737 /*
738 * George adds an insterface, then we mark that state. Add a second interface
739 * an flush the first that is now stale.
740 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700741 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
742 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700743 TRY_CHECK_RC(OM::write(go, itf1));
744
745 TRY_CHECK(OM::mark(go));
746
747 std::string itf2_name = "afpacket2";
Neale Ranns4ef42262018-02-20 08:10:44 -0800748 std::string itf2_tag = "uuid-of-afpacket2-interface";
Neale Ranns812ed392017-10-16 04:20:13 -0700749 interface itf2(itf2_name,
750 interface::type_t::AFPACKET,
Neale Ranns4ef42262018-02-20 08:10:44 -0800751 interface::admin_state_t::UP,
752 itf2_tag);
Neale Ranns812ed392017-10-16 04:20:13 -0700753 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
754
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700755 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
Neale Ranns4ef42262018-02-20 08:10:44 -0800756 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700757 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700758 TRY_CHECK_RC(OM::write(go, itf2));
759
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700760 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
761 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700762 TRY_CHECK(OM::sweep(go));
763
764 TRY_CHECK(OM::mark(go));
765
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700766 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
767 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700768 TRY_CHECK(OM::sweep(go));
Neale Ranns4ef42262018-02-20 08:10:44 -0800769
770
771 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
772 std::string itf3_tag = "uuid-of-vhost_user1-interface";
773 interface itf3(itf3_name,
774 interface::type_t::VHOST,
775 interface::admin_state_t::UP,
776 itf3_tag);
777 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
778
779 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
780 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
781 TRY_CHECK_RC(OM::write(go, itf3));
782
783 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
784 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
785 TRY_CHECK(OM::remove(go));
Neale Ranns812ed392017-10-16 04:20:13 -0700786}
787
788BOOST_AUTO_TEST_CASE(test_bvi) {
789 VppInit vi;
790 const std::string ernest = "ErnestHemmingway";
791 const std::string graham = "GrahamGreene";
792 rc_t rc = rc_t::OK;
793 l3_binding *l3;
794
795 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
796 rc_t::OK);
797 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
798 rc_t::OK);
799
800 /*
801 * Enrest creates a BVI with address 10.10.10.10/24
802 */
803 route::prefix_t pfx_10("10.10.10.10", 24);
804
805 const std::string bvi_name = "bvi1";
806 interface itf(bvi_name,
807 interface::type_t::BVI,
808 interface::admin_state_t::UP);
809 HW::item<handle_t> hw_ifh(4, rc_t::OK);
810 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
811
Neale Rannsb02d2302019-06-07 03:54:21 -0400812 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh, bvi_name));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700813 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
814 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700815 TRY_CHECK_RC(OM::write(ernest, itf));
816
817 l3 = new l3_binding(itf, pfx_10);
818 HW::item<bool> hw_l3_bind(true, rc_t::OK);
819 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700820 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700821 TRY_CHECK_RC(OM::write(ernest, *l3));
822
823 // change the MAC address on the BVI
824 interface itf_new_mac(bvi_name,
825 interface::type_t::BVI,
826 interface::admin_state_t::UP);
827 l2_address_t l2_addr({0,1,2,3,4,5});
828 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
829 itf_new_mac.set(l2_addr);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700830 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700831 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
832
833 // create/write the interface to the OM again but with an unset MAC
834 // this should not generate a MAC address update
835 TRY_CHECK_RC(OM::write(ernest, itf));
836
837 // change the MAC address on the BVI - again
838 interface itf_new_mac2(bvi_name,
839 interface::type_t::BVI,
840 interface::admin_state_t::UP);
841 l2_address_t l2_addr2({0,1,2,3,4,6});
842 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
843 itf_new_mac2.set(l2_addr2);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700844 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700845 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
846
847 delete l3;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700848 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
849 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Rannsb02d2302019-06-07 03:54:21 -0400850 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700851 TRY_CHECK(OM::remove(ernest));
852
853 /*
854 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
855 */
856 route_domain rd(1);
857 HW::item<bool> hw_rd4_create(true, rc_t::OK);
858 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
859 HW::item<bool> hw_rd6_create(true, rc_t::OK);
860 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
861 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
862 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
863 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
864 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700865 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
866 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700867 TRY_CHECK_RC(OM::write(graham, rd));
868
869 const std::string bvi2_name = "bvi2";
870 interface *itf2 = new interface(bvi2_name,
871 interface::type_t::BVI,
872 interface::admin_state_t::UP,
873 rd);
874 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
875
Neale Rannsb02d2302019-06-07 03:54:21 -0400876 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh2, bvi2_name));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700877 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
879 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
880 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700881
882 TRY_CHECK_RC(OM::write(graham, *itf2));
883
884 l3 = new l3_binding(*itf2, pfx_10);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700885 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700886 TRY_CHECK_RC(OM::write(graham, *l3));
887
888 delete l3;
889 delete itf2;
890
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700891 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
892 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
893 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
894 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
Neale Rannsb02d2302019-06-07 03:54:21 -0400895 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh2));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700896 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
897 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700898 TRY_CHECK(OM::remove(graham));
899}
900
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100901BOOST_AUTO_TEST_CASE(test_bond) {
902 VppInit vi;
903 const std::string cb = "CarolBerg";
904 rc_t rc = rc_t::OK;
905
906 /*
907 * creates the interfaces
908 */
909 std::string itf1_name = "afpacket1";
910 interface itf1(itf1_name,
911 interface::type_t::AFPACKET,
912 interface::admin_state_t::UP);
913
914 HW::item<handle_t> hw_ifh(2, rc_t::OK);
915 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
916
917 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
918 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
919
920 TRY_CHECK_RC(OM::write(cb, itf1));
921
922 std::string itf2_name = "afpacket2";
923 interface itf2(itf2_name,
924 interface::type_t::AFPACKET,
925 interface::admin_state_t::UP);
926
927
928 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
929 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
930 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
931
932 TRY_CHECK_RC(OM::write(cb, itf2));
933
934 std::string bond_name = "bond";
935 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
936 bond_interface::mode_t::LACP);
937
938 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
939 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
940 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
941 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
942
943 TRY_CHECK_RC(OM::write(cb, bond_itf));
944
945 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
946 bond_member::rate_t::SLOW);
947 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
948 bond_member::rate_t::SLOW);
949 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
950
951 HW::item<bool> bond_hw_bind(true, rc_t::OK);
952 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
953 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
954
955 TRY_CHECK_RC(OM::write(cb, *bgb));
956
957 delete bgb;
958 delete bm2;
959 delete bm1;
960
961 STRICT_ORDER_OFF();
962 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
963 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
964 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
965 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
966 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
967 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
968 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
969 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
970 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
971
972 TRY_CHECK(OM::remove(cb));
973}
974
Neale Ranns812ed392017-10-16 04:20:13 -0700975BOOST_AUTO_TEST_CASE(test_bridge) {
976 VppInit vi;
977 const std::string franz = "FranzKafka";
978 const std::string dante = "Dante";
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100979 const std::string jkr = "jkrowling";
Neale Ranns812ed392017-10-16 04:20:13 -0700980 rc_t rc = rc_t::OK;
981
982 /*
983 * Franz creates an interface, Bridge-domain, then binds the two
984 */
985
986 // interface create
987 std::string itf1_name = "afpacket1";
988 interface itf1(itf1_name,
989 interface::type_t::AFPACKET,
990 interface::admin_state_t::UP);
991
992 HW::item<handle_t> hw_ifh(3, rc_t::OK);
993 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
994 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700995 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
996 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700997
998 TRY_CHECK_RC(OM::write(franz, itf1));
999
1000 // bridge-domain create
1001 bridge_domain bd1(33);
1002
1003 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001004 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1005 bridge_domain::learning_mode_t::ON,
1006 bridge_domain::arp_term_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -04001007 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -07001008 bridge_domain::flood_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -04001009 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -07001010 bridge_domain::mac_age_mode_t::OFF));
Neale Ranns812ed392017-10-16 04:20:13 -07001011
1012 TRY_CHECK_RC(OM::write(franz, bd1));
1013
1014 // L2-interface create and bind
1015 // this needs to be delete'd before the flush below, since it too maintains
1016 // references to the BD and Interface
1017 l2_binding *l2itf = new l2_binding(itf1, bd1);
1018 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1019
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001020 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1021 hw_ifh.data(),
1022 hw_bd.data(),
1023 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -07001024 TRY_CHECK_RC(OM::write(franz, *l2itf));
1025
1026 /*
1027 * Dante adds an interface to the same BD
1028 */
1029 std::string itf2_name = "afpacket2";
1030 interface itf2(itf2_name,
1031 interface::type_t::AFPACKET,
1032 interface::admin_state_t::UP);
1033
1034 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001035 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1036 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001037 TRY_CHECK_RC(OM::write(dante, itf2));
1038
1039 // BD add is a no-op since it exists
1040 TRY_CHECK_RC(OM::write(dante, bd1));
1041
1042 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
Neale Ranns53322002019-02-22 02:48:25 -08001043 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
1044 l2itf2->set(l2_vtr::option_t::POP_1, 68);
Neale Ranns812ed392017-10-16 04:20:13 -07001045
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001046 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1047 hw_ifh2.data(),
1048 hw_bd.data(),
1049 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns53322002019-02-22 02:48:25 -08001050 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
Neale Ranns812ed392017-10-16 04:20:13 -07001051 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1052
1053 // Add some static entries to the bridge-domain
1054 HW::item<bool> hw_be1(true, rc_t::OK);
1055 mac_address_t mac1({0,1,2,3,4,5});
1056 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001057 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1058 false));
Neale Ranns812ed392017-10-16 04:20:13 -07001059 TRY_CHECK_RC(OM::write(dante, *be1));
1060
1061 // Add some entries to the bridge-domain ARP termination table
1062 HW::item<bool> hw_bea1(true, rc_t::OK);
1063 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1064
Neale Rannsfd920602017-11-23 12:15:00 -08001065 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001066 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
Neale Ranns812ed392017-10-16 04:20:13 -07001067 TRY_CHECK_RC(OM::write(dante, *bea1));
1068
1069 // flush Franz's state
1070 delete l2itf;
1071 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1072 rc_t::OK);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001073 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1074 hw_ifh.data(),
1075 hw_bd.data(),
1076 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001077 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1078 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001079 TRY_CHECK(OM::remove(franz));
1080
1081 // flush Dante's state - the order the interface and BD are deleted
1082 // is an uncontrollable artifact of the C++ object destruction.
1083 delete l2itf2;
1084 delete be1;
1085 delete bea1;
1086 STRICT_ORDER_OFF();
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001087 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1088 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001089 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1090 hw_ifh2.data(),
1091 hw_bd.data(),
1092 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001093
1094 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001095 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1096 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001097 TRY_CHECK(OM::remove(dante));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001098
1099 // test the BVI entry in l2fib
1100 bridge_domain bd2(99);
1101
1102 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001103 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1104 bridge_domain::learning_mode_t::ON,
1105 bridge_domain::arp_term_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -04001106 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -07001107 bridge_domain::flood_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -04001108 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -07001109 bridge_domain::mac_age_mode_t::OFF));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001110
1111 TRY_CHECK_RC(OM::write(jkr, bd2));
1112
1113 std::string itf3_name = "bvi";
1114 interface itf3(itf3_name,
1115 interface::type_t::BVI,
1116 interface::admin_state_t::UP);
1117
1118 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
Neale Rannsb02d2302019-06-07 03:54:21 -04001119 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh3, itf3_name));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001120 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1121 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1122 TRY_CHECK_RC(OM::write(jkr, itf3));
1123
1124 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001125 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1126 hw_ifh3.data(),
1127 hw_bd2.data(),
1128 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001129 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1130
1131 HW::item<bool> hw_be2(true, rc_t::OK);
1132 mac_address_t mac2({0,1,2,3,4,5});
1133 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1134 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1135 TRY_CHECK_RC(OM::write(jkr, *be2));
1136
1137 delete l2itf3;
1138 delete be2;
1139 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001140 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1141 hw_ifh3.data(),
1142 hw_bd2.data(),
1143 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001144 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1145 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
Neale Rannsb02d2302019-06-07 03:54:21 -04001146 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh3));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001147 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1148 TRY_CHECK(OM::remove(jkr));
Neale Ranns812ed392017-10-16 04:20:13 -07001149}
1150
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +02001151BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1152 VppInit vi;
1153 const std::string nicholas = "NicholasAbercrombie";
1154 rc_t rc = rc_t::OK;
1155
1156 /*
1157 * Interface 1
1158 */
1159 std::string itf1_name = "host1";
1160 interface itf1(itf1_name,
1161 interface::type_t::AFPACKET,
1162 interface::admin_state_t::UP);
1163 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1164 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1165 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1166 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1167 TRY_CHECK_RC(OM::write(nicholas, itf1));
1168
1169 /*
1170 * Interface 2
1171 */
1172 std::string itf2_name = "host2";
1173 interface itf2(itf2_name,
1174 interface::type_t::AFPACKET,
1175 interface::admin_state_t::UP);
1176
1177 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1178 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1179 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1180 TRY_CHECK_RC(OM::write(nicholas, itf2));
1181
1182 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1183 HW::item<bool> xconnect_east(true, rc_t::OK);
1184 HW::item<bool> xconnect_west(true, rc_t::OK);
1185 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1186 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1187 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1188 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1189 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1190
1191 delete l2_xconn;
1192
1193 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1194 STRICT_ORDER_OFF();
1195 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1196 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1197 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1198 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1199 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1200 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1201
1202 TRY_CHECK(OM::remove(nicholas));
1203}
1204
Neale Ranns812ed392017-10-16 04:20:13 -07001205BOOST_AUTO_TEST_CASE(test_vxlan) {
1206 VppInit vi;
1207 const std::string franz = "FranzKafka";
1208 rc_t rc = rc_t::OK;
1209
1210 /*
1211 * Franz creates an interface, Bridge-domain, then binds the two
1212 */
1213
1214 // VXLAN create
1215 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
Neale Ranns25b04942018-04-04 09:34:50 -07001216 boost::asio::ip::address::from_string("10.10.10.11"),
1217 322);
Neale Ranns812ed392017-10-16 04:20:13 -07001218
1219 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1220
1221 HW::item<handle_t> hw_vxt(3, rc_t::OK);
Neale Rannscf3ecb12018-12-11 08:40:20 -08001222 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1223 handle_t::INVALID));
Neale Ranns812ed392017-10-16 04:20:13 -07001224
1225 TRY_CHECK_RC(OM::write(franz, vxt));
1226
1227 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001228 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1229 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001230 bridge_domain::arp_ufwd_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001231 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001232 bridge_domain::uu_flood_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001233 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001234
1235 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001236 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1237 bridge_domain::learning_mode_t::OFF,
1238 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001239 bridge_domain::arp_ufwd_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001240 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001241 bridge_domain::uu_flood_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001242 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001243
1244 TRY_CHECK_RC(OM::write(franz, bd1));
1245
1246 // L2-interface create and bind
1247 // this needs to be delete'd before the flush below, since it too maintains
1248 // references to the BD and Interface
1249 l2_binding *l2itf = new l2_binding(vxt, bd1);
1250 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1251
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001252 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1253 hw_vxt.data(),
1254 hw_bd.data(),
1255 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -07001256 TRY_CHECK_RC(OM::write(franz, *l2itf));
1257
1258 // flush Franz's state
1259 delete l2itf;
1260 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1261 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001262 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1263 hw_vxt.data(),
1264 hw_bd.data(),
1265 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001266 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1267 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001268 TRY_CHECK(OM::remove(franz));
1269}
1270
1271BOOST_AUTO_TEST_CASE(test_vlan) {
1272 VppInit vi;
1273 const std::string noam = "NoamChomsky";
1274 rc_t rc = rc_t::OK;
1275
1276 std::string itf1_name = "host1";
1277 interface itf1(itf1_name,
1278 interface::type_t::AFPACKET,
1279 interface::admin_state_t::UP);
1280
1281 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001282 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001283
1284 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001285 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001286
1287 TRY_CHECK_RC(OM::write(noam, itf1));
1288
1289 sub_interface *vl33 = new sub_interface(itf1,
1290 interface::admin_state_t::UP,
1291 33);
1292
1293 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001294 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1295 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001296
1297 TRY_CHECK_RC(OM::write(noam, *vl33));
1298
1299 delete vl33;
1300 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1301 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001302 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1303 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1304 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1305 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001306
1307 TRY_CHECK(OM::remove(noam));
1308}
1309
1310BOOST_AUTO_TEST_CASE(test_acl) {
1311 VppInit vi;
1312 const std::string fyodor = "FyodorDostoyevsky";
1313 const std::string leo = "LeoTolstoy";
1314 rc_t rc = rc_t::OK;
1315
1316 /*
1317 * Fyodor adds an ACL in the input direction
1318 */
1319 std::string itf1_name = "host1";
1320 interface itf1(itf1_name,
1321 interface::type_t::AFPACKET,
1322 interface::admin_state_t::UP);
1323 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1324 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001325 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1326 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001327 TRY_CHECK_RC(OM::write(fyodor, itf1));
1328
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001329 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1330 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1331 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1332 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1333 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1334 HW::item<bool> ae_binding(true, rc_t::OK);
1335 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1336 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1337
Neale Ranns812ed392017-10-16 04:20:13 -07001338 route::prefix_t src("10.10.10.10", 32);
1339 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1340 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1341
1342 std::string acl_name = "acl1";
1343 ACL::l3_list acl1(acl_name);
1344 acl1.insert(r2);
1345 acl1.insert(r1);
1346 ACL::l3_list::rules_t rules = {r1, r2};
1347
1348 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001349 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001350 TRY_CHECK_RC(OM::write(fyodor, acl1));
1351
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001352 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1353 ACL::l3_list acl2(acl_name);
1354 acl2.insert(r3);
1355 ACL::l3_list::rules_t rules2 = {r3};
1356 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1357 TRY_CHECK_RC(OM::write(fyodor, acl2));
1358
Neale Ranns812ed392017-10-16 04:20:13 -07001359 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1360 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001361 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1362 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001363 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1364
1365 /**
1366 * Leo adds an L2 ACL in the output direction
1367 */
1368 TRY_CHECK_RC(OM::write(leo, itf1));
1369
1370 std::string l2_acl_name = "l2_acl1";
1371 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1372 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1373 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1374 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1375
1376 ACL::l2_list l2_acl(l2_acl_name);
1377 l2_acl.insert(l2_r2);
1378 l2_acl.insert(l2_r1);
1379
1380 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1381
1382 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001383 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001384 TRY_CHECK_RC(OM::write(leo, l2_acl));
1385
1386 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1387 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001388 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001389 hw_ifh.data(), l2_hw_acl.data()));
1390 TRY_CHECK_RC(OM::write(leo, *l2b));
1391
1392 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001393 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1394 hw_ifh.data(), l2_hw_acl.data()));
1395 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001396 TRY_CHECK(OM::remove(leo));
1397
1398 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001399 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001400 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1401 rc_t::OK);
1402 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001403 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001404 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001405 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001406 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001407 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1408 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001409
1410 TRY_CHECK(OM::remove(fyodor));
1411}
1412
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001413BOOST_AUTO_TEST_CASE(test_igmp) {
1414 VppInit vi;
1415 const std::string Isaiah = "IsaiahBerlin";
1416 rc_t rc = rc_t::OK;
1417
Ole Troan003d5da2018-12-18 12:23:13 +01001418 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1419 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1420 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001421
1422 std::string itf3_name = "host3";
1423 interface itf3(itf3_name,
1424 interface::type_t::AFPACKET,
1425 interface::admin_state_t::UP);
1426 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1427 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1428 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1429 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1430 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1431
1432 igmp_binding *ib = new igmp_binding(itf3);
1433 HW::item<bool> hw_binding(true, rc_t::OK);
1434 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1435 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1436
1437 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1438
1439 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1440 HW::item<bool> hw_as_listen(true, rc_t::OK);
1441 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1442 TRY_CHECK_RC(OM::write(Isaiah, *il));
1443
1444 delete il;
1445 delete ib;
1446
1447 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1448 rc_t::OK);
1449 STRICT_ORDER_OFF();
1450 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1451 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1452 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1453 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1454
1455 TRY_CHECK(OM::remove(Isaiah));
1456}
1457
Neale Ranns812ed392017-10-16 04:20:13 -07001458BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1459 VppInit vi;
1460 const std::string kurt = "KurtVonnegut";
1461 rc_t rc = rc_t::OK;
1462
1463 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1464 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1465
1466 arp_proxy_config ap(low, high);
1467 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001468 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001469 TRY_CHECK_RC(OM::write(kurt, ap));
1470
1471 std::string itf3_name = "host3";
1472 interface itf3(itf3_name,
1473 interface::type_t::AFPACKET,
1474 interface::admin_state_t::UP);
1475 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1476 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001477 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1478 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001479 TRY_CHECK_RC(OM::write(kurt, itf3));
1480
Neale Ranns0053de62018-05-22 08:40:52 -07001481 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001482 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001483 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001484 TRY_CHECK_RC(OM::write(kurt, *apb));
1485
1486 delete apb;
1487
1488 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1489 rc_t::OK);
1490 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001491 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1492 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1493 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1494 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001495
1496 TRY_CHECK(OM::remove(kurt));
1497}
1498
Mohsin Kazmie23edac2018-09-25 18:26:52 +02001499BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1500 VppInit vi;
1501 const std::string eliot = "EliotReed";
1502 rc_t rc = rc_t::OK;
1503
1504 /*
1505 * Interface 1 is the tx interface
1506 */
1507 std::string itf1_name = "tx-itf";
1508 interface itf1(itf1_name,
1509 interface::type_t::AFPACKET,
1510 interface::admin_state_t::UP);
1511 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1512 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1513 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1514 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1515 TRY_CHECK_RC(OM::write(eliot, itf1));
1516
1517 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1518
1519 /*
1520 * Interface 2 is the rx interface
1521 */
1522 std::string itf2_name = "rx-itf";
1523 interface itf2(itf2_name,
1524 interface::type_t::AFPACKET,
1525 interface::admin_state_t::UP);
1526
1527 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1528 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1529 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1530 TRY_CHECK_RC(OM::write(eliot, itf2));
1531
1532 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1533 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1534 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1535 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1536 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1537
1538 delete ip_punt;
1539
1540 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1541 STRICT_ORDER_OFF();
1542 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1543 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1544 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1545 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1546 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1547
1548 TRY_CHECK(OM::remove(eliot));
1549}
1550
Neale Ranns812ed392017-10-16 04:20:13 -07001551BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1552 VppInit vi;
1553 const std::string eric = "EricAmbler";
1554 rc_t rc = rc_t::OK;
1555
1556 /*
1557 * Interface 1 has the L3 address
1558 */
1559 std::string itf1_name = "host1";
1560 interface itf1(itf1_name,
1561 interface::type_t::AFPACKET,
1562 interface::admin_state_t::UP);
1563 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1564 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001565 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1566 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001567 TRY_CHECK_RC(OM::write(eric, itf1));
1568
1569 route::prefix_t pfx_10("10.10.10.10", 24);
1570 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1571 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1572 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001573 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001574 TRY_CHECK_RC(OM::write(eric, *l3));
1575
1576 /*
1577 * Interface 2 is unnumbered
1578 */
1579 std::string itf2_name = "host2";
1580 interface itf2(itf2_name,
1581 interface::type_t::AFPACKET,
1582 interface::admin_state_t::UP);
1583
1584 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001585 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1586 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001587 TRY_CHECK_RC(OM::write(eric, itf2));
1588
1589 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1590 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1591 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001592 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001593 TRY_CHECK_RC(OM::write(eric, *ipun));
1594
1595 delete l3;
1596 delete ipun;
1597
1598 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1599 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001600 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1601 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1602 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1603 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1604 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1605 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001606
1607 TRY_CHECK(OM::remove(eric));
1608}
1609
1610BOOST_AUTO_TEST_CASE(test_ip6nd) {
1611 VppInit vi;
1612 const std::string paulo = "PauloCoelho";
1613 rc_t rc = rc_t::OK;
1614
1615 /*
1616 * ra config
1617 */
1618 std::string itf_name = "host_ip6nd";
1619 interface itf(itf_name,
1620 interface::type_t::AFPACKET,
1621 interface::admin_state_t::UP);
1622 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1623 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001624 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1625 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001626 TRY_CHECK_RC(OM::write(paulo, itf));
1627
1628 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1629 l3_binding *l3 = new l3_binding(itf, pfx_10);
1630 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1631 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001632 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001633 TRY_CHECK_RC(OM::write(paulo, *l3));
1634
1635 ra_config ra(0, 1, 0, 4);
1636 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1637 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1638 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1639 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1640 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1641
1642 /*
1643 * ra prefix
1644 */
1645 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1646 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1647 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1648 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1649 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1650 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1651
1652 delete ip6pfx;
1653
1654 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1655
1656 delete ip6ra;
1657 delete l3;
1658
1659 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1660
1661 STRICT_ORDER_OFF();
1662 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001663 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1664 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1665 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001666
1667 TRY_CHECK(OM::remove(paulo));
1668}
1669
1670BOOST_AUTO_TEST_CASE(test_interface_span) {
1671 VppInit vi;
1672 const std::string elif = "ElifShafak";
1673 rc_t rc = rc_t::OK;
1674
1675 /*
1676 * Interface 1 to be mirrored
1677 */
1678 std::string itf1_name = "port-from";
1679 interface itf1(itf1_name,
1680 interface::type_t::AFPACKET,
1681 interface::admin_state_t::UP);
1682 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1683 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001684 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1685 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001686 TRY_CHECK_RC(OM::write(elif, itf1));
1687
1688 /*
1689 * Interface 2 where traffic is mirrored
1690 */
1691 std::string itf2_name = "port-to";
1692 interface itf2(itf2_name,
1693 interface::type_t::AFPACKET,
1694 interface::admin_state_t::UP);
1695
1696 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1697 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1698
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001699 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1700 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001701 TRY_CHECK_RC(OM::write(elif, itf2));
1702
1703 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1704 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1705 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001706 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
Neale Ranns812ed392017-10-16 04:20:13 -07001707 TRY_CHECK_RC(OM::write(elif, *itf_span));
1708
1709 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1710 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1711
1712 delete itf_span;
1713 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001714 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1715 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1716 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1717 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1718 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001719
1720 TRY_CHECK(OM::remove(elif));
1721}
1722
1723BOOST_AUTO_TEST_CASE(test_routing) {
1724 VppInit vi;
1725 const std::string ian = "IanFleming";
1726 rc_t rc = rc_t::OK;
1727
1728 /*
1729 * non-default route domain
1730 */
1731 route_domain rd4(1);
1732 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1733 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1734 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1735 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1736 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1737 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1738 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1739 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001740 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1741 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001742 TRY_CHECK_RC(OM::write(ian, rd4));
1743
1744 /*
1745 * a couple of interfaces
1746 */
1747 std::string itf1_name = "af1";
1748 interface itf1(itf1_name,
1749 interface::type_t::AFPACKET,
1750 interface::admin_state_t::UP);
1751 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1752 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1753 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001754 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1755 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001756 TRY_CHECK_RC(OM::write(ian, itf1));
1757
1758 std::string itf2_name = "af2";
1759 interface *itf2 = new interface(itf2_name,
1760 interface::type_t::AFPACKET,
1761 interface::admin_state_t::UP,
1762 rd4);
1763
1764 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1765 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1766 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001767 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1768 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1769 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1770 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001771 TRY_CHECK_RC(OM::write(ian, *itf2));
1772
1773 /*
1774 * prefix on each interface
1775 */
1776 route::prefix_t pfx_10("10.10.10.10", 24);
1777 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1778 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1779 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001780 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001781 TRY_CHECK_RC(OM::write(ian, *l3_10));
1782 route::prefix_t pfx_11("11.11.11.11", 24);
1783 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1784 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1785 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001786 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001787 TRY_CHECK_RC(OM::write(ian, *l3_11));
1788
1789 /*
1790 * A route via interface 1 in the default table
1791 */
1792 route::prefix_t pfx_5("5.5.5.5", 32);
Neale Ranns6ad72312019-01-10 08:56:38 -08001793 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1794 route::path *path_9 = new route::path(nh_9, itf1);
Neale Ranns812ed392017-10-16 04:20:13 -07001795 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1796 route::path *path_10 = new route::path(nh_10, itf1);
1797 route::ip_route *route_5 = new route::ip_route(pfx_5);
1798 route_5->add(*path_10);
Neale Ranns6ad72312019-01-10 08:56:38 -08001799 route_5->add(*path_9);
Neale Rannsa608afe2019-06-26 00:26:08 -07001800 route::path_list_t pl_9_10 = {*path_9, *path_10};
1801 HW::item<handle_t> hw_route_5(0, rc_t::OK);
1802 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_9_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001803 TRY_CHECK_RC(OM::write(ian, *route_5));
1804
Neale Ranns6ad72312019-01-10 08:56:38 -08001805 route_5->remove(*path_9);
Neale Rannsa608afe2019-06-26 00:26:08 -07001806 route::path_list_t pl_10 = {*path_10};
1807 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_10));
Neale Ranns6ad72312019-01-10 08:56:38 -08001808 TRY_CHECK_RC(OM::write(ian, *route_5));
1809
1810 delete path_9;
1811
Neale Ranns812ed392017-10-16 04:20:13 -07001812 /*
1813 * A route via interface 2 in the non-default table
1814 */
1815 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1816 route::path *path_11 = new route::path(nh_11, *itf2);
Neale Ranns6ad72312019-01-10 08:56:38 -08001817 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1818 route::path *path_12 = new route::path(nh_12, *itf2);
Neale Ranns812ed392017-10-16 04:20:13 -07001819 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
Neale Rannsa608afe2019-06-26 00:26:08 -07001820 route::path_list_t pl_11 = {*path_11};
Neale Ranns812ed392017-10-16 04:20:13 -07001821 route_5_2->add(*path_11);
Neale Rannsa608afe2019-06-26 00:26:08 -07001822 HW::item<handle_t> hw_route_5_2(1, rc_t::OK);
1823 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11));
Neale Ranns6ad72312019-01-10 08:56:38 -08001824 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1825
Neale Rannsa608afe2019-06-26 00:26:08 -07001826 route::path_list_t pl_11_12 = {*path_11, *path_12};
Neale Ranns6ad72312019-01-10 08:56:38 -08001827 route_5_2->add(*path_12);
Neale Rannsa608afe2019-06-26 00:26:08 -07001828 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11_12));
Neale Ranns812ed392017-10-16 04:20:13 -07001829 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1830
1831 /*
1832 * An ARP entry for the neighbour on itf1
1833 */
Neale Rannsa608afe2019-06-26 00:26:08 -07001834 HW::item<handle_t> hw_neighbour(0, rc_t::OK);
Neale Ranns812ed392017-10-16 04:20:13 -07001835 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001836 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns6fef74a2019-02-12 06:18:30 -08001837 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1838 mac_n, nh_10,
1839 neighbour::flags_t::STATIC));
Neale Ranns812ed392017-10-16 04:20:13 -07001840 TRY_CHECK_RC(OM::write(ian, *ne));
1841
1842 /*
1843 * A DVR route
1844 */
1845 route::prefix_t pfx_6("6.6.6.6", 32);
Neale Rannsa608afe2019-06-26 00:26:08 -07001846 route::path *path_13 = new route::path(*itf2, nh_proto_t::ETHERNET);
Neale Ranns812ed392017-10-16 04:20:13 -07001847 route::ip_route *route_dvr = new route::ip_route(pfx_6);
Neale Rannsa608afe2019-06-26 00:26:08 -07001848 route_dvr->add(*path_13);
1849 route::path_list_t pl_13 = {*path_13};
1850 HW::item<handle_t> hw_route_dvr(2, rc_t::OK);
1851 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, pl_13));
Neale Ranns812ed392017-10-16 04:20:13 -07001852 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1853
Neale Ranns7c03ed42018-12-27 03:21:28 -08001854 /*
1855 * a multicast route
1856 */
1857 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1858 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1859
1860 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1861 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1862 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1863 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1864 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1865 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1866 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1867 *mp1, route::itf_flags_t::FORWARD));
1868 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1869 *mp2, route::itf_flags_t::FORWARD));
1870 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1871 *mp1, route::itf_flags_t::ACCEPT));
1872 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1873
Neale Ranns812ed392017-10-16 04:20:13 -07001874 STRICT_ORDER_OFF();
1875 // delete the stack objects that hold references to others
1876 // so the OM::remove is the call that removes the last reference
1877 delete l3_11;
1878 delete l3_10;
1879 delete itf2;
1880 delete route_5;
Neale Ranns812ed392017-10-16 04:20:13 -07001881 delete route_5_2;
Neale Ranns812ed392017-10-16 04:20:13 -07001882 delete route_dvr;
Neale Ranns812ed392017-10-16 04:20:13 -07001883 delete ne;
Neale Ranns7c03ed42018-12-27 03:21:28 -08001884 delete mroute_4;
1885
1886 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1887 *mp1, route::itf_flags_t::FORWARD));
1888 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1889 *mp2, route::itf_flags_t::FORWARD));
1890 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1891 *mp1, route::itf_flags_t::ACCEPT));
1892
1893 delete mp1;
1894 delete mp2;
1895
Neale Ranns6fef74a2019-02-12 06:18:30 -08001896 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1897 mac_n, nh_10,
1898 neighbour::flags_t::STATIC));
Neale Rannsa608afe2019-06-26 00:26:08 -07001899 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1900 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1901 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
Neale Ranns6ad72312019-01-10 08:56:38 -08001902
1903 delete path_10;
1904 delete path_11;
1905 delete path_12;
Neale Rannsa608afe2019-06-26 00:26:08 -07001906 delete path_13;
Neale Ranns22d009b2019-06-26 06:59:53 -07001907 pl_9_10.clear();
1908 pl_10.clear();
1909 pl_13.clear();
1910 pl_11_12.clear();
1911 pl_11.clear();
Neale Ranns6ad72312019-01-10 08:56:38 -08001912
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001913 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1914 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1915 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1916 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1917 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1918 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1919 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1920 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1921 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1922 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001923
1924 TRY_CHECK(OM::remove(ian));
1925}
1926
1927BOOST_AUTO_TEST_CASE(test_nat) {
1928 VppInit vi;
1929 const std::string gs = "GeorgeSimenon";
1930 rc_t rc = rc_t::OK;
1931
1932 /*
1933 * Inside Interface
1934 */
1935 std::string itf_in_name = "inside";
1936 interface itf_in(itf_in_name,
1937 interface::type_t::AFPACKET,
1938 interface::admin_state_t::UP);
1939 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1940 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1941 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001942 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1943 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001944 TRY_CHECK_RC(OM::write(gs, itf_in));
1945
1946 /*
1947 * outside
1948 */
1949 std::string itf_out_name = "port-to";
1950 interface itf_out(itf_out_name,
1951 interface::type_t::AFPACKET,
1952 interface::admin_state_t::UP);
1953
1954 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1955 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1956 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1957
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001958 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1959 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001960 TRY_CHECK_RC(OM::write(gs, itf_out));
1961
1962 /*
1963 * A NAT static mapping
1964 */
1965 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1966 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1967
1968 nat_static ns(in_addr, out_addr);
1969 HW::item<bool> hw_ns(true, rc_t::OK);
1970
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001971 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001972 TRY_CHECK_RC(OM::write(gs, ns));
1973
1974 /*
1975 * bind nat inside and out
1976 */
1977 nat_binding *nb_in = new nat_binding(itf_in,
1978 direction_t::INPUT,
1979 l3_proto_t::IPV4,
1980 nat_binding::zone_t::INSIDE);
1981 HW::item<bool> hw_nb_in(true, rc_t::OK);
1982
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001983 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1984 hw_ifh.data().value(),
1985 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001986 TRY_CHECK_RC(OM::write(gs, *nb_in));
1987
1988 nat_binding *nb_out = new nat_binding(itf_out,
1989 direction_t::INPUT,
1990 l3_proto_t::IPV4,
1991 nat_binding::zone_t::OUTSIDE);
1992 HW::item<bool> hw_nb_out(true, rc_t::OK);
1993
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001994 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1995 hw_ifh2.data().value(),
1996 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001997 TRY_CHECK_RC(OM::write(gs, *nb_out));
1998
1999
2000 STRICT_ORDER_OFF();
2001 delete nb_in;
2002 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07002003 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
2004 hw_ifh.data().value(),
2005 nat_binding::zone_t::INSIDE));
2006 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
2007 hw_ifh2.data().value(),
2008 nat_binding::zone_t::OUTSIDE));
2009 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
2010 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
2011 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
2012 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
2013 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07002014
2015 TRY_CHECK(OM::remove(gs));
2016}
2017
2018BOOST_AUTO_TEST_CASE(test_interface_events) {
2019 VppInit vi;
2020 MockListener ml;
2021
2022 HW::item<bool> hw_want(true, rc_t::OK);
2023
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07002024 ADD_EXPECT(interface_cmds::events_cmd(ml));
2025 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07002026
2027 HW::enqueue(itf);
2028 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07002029}
2030
Neale Ranns352ea0c2017-11-14 11:04:28 -08002031BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
2032 VppInit vi;
2033 const std::string rene = "ReneGoscinny";
2034 rc_t rc = rc_t::OK;
2035
2036 /*
2037 * Create an interface with two IP addresses
2038 */
2039 std::string itf1_name = "host1";
2040 interface itf1(itf1_name,
2041 interface::type_t::AFPACKET,
2042 interface::admin_state_t::UP);
2043 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
2044 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
2045 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
2046 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
2047 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
2048 TRY_CHECK_RC(OM::write(rene, itf1));
2049
2050 route::prefix_t pfx_10("10.10.10.10", 24);
2051 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
2052 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
2053 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
2054 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2055 TRY_CHECK_RC(OM::write(rene, *l3_1));
2056
2057 route::prefix_t pfx_11("10.10.11.11", 24);
2058 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
2059 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
2060 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
2061 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2062 TRY_CHECK_RC(OM::write(rene, *l3_2));
2063
2064 route_domain rd(1);
2065 HW::item<bool> hw_rd_create(true, rc_t::OK);
2066 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2067 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2068 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2069 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2070 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2071 TRY_CHECK_RC(OM::write(rene, rd));
2072
2073 /*
2074 * update the interface to change to a new route-domain
2075 * expect that the l3-bindings are removed and readded.
2076 */
2077 interface *itf2 = new interface(itf1_name,
2078 interface::type_t::AFPACKET,
2079 interface::admin_state_t::UP,
2080 rd);
2081 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2082 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2083 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2084 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2085 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2086 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2087 TRY_CHECK_RC(OM::write(rene, *itf2));
2088
2089 /*
2090 * mve the interface back to the default route-domain
2091 */
2092 interface itf3(itf1_name,
2093 interface::type_t::AFPACKET,
2094 interface::admin_state_t::UP);
2095 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2096 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2097 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2098 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2099 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2100 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2101 TRY_CHECK_RC(OM::write(rene, itf3));
2102
2103 delete l3_1;
2104 delete l3_2;
2105 delete itf2;
2106
2107 STRICT_ORDER_OFF();
2108 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2109 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2110 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2111 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2112 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2113 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2114
2115 TRY_CHECK(OM::remove(rene));
2116}
2117
Neale Rannsd3464b52017-12-07 08:48:02 -08002118BOOST_AUTO_TEST_CASE(test_prefixes) {
2119 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2120
2121 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2122
2123 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2124
2125 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2126 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2127
2128 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2129 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2130 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2131
2132 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2133
2134 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2135
2136 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2137
2138 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2139 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2140 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2141
2142 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2143
2144 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2145 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2146 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2147
2148 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2149
2150 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2151 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2152 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2153
2154}
2155
Neale Ranns208c29a2018-04-11 08:08:30 -07002156BOOST_AUTO_TEST_CASE(test_pipes) {
2157 VppInit vi;
2158 const std::string gk = "GKChesterton";
2159
2160 const std::string pipe_name_1 = "pipe1";
2161 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2162 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2163 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2164
2165 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2166 rc_t::OK);
2167 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2168 rc_t::OK);
2169 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2170 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2171 TRY_CHECK_RC(OM::write(gk, pipe1));
2172
2173 pipe1.set_ends(hw_hdl_pair.data());
2174
2175 // put each end of the pipe in a BD
2176 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2177 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002178 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002179 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002180 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002181 bridge_domain::mac_age_mode_t::ON);
2182
2183 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2184 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2185 bridge_domain::learning_mode_t::OFF,
2186 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002187 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002188 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002189 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002190 bridge_domain::mac_age_mode_t::ON));
2191
2192 TRY_CHECK_RC(OM::write(gk, bd1));
2193
2194 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2195 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2196
2197 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2198 pipe1.east()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002199 hw_bd.data(),
2200 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002201 TRY_CHECK_RC(OM::write(gk, *l2_1));
2202
2203 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2204 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2205
2206 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2207 pipe1.west()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002208 hw_bd.data(),
2209 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002210 TRY_CHECK_RC(OM::write(gk, *l2_2));
2211
2212 STRICT_ORDER_OFF();
2213
2214 delete l2_1;
2215 delete l2_2;
2216 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2217 pipe1.east()->handle(),
2218 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002219 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002220 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2221 pipe1.west()->handle(),
2222 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002223 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002224 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2225 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2226 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2227 TRY_CHECK(OM::remove(gk));
2228}
2229
Neale Rannsc17c1872019-07-23 01:48:55 -07002230BOOST_AUTO_TEST_CASE(test_qos) {
2231 VppInit vi;
2232 const std::string albert = "AlbertCamus";
2233 rc_t rc = rc_t::OK;
2234
2235 /*
2236 * Create an interface on which to enable QoS
2237 */
2238 std::string itf_name = "host1";
2239 interface itf(itf_name,
2240 interface::type_t::AFPACKET,
2241 interface::admin_state_t::UP);
2242 HW::item<handle_t> hw_ifh(2, rc_t::OK);
2243 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
2244 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
2245 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
2246 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
2247 TRY_CHECK_RC(OM::write(albert, itf));
2248
2249 QoS::map::outputs_t out;
2250 out[0][5] = 5;
2251 out[3][6] = 6;
2252
2253 QoS::map qem(1, out);
2254
2255 HW::item<bool> hw_qem(true, rc_t::OK);
2256 ADD_EXPECT(QoS::map_cmds::create_cmd(hw_qem, 1, out));
2257 TRY_CHECK_RC(OM::write(albert, qem));
2258
2259 QoS::record *qr = new QoS::record(itf, QoS::source_t::IP);
2260 HW::item<bool> hw_qr(true, rc_t::OK);
2261 ADD_EXPECT(QoS::record_cmds::create_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP));
2262 TRY_CHECK_RC(OM::write(albert, *qr));
2263
Neale Ranns83832e72019-07-31 02:48:02 -07002264 QoS::store *qs = new QoS::store(itf, QoS::source_t::IP, 55);
2265 HW::item<bool> hw_qs(true, rc_t::OK);
2266 ADD_EXPECT(QoS::store_cmds::create_cmd(hw_qs, hw_ifh.data(), QoS::source_t::IP, 55));
2267 TRY_CHECK_RC(OM::write(albert, *qs));
2268
Neale Rannsc17c1872019-07-23 01:48:55 -07002269 QoS::mark *qm = new QoS::mark(itf, qem, QoS::source_t::IP);
2270 HW::item<bool> hw_qm(true, rc_t::OK);
2271 ADD_EXPECT(QoS::mark_cmds::create_cmd(hw_qm, hw_ifh.data(), 1, QoS::source_t::IP));
2272 TRY_CHECK_RC(OM::write(albert, *qm));
2273
Neale Ranns83832e72019-07-31 02:48:02 -07002274 STRICT_ORDER_OFF();
Neale Rannsc17c1872019-07-23 01:48:55 -07002275 delete qr;
2276 delete qm;
Neale Ranns83832e72019-07-31 02:48:02 -07002277 delete qs;
Neale Rannsc17c1872019-07-23 01:48:55 -07002278 ADD_EXPECT(QoS::mark_cmds::delete_cmd(hw_qm, hw_ifh.data(), QoS::source_t::IP));
2279 ADD_EXPECT(QoS::map_cmds::delete_cmd(hw_qem, 1));
2280 ADD_EXPECT(QoS::record_cmds::delete_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP));
Neale Ranns83832e72019-07-31 02:48:02 -07002281 ADD_EXPECT(QoS::store_cmds::delete_cmd(hw_qs, hw_ifh.data(), QoS::source_t::IP));
Neale Rannsc17c1872019-07-23 01:48:55 -07002282 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
2283 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
2284 TRY_CHECK(OM::remove(albert));
2285}
2286
Neale Ranns812ed392017-10-16 04:20:13 -07002287BOOST_AUTO_TEST_SUITE_END()