blob: 569bd8c1fd9e275a09618e8b2b39d07c9b46d8ec [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 Ranns812ed392017-10-16 04:20:13 -070081
82using namespace boost;
83using namespace VOM;
84
85/**
86 * An expectation exception
87 */
88class ExpException
89{
90public:
91 ExpException(unsigned int number)
92 {
93 // a neat place to add a break point
94 std::cout << " ExpException here: " << number << std::endl;
95 }
96};
97
98class MockListener : public interface::event_listener,
99 public interface::stat_listener
100{
Mohsin Kazmi51edc3a2018-11-21 19:00:46 +0100101 void handle_interface_stat(const interface& itf)
Neale Ranns812ed392017-10-16 04:20:13 -0700102 {
103 }
Neale Ranns193c47d2018-12-10 06:01:46 -0800104 void handle_interface_event(std::vector<VOM::interface::event> events)
Neale Ranns812ed392017-10-16 04:20:13 -0700105 {
106 }
107};
108
109class MockCmdQ : public HW::cmd_q
110{
111public:
112 MockCmdQ():
113 m_strict_order(true)
114 {
115 }
116 virtual ~MockCmdQ()
117 {
118 }
119 void expect(cmd *f)
120 {
121 m_exp_queue.push_back(f);
122 }
123 void enqueue(cmd *f)
124 {
125 m_act_queue.push_back(f);
126 }
127 void enqueue(std::queue<cmd*> &cmds)
128 {
129 while (cmds.size())
130 {
131 m_act_queue.push_back(cmds.front());
132 cmds.pop();
133 }
134 }
135 void enqueue(std::shared_ptr<cmd> f)
136 {
137 m_act_queue.push_back(f.get());
138 }
139
140 void dequeue(cmd *f)
141 {
142 }
143
144 void dequeue(std::shared_ptr<cmd> cmd)
145 {
146 }
147
148 void strict_order(bool on)
149 {
150 m_strict_order = on;
151 }
152
153 bool is_empty()
154 {
155 return ((0 == m_exp_queue.size()) &&
156 (0 == m_act_queue.size()));
157 }
158
159 rc_t write()
160 {
161 cmd *f_exp, *f_act;
162 rc_t rc = rc_t::OK;
163
164 while (m_act_queue.size())
165 {
166 bool matched = false;
167 auto it_exp = m_exp_queue.begin();
168 auto it_act = m_act_queue.begin();
169
170 f_act = *it_act;
171
172 std::cout << " Act: " << f_act->to_string() << std::endl;
173 while (it_exp != m_exp_queue.end())
174 {
175 f_exp = *it_exp;
176 try
177 {
178 std::cout << " Exp: " << f_exp->to_string() << std::endl;
179
180 if (typeid(*f_exp) != typeid(*f_act))
181 {
182 throw ExpException(1);
183 }
184
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700185 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700186 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700187 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700188 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700189 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700190 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700191 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700192 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800193 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
194 {
195 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
196 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100197 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
198 {
199 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
200 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700201 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700202 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700203 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700204 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700205 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700206 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700207 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700208 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800209 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
210 {
211 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
212 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100213 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
214 {
215 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
216 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700217 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700218 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700219 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700220 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700221 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700222 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700223 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700224 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700225 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700226 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700227 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700228 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700229 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
Neale Ranns812ed392017-10-16 04:20:13 -0700230 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700231 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700232 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100233 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
234 {
235 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
236 }
237 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
238 {
239 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
240 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700241 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700242 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700243 rc = handle_derived<route_domain_cmds::create_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(route_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700246 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700247 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700248 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700249 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700250 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700251 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700252 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700253 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700254 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700255 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700256 }
Neale Ranns7c03ed42018-12-27 03:21:28 -0800257 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
258 {
259 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
260 }
261 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
262 {
263 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
264 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700265 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700266 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700267 rc = handle_derived<neighbour_cmds::create_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(neighbour_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700270 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700271 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700272 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700273 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700274 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700275 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700276 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700277 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700278 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700279 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700280 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700281 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700282 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700283 rc = handle_derived<bridge_domain_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(bridge_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700286 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700287 rc = handle_derived<bridge_domain_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(bridge_domain_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700290 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700291 rc = handle_derived<bridge_domain_entry_cmds::create_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(bridge_domain_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700294 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700295 rc = handle_derived<bridge_domain_entry_cmds::delete_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_arp_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700298 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700299 rc = handle_derived<bridge_domain_arp_entry_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_arp_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700302 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700303 rc = handle_derived<bridge_domain_arp_entry_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(l2_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700306 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700307 rc = handle_derived<l2_binding_cmds::bind_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(l2_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700310 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700311 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700312 }
Neale Ranns53322002019-02-22 02:48:25 -0800313 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700314 {
Neale Ranns53322002019-02-22 02:48:25 -0800315 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700316 }
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +0200317 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
318 {
319 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
320 }
321 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
322 {
323 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
324 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700325 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700326 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700327 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700328 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700329 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700330 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700331 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700332 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700333 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700334 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700335 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700336 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700337 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700338 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700339 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700340 }
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +0100341 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
342 {
343 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
344 }
Mohsin Kazmi04def742018-03-07 19:53:51 +0100345 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
346 {
347 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
348 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700349 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700350 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700351 rc = handle_derived<ACL::list_cmds::l3_update_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(ACL::list_cmds::l3_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700354 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700355 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700356 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700357 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700358 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700359 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700360 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700361 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700362 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700363 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700364 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700365 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700366 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700367 rc = handle_derived<ACL::list_cmds::l2_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::l2_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700370 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700371 rc = handle_derived<ACL::list_cmds::l2_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::l2_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700374 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700375 rc = handle_derived<ACL::binding_cmds::l2_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::l2_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700378 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700379 rc = handle_derived<ACL::binding_cmds::l2_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(arp_proxy_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700382 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700383 rc = handle_derived<arp_proxy_binding_cmds::bind_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(arp_proxy_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700386 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700387 rc = handle_derived<arp_proxy_binding_cmds::unbind_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(arp_proxy_config_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700390 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700391 rc = handle_derived<arp_proxy_config_cmds::config_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(arp_proxy_config_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700394 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700395 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700396 }
Mohsin Kazmi12fe8782018-10-30 19:24:34 +0100397 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
398 {
399 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
400 }
401 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
402 {
403 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
404 }
405 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
406 {
407 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
408 }
409 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
410 {
411 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
412 }
Mohsin Kazmie23edac2018-09-25 18:26:52 +0200413 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
414 {
415 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
416 }
417 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
418 {
419 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
420 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700421 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700422 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700423 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700424 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700425 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700426 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700427 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700428 }
429 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
430 {
431 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
432 }
433 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
434 {
435 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
436 }
437 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
438 {
439 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
440 }
441 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
442 {
443 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
444 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700445 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700446 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700447 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700448 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700449 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700450 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700451 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700452 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700453 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700454 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700455 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700456 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700457 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700458 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700459 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700460 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700461 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700462 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700463 rc = handle_derived<nat_binding_cmds::bind_44_input_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(nat_binding_cmds::unbind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700466 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700467 rc = handle_derived<nat_binding_cmds::unbind_44_input_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(interface_cmds::events_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700470 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700471 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700472 }
Neale Ranns208c29a2018-04-11 08:08:30 -0700473 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
474 {
475 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
476 }
477 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
478 {
479 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
480 }
Neale Ranns812ed392017-10-16 04:20:13 -0700481 else
482 {
483 throw ExpException(2);
484 }
485
486 // if we get here then we found the match.
487 m_exp_queue.erase(it_exp);
488 m_act_queue.erase(it_act);
489 delete f_exp;
490 delete f_act;
491
492 // return any injected failures to the agent
493 if (rc_t::OK != rc && rc_t::NOOP != rc)
494 {
495 return (rc);
496 }
497
498 matched = true;
499 break;
500 }
501 catch (ExpException &e)
502 {
503 // The expected and actual do not match
504 if (m_strict_order)
505 {
506 // in strict ordering mode this is fatal, so rethrow
507 throw e;
508 }
509 else
510 {
511 // move the iterator onto the next in the expected list and
512 // check for a match
513 ++it_exp;
514 }
515 }
516 }
517
518 if (!matched)
519 throw ExpException(3);
520 }
521
522 return (rc);
523 }
524private:
525
526 template <typename T>
527 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
528 {
529 const T *i_exp;
530 T *i_act;
531
532 i_exp = dynamic_cast<const T*>(f_exp);
533 i_act = dynamic_cast<T*>(f_act);
534 if (!(*i_exp == *i_act))
535 {
536 throw ExpException(4);
537 }
538 // pass the data and return code to the agent
539 i_act->item() = i_exp->item();
540
541 return (i_act->item().rc());
542 }
543
544 // The Q to push the expectations on
545 std::deque<cmd*> m_exp_queue;
546
547 // the queue to push the actual events on
548 std::deque<cmd*> m_act_queue;
549
550 // control whether the expected queue is strictly ordered.
551 bool m_strict_order;
552};
553
554class VppInit {
555public:
556 std::string name;
557 MockCmdQ *f;
558
559 VppInit()
560 : name("vpp-ut"),
561 f(new MockCmdQ())
562 {
563 HW::init(f);
564 OM::init();
565 logger().set(log_level_t::DEBUG);
566 }
567
568 ~VppInit() {
569 delete f;
570 }
571};
572
Neale Rannsd3464b52017-12-07 08:48:02 -0800573BOOST_AUTO_TEST_SUITE(vom)
Neale Ranns812ed392017-10-16 04:20:13 -0700574
575#define TRY_CHECK_RC(stmt) \
576{ \
577 try { \
578 BOOST_CHECK(rc_t::OK == stmt); \
579 } \
580 catch (ExpException &e) \
581 { \
582 BOOST_CHECK(false); \
583 } \
584 BOOST_CHECK(vi.f->is_empty()); \
585}
586
587#define TRY_CHECK(stmt) \
588{ \
589 try { \
590 stmt; \
591 } \
592 catch (ExpException &e) \
593 { \
594 BOOST_CHECK(false); \
595 } \
596 BOOST_CHECK(vi.f->is_empty()); \
597}
598
599#define ADD_EXPECT(stmt) \
600 vi.f->expect(new stmt)
601
602#define STRICT_ORDER_OFF() \
603 vi.f->strict_order(false)
604
605BOOST_AUTO_TEST_CASE(test_interface) {
606 VppInit vi;
607 const std::string go = "GeorgeOrwell";
608 const std::string js = "JohnSteinbeck";
609 rc_t rc = rc_t::OK;
610
611 /*
612 * George creates and deletes the interface
613 */
614 std::string itf1_name = "afpacket1";
615 interface itf1(itf1_name,
616 interface::type_t::AFPACKET,
617 interface::admin_state_t::UP);
618
619 /*
620 * set the expectation for a afpacket interface create.
621 * 2 is the interface handle VPP [mock] assigns
622 */
623 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700624 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700625
626 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700627 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700628
629 TRY_CHECK_RC(OM::write(go, itf1));
630
631 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700632 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
633 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700634
635 TRY_CHECK(OM::remove(go));
636
637 /*
638 * George creates the interface, then John brings it down.
639 * George's remove is a no-op, sice John also owns the interface
640 */
641 interface itf1b(itf1_name,
642 interface::type_t::AFPACKET,
643 interface::admin_state_t::DOWN);
644
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700645 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
646 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700647 TRY_CHECK_RC(OM::write(go, itf1));
648
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700649 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700650 TRY_CHECK_RC(OM::write(js, itf1b));
651
652 TRY_CHECK(OM::remove(go));
653
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700654 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700655 TRY_CHECK(OM::remove(js));
656
657 /*
658 * George adds an interface, then we flush all of Geroge's state
659 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700660 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
661 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700662 TRY_CHECK_RC(OM::write(go, itf1));
663
664 TRY_CHECK(OM::mark(go));
665
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700666 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
667 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700668 TRY_CHECK(OM::sweep(go));
669
670 /*
671 * George adds an interface. mark stale. update the same interface. sweep
672 * and expect no delete
673 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700674 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
675 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700676 TRY_CHECK_RC(OM::write(go, itf1b));
677
678 TRY_CHECK(OM::mark(go));
679
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700680 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700681 TRY_CHECK_RC(OM::write(go, itf1));
682
683 TRY_CHECK(OM::sweep(go));
684
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700685 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
686 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700687 TRY_CHECK(OM::remove(go));
688
689 /*
690 * George adds an insterface, then we mark that state. Add a second interface
691 * an flush the first that is now stale.
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
697 TRY_CHECK(OM::mark(go));
698
699 std::string itf2_name = "afpacket2";
Neale Ranns4ef42262018-02-20 08:10:44 -0800700 std::string itf2_tag = "uuid-of-afpacket2-interface";
Neale Ranns812ed392017-10-16 04:20:13 -0700701 interface itf2(itf2_name,
702 interface::type_t::AFPACKET,
Neale Ranns4ef42262018-02-20 08:10:44 -0800703 interface::admin_state_t::UP,
704 itf2_tag);
Neale Ranns812ed392017-10-16 04:20:13 -0700705 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
706
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700707 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
Neale Ranns4ef42262018-02-20 08:10:44 -0800708 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700709 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700710 TRY_CHECK_RC(OM::write(go, itf2));
711
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700712 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
713 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700714 TRY_CHECK(OM::sweep(go));
715
716 TRY_CHECK(OM::mark(go));
717
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700718 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
719 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700720 TRY_CHECK(OM::sweep(go));
Neale Ranns4ef42262018-02-20 08:10:44 -0800721
722
723 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
724 std::string itf3_tag = "uuid-of-vhost_user1-interface";
725 interface itf3(itf3_name,
726 interface::type_t::VHOST,
727 interface::admin_state_t::UP,
728 itf3_tag);
729 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
730
731 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
732 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
733 TRY_CHECK_RC(OM::write(go, itf3));
734
735 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
736 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
737 TRY_CHECK(OM::remove(go));
Neale Ranns812ed392017-10-16 04:20:13 -0700738}
739
740BOOST_AUTO_TEST_CASE(test_bvi) {
741 VppInit vi;
742 const std::string ernest = "ErnestHemmingway";
743 const std::string graham = "GrahamGreene";
744 rc_t rc = rc_t::OK;
745 l3_binding *l3;
746
747 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
748 rc_t::OK);
749 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
750 rc_t::OK);
751
752 /*
753 * Enrest creates a BVI with address 10.10.10.10/24
754 */
755 route::prefix_t pfx_10("10.10.10.10", 24);
756
757 const std::string bvi_name = "bvi1";
758 interface itf(bvi_name,
759 interface::type_t::BVI,
760 interface::admin_state_t::UP);
761 HW::item<handle_t> hw_ifh(4, rc_t::OK);
762 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
763
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700764 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
765 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
766 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700767 TRY_CHECK_RC(OM::write(ernest, itf));
768
769 l3 = new l3_binding(itf, pfx_10);
770 HW::item<bool> hw_l3_bind(true, rc_t::OK);
771 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700772 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700773 TRY_CHECK_RC(OM::write(ernest, *l3));
774
775 // change the MAC address on the BVI
776 interface itf_new_mac(bvi_name,
777 interface::type_t::BVI,
778 interface::admin_state_t::UP);
779 l2_address_t l2_addr({0,1,2,3,4,5});
780 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
781 itf_new_mac.set(l2_addr);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700782 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700783 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
784
785 // create/write the interface to the OM again but with an unset MAC
786 // this should not generate a MAC address update
787 TRY_CHECK_RC(OM::write(ernest, itf));
788
789 // change the MAC address on the BVI - again
790 interface itf_new_mac2(bvi_name,
791 interface::type_t::BVI,
792 interface::admin_state_t::UP);
793 l2_address_t l2_addr2({0,1,2,3,4,6});
794 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
795 itf_new_mac2.set(l2_addr2);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700796 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700797 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
798
799 delete l3;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700800 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
801 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
802 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700803 TRY_CHECK(OM::remove(ernest));
804
805 /*
806 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
807 */
808 route_domain rd(1);
809 HW::item<bool> hw_rd4_create(true, rc_t::OK);
810 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
811 HW::item<bool> hw_rd6_create(true, rc_t::OK);
812 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
813 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
814 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
815 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
816 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700817 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
818 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700819 TRY_CHECK_RC(OM::write(graham, rd));
820
821 const std::string bvi2_name = "bvi2";
822 interface *itf2 = new interface(bvi2_name,
823 interface::type_t::BVI,
824 interface::admin_state_t::UP,
825 rd);
826 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
827
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700828 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
829 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
830 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
831 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
832 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700833
834 TRY_CHECK_RC(OM::write(graham, *itf2));
835
836 l3 = new l3_binding(*itf2, pfx_10);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700837 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700838 TRY_CHECK_RC(OM::write(graham, *l3));
839
840 delete l3;
841 delete itf2;
842
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700843 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
844 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
845 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
846 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
847 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
848 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
849 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700850 TRY_CHECK(OM::remove(graham));
851}
852
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100853BOOST_AUTO_TEST_CASE(test_bond) {
854 VppInit vi;
855 const std::string cb = "CarolBerg";
856 rc_t rc = rc_t::OK;
857
858 /*
859 * creates the interfaces
860 */
861 std::string itf1_name = "afpacket1";
862 interface itf1(itf1_name,
863 interface::type_t::AFPACKET,
864 interface::admin_state_t::UP);
865
866 HW::item<handle_t> hw_ifh(2, rc_t::OK);
867 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
868
869 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
870 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
871
872 TRY_CHECK_RC(OM::write(cb, itf1));
873
874 std::string itf2_name = "afpacket2";
875 interface itf2(itf2_name,
876 interface::type_t::AFPACKET,
877 interface::admin_state_t::UP);
878
879
880 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
881 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
882 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
883
884 TRY_CHECK_RC(OM::write(cb, itf2));
885
886 std::string bond_name = "bond";
887 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
888 bond_interface::mode_t::LACP);
889
890 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
891 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
892 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
893 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
894
895 TRY_CHECK_RC(OM::write(cb, bond_itf));
896
897 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
898 bond_member::rate_t::SLOW);
899 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
900 bond_member::rate_t::SLOW);
901 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
902
903 HW::item<bool> bond_hw_bind(true, rc_t::OK);
904 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
905 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
906
907 TRY_CHECK_RC(OM::write(cb, *bgb));
908
909 delete bgb;
910 delete bm2;
911 delete bm1;
912
913 STRICT_ORDER_OFF();
914 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
915 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
916 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
917 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
918 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
919 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
920 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
921 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
922 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
923
924 TRY_CHECK(OM::remove(cb));
925}
926
Neale Ranns812ed392017-10-16 04:20:13 -0700927BOOST_AUTO_TEST_CASE(test_bridge) {
928 VppInit vi;
929 const std::string franz = "FranzKafka";
930 const std::string dante = "Dante";
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100931 const std::string jkr = "jkrowling";
Neale Ranns812ed392017-10-16 04:20:13 -0700932 rc_t rc = rc_t::OK;
933
934 /*
935 * Franz creates an interface, Bridge-domain, then binds the two
936 */
937
938 // interface create
939 std::string itf1_name = "afpacket1";
940 interface itf1(itf1_name,
941 interface::type_t::AFPACKET,
942 interface::admin_state_t::UP);
943
944 HW::item<handle_t> hw_ifh(3, rc_t::OK);
945 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
946 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700947 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
948 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700949
950 TRY_CHECK_RC(OM::write(franz, itf1));
951
952 // bridge-domain create
953 bridge_domain bd1(33);
954
955 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -0700956 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
957 bridge_domain::learning_mode_t::ON,
958 bridge_domain::arp_term_mode_t::ON,
959 bridge_domain::flood_mode_t::ON,
960 bridge_domain::mac_age_mode_t::OFF));
Neale Ranns812ed392017-10-16 04:20:13 -0700961
962 TRY_CHECK_RC(OM::write(franz, bd1));
963
964 // L2-interface create and bind
965 // this needs to be delete'd before the flush below, since it too maintains
966 // references to the BD and Interface
967 l2_binding *l2itf = new l2_binding(itf1, bd1);
968 HW::item<bool> hw_l2_bind(true, rc_t::OK);
969
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200970 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
971 hw_ifh.data(),
972 hw_bd.data(),
973 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -0700974 TRY_CHECK_RC(OM::write(franz, *l2itf));
975
976 /*
977 * Dante adds an interface to the same BD
978 */
979 std::string itf2_name = "afpacket2";
980 interface itf2(itf2_name,
981 interface::type_t::AFPACKET,
982 interface::admin_state_t::UP);
983
984 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700985 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
986 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700987 TRY_CHECK_RC(OM::write(dante, itf2));
988
989 // BD add is a no-op since it exists
990 TRY_CHECK_RC(OM::write(dante, bd1));
991
992 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
Neale Ranns53322002019-02-22 02:48:25 -0800993 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
994 l2itf2->set(l2_vtr::option_t::POP_1, 68);
Neale Ranns812ed392017-10-16 04:20:13 -0700995
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200996 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
997 hw_ifh2.data(),
998 hw_bd.data(),
999 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns53322002019-02-22 02:48:25 -08001000 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
Neale Ranns812ed392017-10-16 04:20:13 -07001001 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1002
1003 // Add some static entries to the bridge-domain
1004 HW::item<bool> hw_be1(true, rc_t::OK);
1005 mac_address_t mac1({0,1,2,3,4,5});
1006 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001007 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1008 false));
Neale Ranns812ed392017-10-16 04:20:13 -07001009 TRY_CHECK_RC(OM::write(dante, *be1));
1010
1011 // Add some entries to the bridge-domain ARP termination table
1012 HW::item<bool> hw_bea1(true, rc_t::OK);
1013 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1014
Neale Rannsfd920602017-11-23 12:15:00 -08001015 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001016 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
Neale Ranns812ed392017-10-16 04:20:13 -07001017 TRY_CHECK_RC(OM::write(dante, *bea1));
1018
1019 // flush Franz's state
1020 delete l2itf;
1021 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1022 rc_t::OK);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001023 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1024 hw_ifh.data(),
1025 hw_bd.data(),
1026 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001027 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1028 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001029 TRY_CHECK(OM::remove(franz));
1030
1031 // flush Dante's state - the order the interface and BD are deleted
1032 // is an uncontrollable artifact of the C++ object destruction.
1033 delete l2itf2;
1034 delete be1;
1035 delete bea1;
1036 STRICT_ORDER_OFF();
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001037 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1038 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001039 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1040 hw_ifh2.data(),
1041 hw_bd.data(),
1042 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001043
1044 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001045 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1046 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001047 TRY_CHECK(OM::remove(dante));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001048
1049 // test the BVI entry in l2fib
1050 bridge_domain bd2(99);
1051
1052 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001053 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1054 bridge_domain::learning_mode_t::ON,
1055 bridge_domain::arp_term_mode_t::ON,
1056 bridge_domain::flood_mode_t::ON,
1057 bridge_domain::mac_age_mode_t::OFF));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001058
1059 TRY_CHECK_RC(OM::write(jkr, bd2));
1060
1061 std::string itf3_name = "bvi";
1062 interface itf3(itf3_name,
1063 interface::type_t::BVI,
1064 interface::admin_state_t::UP);
1065
1066 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1067 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1068 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1069 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1070 TRY_CHECK_RC(OM::write(jkr, itf3));
1071
1072 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001073 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1074 hw_ifh3.data(),
1075 hw_bd2.data(),
1076 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001077 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1078
1079 HW::item<bool> hw_be2(true, rc_t::OK);
1080 mac_address_t mac2({0,1,2,3,4,5});
1081 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1082 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1083 TRY_CHECK_RC(OM::write(jkr, *be2));
1084
1085 delete l2itf3;
1086 delete be2;
1087 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001088 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1089 hw_ifh3.data(),
1090 hw_bd2.data(),
1091 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001092 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1093 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1094 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1095 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1096 TRY_CHECK(OM::remove(jkr));
Neale Ranns812ed392017-10-16 04:20:13 -07001097}
1098
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +02001099BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1100 VppInit vi;
1101 const std::string nicholas = "NicholasAbercrombie";
1102 rc_t rc = rc_t::OK;
1103
1104 /*
1105 * Interface 1
1106 */
1107 std::string itf1_name = "host1";
1108 interface itf1(itf1_name,
1109 interface::type_t::AFPACKET,
1110 interface::admin_state_t::UP);
1111 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1112 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1113 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1114 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1115 TRY_CHECK_RC(OM::write(nicholas, itf1));
1116
1117 /*
1118 * Interface 2
1119 */
1120 std::string itf2_name = "host2";
1121 interface itf2(itf2_name,
1122 interface::type_t::AFPACKET,
1123 interface::admin_state_t::UP);
1124
1125 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1126 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1127 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1128 TRY_CHECK_RC(OM::write(nicholas, itf2));
1129
1130 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1131 HW::item<bool> xconnect_east(true, rc_t::OK);
1132 HW::item<bool> xconnect_west(true, rc_t::OK);
1133 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1134 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1135 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1136 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1137 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1138
1139 delete l2_xconn;
1140
1141 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1142 STRICT_ORDER_OFF();
1143 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1144 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1145 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1146 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1147 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1148 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1149
1150 TRY_CHECK(OM::remove(nicholas));
1151}
1152
Neale Ranns812ed392017-10-16 04:20:13 -07001153BOOST_AUTO_TEST_CASE(test_vxlan) {
1154 VppInit vi;
1155 const std::string franz = "FranzKafka";
1156 rc_t rc = rc_t::OK;
1157
1158 /*
1159 * Franz creates an interface, Bridge-domain, then binds the two
1160 */
1161
1162 // VXLAN create
1163 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
Neale Ranns25b04942018-04-04 09:34:50 -07001164 boost::asio::ip::address::from_string("10.10.10.11"),
1165 322);
Neale Ranns812ed392017-10-16 04:20:13 -07001166
1167 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1168
1169 HW::item<handle_t> hw_vxt(3, rc_t::OK);
Neale Rannscf3ecb12018-12-11 08:40:20 -08001170 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1171 handle_t::INVALID));
Neale Ranns812ed392017-10-16 04:20:13 -07001172
1173 TRY_CHECK_RC(OM::write(franz, vxt));
1174
1175 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001176 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1177 bridge_domain::arp_term_mode_t::OFF,
1178 bridge_domain::flood_mode_t::OFF,
1179 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001180
1181 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001182 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1183 bridge_domain::learning_mode_t::OFF,
1184 bridge_domain::arp_term_mode_t::OFF,
1185 bridge_domain::flood_mode_t::OFF,
1186 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001187
1188 TRY_CHECK_RC(OM::write(franz, bd1));
1189
1190 // L2-interface create and bind
1191 // this needs to be delete'd before the flush below, since it too maintains
1192 // references to the BD and Interface
1193 l2_binding *l2itf = new l2_binding(vxt, bd1);
1194 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1195
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001196 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1197 hw_vxt.data(),
1198 hw_bd.data(),
1199 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -07001200 TRY_CHECK_RC(OM::write(franz, *l2itf));
1201
1202 // flush Franz's state
1203 delete l2itf;
1204 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1205 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001206 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1207 hw_vxt.data(),
1208 hw_bd.data(),
1209 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001210 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1211 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001212 TRY_CHECK(OM::remove(franz));
1213}
1214
1215BOOST_AUTO_TEST_CASE(test_vlan) {
1216 VppInit vi;
1217 const std::string noam = "NoamChomsky";
1218 rc_t rc = rc_t::OK;
1219
1220 std::string itf1_name = "host1";
1221 interface itf1(itf1_name,
1222 interface::type_t::AFPACKET,
1223 interface::admin_state_t::UP);
1224
1225 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001226 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001227
1228 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001229 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001230
1231 TRY_CHECK_RC(OM::write(noam, itf1));
1232
1233 sub_interface *vl33 = new sub_interface(itf1,
1234 interface::admin_state_t::UP,
1235 33);
1236
1237 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001238 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1239 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001240
1241 TRY_CHECK_RC(OM::write(noam, *vl33));
1242
1243 delete vl33;
1244 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1245 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001246 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1247 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1248 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1249 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001250
1251 TRY_CHECK(OM::remove(noam));
1252}
1253
1254BOOST_AUTO_TEST_CASE(test_acl) {
1255 VppInit vi;
1256 const std::string fyodor = "FyodorDostoyevsky";
1257 const std::string leo = "LeoTolstoy";
1258 rc_t rc = rc_t::OK;
1259
1260 /*
1261 * Fyodor adds an ACL in the input direction
1262 */
1263 std::string itf1_name = "host1";
1264 interface itf1(itf1_name,
1265 interface::type_t::AFPACKET,
1266 interface::admin_state_t::UP);
1267 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1268 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001269 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1270 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001271 TRY_CHECK_RC(OM::write(fyodor, itf1));
1272
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001273 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1274 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1275 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1276 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1277 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1278 HW::item<bool> ae_binding(true, rc_t::OK);
1279 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1280 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1281
Neale Ranns812ed392017-10-16 04:20:13 -07001282 route::prefix_t src("10.10.10.10", 32);
1283 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1284 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1285
1286 std::string acl_name = "acl1";
1287 ACL::l3_list acl1(acl_name);
1288 acl1.insert(r2);
1289 acl1.insert(r1);
1290 ACL::l3_list::rules_t rules = {r1, r2};
1291
1292 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001293 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001294 TRY_CHECK_RC(OM::write(fyodor, acl1));
1295
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001296 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1297 ACL::l3_list acl2(acl_name);
1298 acl2.insert(r3);
1299 ACL::l3_list::rules_t rules2 = {r3};
1300 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1301 TRY_CHECK_RC(OM::write(fyodor, acl2));
1302
Neale Ranns812ed392017-10-16 04:20:13 -07001303 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1304 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001305 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1306 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001307 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1308
1309 /**
1310 * Leo adds an L2 ACL in the output direction
1311 */
1312 TRY_CHECK_RC(OM::write(leo, itf1));
1313
1314 std::string l2_acl_name = "l2_acl1";
1315 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1316 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1317 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1318 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1319
1320 ACL::l2_list l2_acl(l2_acl_name);
1321 l2_acl.insert(l2_r2);
1322 l2_acl.insert(l2_r1);
1323
1324 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1325
1326 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001327 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001328 TRY_CHECK_RC(OM::write(leo, l2_acl));
1329
1330 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1331 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001332 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001333 hw_ifh.data(), l2_hw_acl.data()));
1334 TRY_CHECK_RC(OM::write(leo, *l2b));
1335
1336 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001337 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1338 hw_ifh.data(), l2_hw_acl.data()));
1339 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001340 TRY_CHECK(OM::remove(leo));
1341
1342 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001343 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001344 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1345 rc_t::OK);
1346 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001347 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001348 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001349 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001350 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001351 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1352 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001353
1354 TRY_CHECK(OM::remove(fyodor));
1355}
1356
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001357BOOST_AUTO_TEST_CASE(test_igmp) {
1358 VppInit vi;
1359 const std::string Isaiah = "IsaiahBerlin";
1360 rc_t rc = rc_t::OK;
1361
Ole Troan003d5da2018-12-18 12:23:13 +01001362 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1363 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1364 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001365
1366 std::string itf3_name = "host3";
1367 interface itf3(itf3_name,
1368 interface::type_t::AFPACKET,
1369 interface::admin_state_t::UP);
1370 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1371 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1372 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1373 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1374 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1375
1376 igmp_binding *ib = new igmp_binding(itf3);
1377 HW::item<bool> hw_binding(true, rc_t::OK);
1378 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1379 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1380
1381 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1382
1383 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1384 HW::item<bool> hw_as_listen(true, rc_t::OK);
1385 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1386 TRY_CHECK_RC(OM::write(Isaiah, *il));
1387
1388 delete il;
1389 delete ib;
1390
1391 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1392 rc_t::OK);
1393 STRICT_ORDER_OFF();
1394 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1395 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1396 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1397 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1398
1399 TRY_CHECK(OM::remove(Isaiah));
1400}
1401
Neale Ranns812ed392017-10-16 04:20:13 -07001402BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1403 VppInit vi;
1404 const std::string kurt = "KurtVonnegut";
1405 rc_t rc = rc_t::OK;
1406
1407 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1408 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1409
1410 arp_proxy_config ap(low, high);
1411 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001412 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001413 TRY_CHECK_RC(OM::write(kurt, ap));
1414
1415 std::string itf3_name = "host3";
1416 interface itf3(itf3_name,
1417 interface::type_t::AFPACKET,
1418 interface::admin_state_t::UP);
1419 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1420 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001421 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1422 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001423 TRY_CHECK_RC(OM::write(kurt, itf3));
1424
Neale Ranns0053de62018-05-22 08:40:52 -07001425 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001426 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001427 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001428 TRY_CHECK_RC(OM::write(kurt, *apb));
1429
1430 delete apb;
1431
1432 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1433 rc_t::OK);
1434 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001435 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1436 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1437 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1438 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001439
1440 TRY_CHECK(OM::remove(kurt));
1441}
1442
Mohsin Kazmie23edac2018-09-25 18:26:52 +02001443BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1444 VppInit vi;
1445 const std::string eliot = "EliotReed";
1446 rc_t rc = rc_t::OK;
1447
1448 /*
1449 * Interface 1 is the tx interface
1450 */
1451 std::string itf1_name = "tx-itf";
1452 interface itf1(itf1_name,
1453 interface::type_t::AFPACKET,
1454 interface::admin_state_t::UP);
1455 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1456 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1457 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1458 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1459 TRY_CHECK_RC(OM::write(eliot, itf1));
1460
1461 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1462
1463 /*
1464 * Interface 2 is the rx interface
1465 */
1466 std::string itf2_name = "rx-itf";
1467 interface itf2(itf2_name,
1468 interface::type_t::AFPACKET,
1469 interface::admin_state_t::UP);
1470
1471 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1472 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1473 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1474 TRY_CHECK_RC(OM::write(eliot, itf2));
1475
1476 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1477 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1478 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1479 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1480 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1481
1482 delete ip_punt;
1483
1484 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1485 STRICT_ORDER_OFF();
1486 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1487 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1488 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1489 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1490 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1491
1492 TRY_CHECK(OM::remove(eliot));
1493}
1494
Neale Ranns812ed392017-10-16 04:20:13 -07001495BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1496 VppInit vi;
1497 const std::string eric = "EricAmbler";
1498 rc_t rc = rc_t::OK;
1499
1500 /*
1501 * Interface 1 has the L3 address
1502 */
1503 std::string itf1_name = "host1";
1504 interface itf1(itf1_name,
1505 interface::type_t::AFPACKET,
1506 interface::admin_state_t::UP);
1507 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1508 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001509 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1510 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001511 TRY_CHECK_RC(OM::write(eric, itf1));
1512
1513 route::prefix_t pfx_10("10.10.10.10", 24);
1514 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1515 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1516 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001517 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001518 TRY_CHECK_RC(OM::write(eric, *l3));
1519
1520 /*
1521 * Interface 2 is unnumbered
1522 */
1523 std::string itf2_name = "host2";
1524 interface itf2(itf2_name,
1525 interface::type_t::AFPACKET,
1526 interface::admin_state_t::UP);
1527
1528 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001529 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1530 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001531 TRY_CHECK_RC(OM::write(eric, itf2));
1532
1533 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1534 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1535 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001536 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001537 TRY_CHECK_RC(OM::write(eric, *ipun));
1538
1539 delete l3;
1540 delete ipun;
1541
1542 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1543 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001544 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1545 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1546 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1547 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1548 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1549 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001550
1551 TRY_CHECK(OM::remove(eric));
1552}
1553
1554BOOST_AUTO_TEST_CASE(test_ip6nd) {
1555 VppInit vi;
1556 const std::string paulo = "PauloCoelho";
1557 rc_t rc = rc_t::OK;
1558
1559 /*
1560 * ra config
1561 */
1562 std::string itf_name = "host_ip6nd";
1563 interface itf(itf_name,
1564 interface::type_t::AFPACKET,
1565 interface::admin_state_t::UP);
1566 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1567 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001568 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1569 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001570 TRY_CHECK_RC(OM::write(paulo, itf));
1571
1572 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1573 l3_binding *l3 = new l3_binding(itf, pfx_10);
1574 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1575 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001576 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001577 TRY_CHECK_RC(OM::write(paulo, *l3));
1578
1579 ra_config ra(0, 1, 0, 4);
1580 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1581 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1582 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1583 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1584 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1585
1586 /*
1587 * ra prefix
1588 */
1589 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1590 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1591 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1592 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1593 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1594 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1595
1596 delete ip6pfx;
1597
1598 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1599
1600 delete ip6ra;
1601 delete l3;
1602
1603 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1604
1605 STRICT_ORDER_OFF();
1606 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001607 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1608 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1609 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001610
1611 TRY_CHECK(OM::remove(paulo));
1612}
1613
1614BOOST_AUTO_TEST_CASE(test_interface_span) {
1615 VppInit vi;
1616 const std::string elif = "ElifShafak";
1617 rc_t rc = rc_t::OK;
1618
1619 /*
1620 * Interface 1 to be mirrored
1621 */
1622 std::string itf1_name = "port-from";
1623 interface itf1(itf1_name,
1624 interface::type_t::AFPACKET,
1625 interface::admin_state_t::UP);
1626 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1627 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001628 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1629 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001630 TRY_CHECK_RC(OM::write(elif, itf1));
1631
1632 /*
1633 * Interface 2 where traffic is mirrored
1634 */
1635 std::string itf2_name = "port-to";
1636 interface itf2(itf2_name,
1637 interface::type_t::AFPACKET,
1638 interface::admin_state_t::UP);
1639
1640 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1641 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1642
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001643 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1644 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001645 TRY_CHECK_RC(OM::write(elif, itf2));
1646
1647 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1648 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1649 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001650 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 -07001651 TRY_CHECK_RC(OM::write(elif, *itf_span));
1652
1653 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1654 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1655
1656 delete itf_span;
1657 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001658 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1659 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1660 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1661 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1662 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001663
1664 TRY_CHECK(OM::remove(elif));
1665}
1666
1667BOOST_AUTO_TEST_CASE(test_routing) {
1668 VppInit vi;
1669 const std::string ian = "IanFleming";
1670 rc_t rc = rc_t::OK;
1671
1672 /*
1673 * non-default route domain
1674 */
1675 route_domain rd4(1);
1676 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1677 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1678 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1679 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1680 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1681 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1682 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1683 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001684 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1685 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001686 TRY_CHECK_RC(OM::write(ian, rd4));
1687
1688 /*
1689 * a couple of interfaces
1690 */
1691 std::string itf1_name = "af1";
1692 interface itf1(itf1_name,
1693 interface::type_t::AFPACKET,
1694 interface::admin_state_t::UP);
1695 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1696 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1697 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001698 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1699 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001700 TRY_CHECK_RC(OM::write(ian, itf1));
1701
1702 std::string itf2_name = "af2";
1703 interface *itf2 = new interface(itf2_name,
1704 interface::type_t::AFPACKET,
1705 interface::admin_state_t::UP,
1706 rd4);
1707
1708 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1709 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1710 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001711 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1712 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1713 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1714 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001715 TRY_CHECK_RC(OM::write(ian, *itf2));
1716
1717 /*
1718 * prefix on each interface
1719 */
1720 route::prefix_t pfx_10("10.10.10.10", 24);
1721 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1722 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1723 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001724 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001725 TRY_CHECK_RC(OM::write(ian, *l3_10));
1726 route::prefix_t pfx_11("11.11.11.11", 24);
1727 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1728 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1729 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001730 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001731 TRY_CHECK_RC(OM::write(ian, *l3_11));
1732
1733 /*
1734 * A route via interface 1 in the default table
1735 */
1736 route::prefix_t pfx_5("5.5.5.5", 32);
Neale Ranns6ad72312019-01-10 08:56:38 -08001737 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1738 route::path *path_9 = new route::path(nh_9, itf1);
Neale Ranns812ed392017-10-16 04:20:13 -07001739 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1740 route::path *path_10 = new route::path(nh_10, itf1);
1741 route::ip_route *route_5 = new route::ip_route(pfx_5);
1742 route_5->add(*path_10);
Neale Ranns6ad72312019-01-10 08:56:38 -08001743 route_5->add(*path_9);
Neale Ranns812ed392017-10-16 04:20:13 -07001744 HW::item<bool> hw_route_5(true, rc_t::OK);
Neale Ranns6ad72312019-01-10 08:56:38 -08001745 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_9));
1746 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001747 TRY_CHECK_RC(OM::write(ian, *route_5));
1748
Neale Ranns6ad72312019-01-10 08:56:38 -08001749 route_5->remove(*path_9);
1750 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_9));
1751 TRY_CHECK_RC(OM::write(ian, *route_5));
1752
1753 delete path_9;
1754
Neale Ranns812ed392017-10-16 04:20:13 -07001755 /*
1756 * A route via interface 2 in the non-default table
1757 */
1758 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1759 route::path *path_11 = new route::path(nh_11, *itf2);
Neale Ranns6ad72312019-01-10 08:56:38 -08001760 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1761 route::path *path_12 = new route::path(nh_12, *itf2);
Neale Ranns812ed392017-10-16 04:20:13 -07001762 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1763 route_5_2->add(*path_11);
1764 HW::item<bool> hw_route_5_2(true, rc_t::OK);
Neale Ranns6ad72312019-01-10 08:56:38 -08001765 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1766 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1767
1768 route_5_2->add(*path_12);
1769 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_12));
Neale Ranns812ed392017-10-16 04:20:13 -07001770 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1771
1772 /*
1773 * An ARP entry for the neighbour on itf1
1774 */
1775 HW::item<bool> hw_neighbour(true, rc_t::OK);
1776 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001777 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns6fef74a2019-02-12 06:18:30 -08001778 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1779 mac_n, nh_10,
1780 neighbour::flags_t::STATIC));
Neale Ranns812ed392017-10-16 04:20:13 -07001781 TRY_CHECK_RC(OM::write(ian, *ne));
1782
1783 /*
1784 * A DVR route
1785 */
1786 route::prefix_t pfx_6("6.6.6.6", 32);
1787 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1788 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1789 route_dvr->add(*path_l2);
1790 HW::item<bool> hw_route_dvr(true, rc_t::OK);
Neale Ranns6ad72312019-01-10 08:56:38 -08001791 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
Neale Ranns812ed392017-10-16 04:20:13 -07001792 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1793
Neale Ranns7c03ed42018-12-27 03:21:28 -08001794 /*
1795 * a multicast route
1796 */
1797 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1798 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1799
1800 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1801 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1802 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1803 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1804 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1805 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1806 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1807 *mp1, route::itf_flags_t::FORWARD));
1808 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1809 *mp2, route::itf_flags_t::FORWARD));
1810 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1811 *mp1, route::itf_flags_t::ACCEPT));
1812 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1813
Neale Ranns812ed392017-10-16 04:20:13 -07001814 STRICT_ORDER_OFF();
1815 // delete the stack objects that hold references to others
1816 // so the OM::remove is the call that removes the last reference
1817 delete l3_11;
1818 delete l3_10;
1819 delete itf2;
1820 delete route_5;
Neale Ranns812ed392017-10-16 04:20:13 -07001821 delete route_5_2;
Neale Ranns812ed392017-10-16 04:20:13 -07001822 delete route_dvr;
Neale Ranns812ed392017-10-16 04:20:13 -07001823 delete ne;
Neale Ranns7c03ed42018-12-27 03:21:28 -08001824 delete mroute_4;
1825
1826 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1827 *mp1, route::itf_flags_t::FORWARD));
1828 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1829 *mp2, route::itf_flags_t::FORWARD));
1830 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1831 *mp1, route::itf_flags_t::ACCEPT));
1832
1833 delete mp1;
1834 delete mp2;
1835
Neale Ranns6fef74a2019-02-12 06:18:30 -08001836 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1837 mac_n, nh_10,
1838 neighbour::flags_t::STATIC));
Neale Ranns6ad72312019-01-10 08:56:38 -08001839 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1840 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1841 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1842 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_10));
1843
1844 delete path_10;
1845 delete path_11;
1846 delete path_12;
1847 delete path_l2;
1848
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001849 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1850 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1851 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1852 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1853 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1854 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1855 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1856 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1857 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1858 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001859
1860 TRY_CHECK(OM::remove(ian));
1861}
1862
1863BOOST_AUTO_TEST_CASE(test_nat) {
1864 VppInit vi;
1865 const std::string gs = "GeorgeSimenon";
1866 rc_t rc = rc_t::OK;
1867
1868 /*
1869 * Inside Interface
1870 */
1871 std::string itf_in_name = "inside";
1872 interface itf_in(itf_in_name,
1873 interface::type_t::AFPACKET,
1874 interface::admin_state_t::UP);
1875 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1876 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1877 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001878 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1879 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001880 TRY_CHECK_RC(OM::write(gs, itf_in));
1881
1882 /*
1883 * outside
1884 */
1885 std::string itf_out_name = "port-to";
1886 interface itf_out(itf_out_name,
1887 interface::type_t::AFPACKET,
1888 interface::admin_state_t::UP);
1889
1890 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1891 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1892 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1893
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001894 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1895 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001896 TRY_CHECK_RC(OM::write(gs, itf_out));
1897
1898 /*
1899 * A NAT static mapping
1900 */
1901 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1902 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1903
1904 nat_static ns(in_addr, out_addr);
1905 HW::item<bool> hw_ns(true, rc_t::OK);
1906
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001907 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001908 TRY_CHECK_RC(OM::write(gs, ns));
1909
1910 /*
1911 * bind nat inside and out
1912 */
1913 nat_binding *nb_in = new nat_binding(itf_in,
1914 direction_t::INPUT,
1915 l3_proto_t::IPV4,
1916 nat_binding::zone_t::INSIDE);
1917 HW::item<bool> hw_nb_in(true, rc_t::OK);
1918
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001919 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1920 hw_ifh.data().value(),
1921 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001922 TRY_CHECK_RC(OM::write(gs, *nb_in));
1923
1924 nat_binding *nb_out = new nat_binding(itf_out,
1925 direction_t::INPUT,
1926 l3_proto_t::IPV4,
1927 nat_binding::zone_t::OUTSIDE);
1928 HW::item<bool> hw_nb_out(true, rc_t::OK);
1929
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001930 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1931 hw_ifh2.data().value(),
1932 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001933 TRY_CHECK_RC(OM::write(gs, *nb_out));
1934
1935
1936 STRICT_ORDER_OFF();
1937 delete nb_in;
1938 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001939 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1940 hw_ifh.data().value(),
1941 nat_binding::zone_t::INSIDE));
1942 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1943 hw_ifh2.data().value(),
1944 nat_binding::zone_t::OUTSIDE));
1945 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1946 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1947 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1948 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1949 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001950
1951 TRY_CHECK(OM::remove(gs));
1952}
1953
1954BOOST_AUTO_TEST_CASE(test_interface_events) {
1955 VppInit vi;
1956 MockListener ml;
1957
1958 HW::item<bool> hw_want(true, rc_t::OK);
1959
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001960 ADD_EXPECT(interface_cmds::events_cmd(ml));
1961 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07001962
1963 HW::enqueue(itf);
1964 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07001965}
1966
Neale Ranns352ea0c2017-11-14 11:04:28 -08001967BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1968 VppInit vi;
1969 const std::string rene = "ReneGoscinny";
1970 rc_t rc = rc_t::OK;
1971
1972 /*
1973 * Create an interface with two IP addresses
1974 */
1975 std::string itf1_name = "host1";
1976 interface itf1(itf1_name,
1977 interface::type_t::AFPACKET,
1978 interface::admin_state_t::UP);
1979 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1980 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1981 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1982 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1983 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1984 TRY_CHECK_RC(OM::write(rene, itf1));
1985
1986 route::prefix_t pfx_10("10.10.10.10", 24);
1987 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1988 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1989 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1990 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1991 TRY_CHECK_RC(OM::write(rene, *l3_1));
1992
1993 route::prefix_t pfx_11("10.10.11.11", 24);
1994 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1995 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1996 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1997 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1998 TRY_CHECK_RC(OM::write(rene, *l3_2));
1999
2000 route_domain rd(1);
2001 HW::item<bool> hw_rd_create(true, rc_t::OK);
2002 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2003 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2004 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2005 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2006 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2007 TRY_CHECK_RC(OM::write(rene, rd));
2008
2009 /*
2010 * update the interface to change to a new route-domain
2011 * expect that the l3-bindings are removed and readded.
2012 */
2013 interface *itf2 = new interface(itf1_name,
2014 interface::type_t::AFPACKET,
2015 interface::admin_state_t::UP,
2016 rd);
2017 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2018 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2019 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2020 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2021 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2022 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2023 TRY_CHECK_RC(OM::write(rene, *itf2));
2024
2025 /*
2026 * mve the interface back to the default route-domain
2027 */
2028 interface itf3(itf1_name,
2029 interface::type_t::AFPACKET,
2030 interface::admin_state_t::UP);
2031 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2032 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2033 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2034 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2035 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2036 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2037 TRY_CHECK_RC(OM::write(rene, itf3));
2038
2039 delete l3_1;
2040 delete l3_2;
2041 delete itf2;
2042
2043 STRICT_ORDER_OFF();
2044 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2045 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2046 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2047 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2048 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2049 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2050
2051 TRY_CHECK(OM::remove(rene));
2052}
2053
Neale Rannsd3464b52017-12-07 08:48:02 -08002054BOOST_AUTO_TEST_CASE(test_prefixes) {
2055 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2056
2057 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2058
2059 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2060
2061 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2062 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2063
2064 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2065 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2066 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2067
2068 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2069
2070 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2071
2072 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2073
2074 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2075 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2076 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2077
2078 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2079
2080 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2081 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2082 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2083
2084 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2085
2086 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2087 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2088 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2089
2090}
2091
Neale Ranns208c29a2018-04-11 08:08:30 -07002092BOOST_AUTO_TEST_CASE(test_pipes) {
2093 VppInit vi;
2094 const std::string gk = "GKChesterton";
2095
2096 const std::string pipe_name_1 = "pipe1";
2097 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2098 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2099 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2100
2101 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2102 rc_t::OK);
2103 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2104 rc_t::OK);
2105 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2106 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2107 TRY_CHECK_RC(OM::write(gk, pipe1));
2108
2109 pipe1.set_ends(hw_hdl_pair.data());
2110
2111 // put each end of the pipe in a BD
2112 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2113 bridge_domain::arp_term_mode_t::OFF,
2114 bridge_domain::flood_mode_t::OFF,
2115 bridge_domain::mac_age_mode_t::ON);
2116
2117 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2118 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2119 bridge_domain::learning_mode_t::OFF,
2120 bridge_domain::arp_term_mode_t::OFF,
2121 bridge_domain::flood_mode_t::OFF,
2122 bridge_domain::mac_age_mode_t::ON));
2123
2124 TRY_CHECK_RC(OM::write(gk, bd1));
2125
2126 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2127 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2128
2129 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2130 pipe1.east()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002131 hw_bd.data(),
2132 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002133 TRY_CHECK_RC(OM::write(gk, *l2_1));
2134
2135 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2136 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2137
2138 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2139 pipe1.west()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002140 hw_bd.data(),
2141 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002142 TRY_CHECK_RC(OM::write(gk, *l2_2));
2143
2144 STRICT_ORDER_OFF();
2145
2146 delete l2_1;
2147 delete l2_2;
2148 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2149 pipe1.east()->handle(),
2150 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002151 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002152 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2153 pipe1.west()->handle(),
2154 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002155 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002156 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2157 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2158 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2159 TRY_CHECK(OM::remove(gk));
2160}
2161
Neale Ranns812ed392017-10-16 04:20:13 -07002162BOOST_AUTO_TEST_SUITE_END()