blob: f55dd3ebbc36bc0f7103949cfc9ab4ec6dddc91d [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
Neale Rannsb02d2302019-06-07 03:54:21 -040094 // std::cout << " ExpException here: " << number << std::endl;
Neale Ranns812ed392017-10-16 04:20:13 -070095 }
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 Rannsb02d2302019-06-07 03:54:21 -0400193 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_create_cmd))
194 {
195 rc = handle_derived<interface_cmds::bvi_create_cmd>(f_exp, f_act);
196 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800197 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
198 {
199 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
200 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100201 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
202 {
203 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
204 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700205 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700206 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700207 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700208 }
Neale Rannsb02d2302019-06-07 03:54:21 -0400209 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_delete_cmd))
210 {
211 rc = handle_derived<interface_cmds::bvi_delete_cmd>(f_exp, f_act);
212 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700213 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700214 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700215 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700216 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800217 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
218 {
219 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
220 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100221 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
222 {
223 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
224 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700225 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700226 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700227 rc = handle_derived<interface_cmds::state_change_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_table_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700230 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700231 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700232 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700233 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700234 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700235 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700236 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700237 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
Neale Ranns812ed392017-10-16 04:20:13 -0700238 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700239 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700240 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100241 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
242 {
243 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
244 }
245 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
246 {
247 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
248 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700249 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700250 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700251 rc = handle_derived<route_domain_cmds::create_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_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700254 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700255 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700256 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700257 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700258 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700259 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700260 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700261 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700262 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700263 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700264 }
Neale Ranns7c03ed42018-12-27 03:21:28 -0800265 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
266 {
267 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
268 }
269 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
270 {
271 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
272 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700273 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700274 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700275 rc = handle_derived<neighbour_cmds::create_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(neighbour_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700278 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700279 rc = handle_derived<neighbour_cmds::delete_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(l3_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700282 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700283 rc = handle_derived<l3_binding_cmds::bind_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(l3_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700286 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700287 rc = handle_derived<l3_binding_cmds::unbind_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_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700290 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700291 rc = handle_derived<bridge_domain_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_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700294 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700295 rc = handle_derived<bridge_domain_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_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_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_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_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(bridge_domain_arp_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700306 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700307 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700308 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700309 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700310 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700311 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700312 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700313 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700314 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700315 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700316 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700317 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700318 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700319 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700320 }
Neale Ranns53322002019-02-22 02:48:25 -0800321 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700322 {
Neale Ranns53322002019-02-22 02:48:25 -0800323 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700324 }
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +0200325 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
326 {
327 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
328 }
329 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
330 {
331 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
332 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700333 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700334 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700335 rc = handle_derived<vxlan_tunnel_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(vxlan_tunnel_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700338 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700339 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700340 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700341 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700342 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700343 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700344 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700345 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700346 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700347 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700348 }
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +0100349 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
350 {
351 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
352 }
Mohsin Kazmi04def742018-03-07 19:53:51 +0100353 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
354 {
355 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
356 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700357 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700358 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700359 rc = handle_derived<ACL::list_cmds::l3_update_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::list_cmds::l3_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700362 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700363 rc = handle_derived<ACL::list_cmds::l3_delete_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::binding_cmds::l3_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700366 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700367 rc = handle_derived<ACL::binding_cmds::l3_bind_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::binding_cmds::l3_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700370 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700371 rc = handle_derived<ACL::binding_cmds::l3_unbind_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::list_cmds::l2_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700374 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700375 rc = handle_derived<ACL::list_cmds::l2_update_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::list_cmds::l2_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700378 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700379 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700380 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700381 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700382 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700383 rc = handle_derived<ACL::binding_cmds::l2_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(ACL::binding_cmds::l2_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700386 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700387 rc = handle_derived<ACL::binding_cmds::l2_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_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700390 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700391 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700392 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700393 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700394 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700395 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700396 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700397 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700398 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700399 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700400 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700401 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700402 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700403 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700404 }
Mohsin Kazmi12fe8782018-10-30 19:24:34 +0100405 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
406 {
407 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
408 }
409 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
410 {
411 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
412 }
413 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
414 {
415 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
416 }
417 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
418 {
419 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
420 }
Mohsin Kazmie23edac2018-09-25 18:26:52 +0200421 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
422 {
423 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
424 }
425 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
426 {
427 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
428 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700429 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700430 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700431 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700432 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700433 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700434 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700435 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700436 }
437 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
438 {
439 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
440 }
441 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
442 {
443 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
444 }
445 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
446 {
447 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
448 }
449 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
450 {
451 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
452 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700453 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700454 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700455 rc = handle_derived<interface_span_cmds::config_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(interface_span_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700458 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700459 rc = handle_derived<interface_span_cmds::unconfig_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_static_cmds::create_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700462 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700463 rc = handle_derived<nat_static_cmds::create_44_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_static_cmds::delete_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700466 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700467 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700468 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700469 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700470 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700471 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700472 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700473 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700474 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700475 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700476 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700477 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700478 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700479 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700480 }
Neale Ranns208c29a2018-04-11 08:08:30 -0700481 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
482 {
483 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
484 }
485 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
486 {
487 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
488 }
Neale Ranns812ed392017-10-16 04:20:13 -0700489 else
490 {
491 throw ExpException(2);
492 }
493
494 // if we get here then we found the match.
495 m_exp_queue.erase(it_exp);
496 m_act_queue.erase(it_act);
497 delete f_exp;
498 delete f_act;
499
500 // return any injected failures to the agent
501 if (rc_t::OK != rc && rc_t::NOOP != rc)
502 {
503 return (rc);
504 }
505
506 matched = true;
507 break;
508 }
509 catch (ExpException &e)
510 {
511 // The expected and actual do not match
512 if (m_strict_order)
513 {
514 // in strict ordering mode this is fatal, so rethrow
515 throw e;
516 }
517 else
518 {
519 // move the iterator onto the next in the expected list and
520 // check for a match
521 ++it_exp;
522 }
523 }
524 }
525
526 if (!matched)
527 throw ExpException(3);
528 }
529
530 return (rc);
531 }
532private:
533
534 template <typename T>
535 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
536 {
537 const T *i_exp;
538 T *i_act;
539
540 i_exp = dynamic_cast<const T*>(f_exp);
541 i_act = dynamic_cast<T*>(f_act);
542 if (!(*i_exp == *i_act))
543 {
544 throw ExpException(4);
545 }
546 // pass the data and return code to the agent
547 i_act->item() = i_exp->item();
548
549 return (i_act->item().rc());
550 }
551
552 // The Q to push the expectations on
553 std::deque<cmd*> m_exp_queue;
554
555 // the queue to push the actual events on
556 std::deque<cmd*> m_act_queue;
557
558 // control whether the expected queue is strictly ordered.
559 bool m_strict_order;
560};
561
562class VppInit {
563public:
564 std::string name;
565 MockCmdQ *f;
566
567 VppInit()
568 : name("vpp-ut"),
569 f(new MockCmdQ())
570 {
571 HW::init(f);
572 OM::init();
573 logger().set(log_level_t::DEBUG);
574 }
575
576 ~VppInit() {
577 delete f;
578 }
579};
580
Neale Rannsd3464b52017-12-07 08:48:02 -0800581BOOST_AUTO_TEST_SUITE(vom)
Neale Ranns812ed392017-10-16 04:20:13 -0700582
583#define TRY_CHECK_RC(stmt) \
584{ \
585 try { \
586 BOOST_CHECK(rc_t::OK == stmt); \
587 } \
588 catch (ExpException &e) \
589 { \
590 BOOST_CHECK(false); \
591 } \
592 BOOST_CHECK(vi.f->is_empty()); \
593}
594
595#define TRY_CHECK(stmt) \
596{ \
597 try { \
598 stmt; \
599 } \
600 catch (ExpException &e) \
601 { \
602 BOOST_CHECK(false); \
603 } \
604 BOOST_CHECK(vi.f->is_empty()); \
605}
606
607#define ADD_EXPECT(stmt) \
608 vi.f->expect(new stmt)
609
610#define STRICT_ORDER_OFF() \
611 vi.f->strict_order(false)
612
613BOOST_AUTO_TEST_CASE(test_interface) {
614 VppInit vi;
615 const std::string go = "GeorgeOrwell";
616 const std::string js = "JohnSteinbeck";
617 rc_t rc = rc_t::OK;
618
619 /*
620 * George creates and deletes the interface
621 */
622 std::string itf1_name = "afpacket1";
623 interface itf1(itf1_name,
624 interface::type_t::AFPACKET,
625 interface::admin_state_t::UP);
626
627 /*
628 * set the expectation for a afpacket interface create.
629 * 2 is the interface handle VPP [mock] assigns
630 */
631 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700632 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700633
634 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700635 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700636
637 TRY_CHECK_RC(OM::write(go, itf1));
638
639 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700640 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
641 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700642
643 TRY_CHECK(OM::remove(go));
644
645 /*
646 * George creates the interface, then John brings it down.
647 * George's remove is a no-op, sice John also owns the interface
648 */
649 interface itf1b(itf1_name,
650 interface::type_t::AFPACKET,
651 interface::admin_state_t::DOWN);
652
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700653 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
654 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700655 TRY_CHECK_RC(OM::write(go, itf1));
656
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700657 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700658 TRY_CHECK_RC(OM::write(js, itf1b));
659
660 TRY_CHECK(OM::remove(go));
661
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700662 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700663 TRY_CHECK(OM::remove(js));
664
665 /*
666 * George adds an interface, then we flush all of Geroge's state
667 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700668 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
669 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700670 TRY_CHECK_RC(OM::write(go, itf1));
671
672 TRY_CHECK(OM::mark(go));
673
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700674 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
675 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700676 TRY_CHECK(OM::sweep(go));
677
678 /*
679 * George adds an interface. mark stale. update the same interface. sweep
680 * and expect no delete
681 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700682 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
683 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700684 TRY_CHECK_RC(OM::write(go, itf1b));
685
686 TRY_CHECK(OM::mark(go));
687
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700688 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700689 TRY_CHECK_RC(OM::write(go, itf1));
690
691 TRY_CHECK(OM::sweep(go));
692
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700693 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
694 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700695 TRY_CHECK(OM::remove(go));
696
697 /*
698 * George adds an insterface, then we mark that state. Add a second interface
699 * an flush the first that is now stale.
700 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700701 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
702 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700703 TRY_CHECK_RC(OM::write(go, itf1));
704
705 TRY_CHECK(OM::mark(go));
706
707 std::string itf2_name = "afpacket2";
Neale Ranns4ef42262018-02-20 08:10:44 -0800708 std::string itf2_tag = "uuid-of-afpacket2-interface";
Neale Ranns812ed392017-10-16 04:20:13 -0700709 interface itf2(itf2_name,
710 interface::type_t::AFPACKET,
Neale Ranns4ef42262018-02-20 08:10:44 -0800711 interface::admin_state_t::UP,
712 itf2_tag);
Neale Ranns812ed392017-10-16 04:20:13 -0700713 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
714
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700715 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
Neale Ranns4ef42262018-02-20 08:10:44 -0800716 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700717 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700718 TRY_CHECK_RC(OM::write(go, itf2));
719
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700720 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
721 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700722 TRY_CHECK(OM::sweep(go));
723
724 TRY_CHECK(OM::mark(go));
725
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700726 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
727 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700728 TRY_CHECK(OM::sweep(go));
Neale Ranns4ef42262018-02-20 08:10:44 -0800729
730
731 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
732 std::string itf3_tag = "uuid-of-vhost_user1-interface";
733 interface itf3(itf3_name,
734 interface::type_t::VHOST,
735 interface::admin_state_t::UP,
736 itf3_tag);
737 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
738
739 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
740 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
741 TRY_CHECK_RC(OM::write(go, itf3));
742
743 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
744 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
745 TRY_CHECK(OM::remove(go));
Neale Ranns812ed392017-10-16 04:20:13 -0700746}
747
748BOOST_AUTO_TEST_CASE(test_bvi) {
749 VppInit vi;
750 const std::string ernest = "ErnestHemmingway";
751 const std::string graham = "GrahamGreene";
752 rc_t rc = rc_t::OK;
753 l3_binding *l3;
754
755 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
756 rc_t::OK);
757 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
758 rc_t::OK);
759
760 /*
761 * Enrest creates a BVI with address 10.10.10.10/24
762 */
763 route::prefix_t pfx_10("10.10.10.10", 24);
764
765 const std::string bvi_name = "bvi1";
766 interface itf(bvi_name,
767 interface::type_t::BVI,
768 interface::admin_state_t::UP);
769 HW::item<handle_t> hw_ifh(4, rc_t::OK);
770 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
771
Neale Rannsb02d2302019-06-07 03:54:21 -0400772 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh, bvi_name));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700773 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
774 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700775 TRY_CHECK_RC(OM::write(ernest, itf));
776
777 l3 = new l3_binding(itf, pfx_10);
778 HW::item<bool> hw_l3_bind(true, rc_t::OK);
779 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700780 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700781 TRY_CHECK_RC(OM::write(ernest, *l3));
782
783 // change the MAC address on the BVI
784 interface itf_new_mac(bvi_name,
785 interface::type_t::BVI,
786 interface::admin_state_t::UP);
787 l2_address_t l2_addr({0,1,2,3,4,5});
788 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
789 itf_new_mac.set(l2_addr);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700790 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700791 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
792
793 // create/write the interface to the OM again but with an unset MAC
794 // this should not generate a MAC address update
795 TRY_CHECK_RC(OM::write(ernest, itf));
796
797 // change the MAC address on the BVI - again
798 interface itf_new_mac2(bvi_name,
799 interface::type_t::BVI,
800 interface::admin_state_t::UP);
801 l2_address_t l2_addr2({0,1,2,3,4,6});
802 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
803 itf_new_mac2.set(l2_addr2);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700804 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700805 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
806
807 delete l3;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700808 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
809 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Rannsb02d2302019-06-07 03:54:21 -0400810 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700811 TRY_CHECK(OM::remove(ernest));
812
813 /*
814 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
815 */
816 route_domain rd(1);
817 HW::item<bool> hw_rd4_create(true, rc_t::OK);
818 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
819 HW::item<bool> hw_rd6_create(true, rc_t::OK);
820 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
821 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
822 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
823 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
824 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700825 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
826 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700827 TRY_CHECK_RC(OM::write(graham, rd));
828
829 const std::string bvi2_name = "bvi2";
830 interface *itf2 = new interface(bvi2_name,
831 interface::type_t::BVI,
832 interface::admin_state_t::UP,
833 rd);
834 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
835
Neale Rannsb02d2302019-06-07 03:54:21 -0400836 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh2, bvi2_name));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700837 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
838 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
839 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
840 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700841
842 TRY_CHECK_RC(OM::write(graham, *itf2));
843
844 l3 = new l3_binding(*itf2, pfx_10);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700845 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700846 TRY_CHECK_RC(OM::write(graham, *l3));
847
848 delete l3;
849 delete itf2;
850
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700851 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
852 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
853 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
854 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
Neale Rannsb02d2302019-06-07 03:54:21 -0400855 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh2));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700856 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
857 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700858 TRY_CHECK(OM::remove(graham));
859}
860
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100861BOOST_AUTO_TEST_CASE(test_bond) {
862 VppInit vi;
863 const std::string cb = "CarolBerg";
864 rc_t rc = rc_t::OK;
865
866 /*
867 * creates the interfaces
868 */
869 std::string itf1_name = "afpacket1";
870 interface itf1(itf1_name,
871 interface::type_t::AFPACKET,
872 interface::admin_state_t::UP);
873
874 HW::item<handle_t> hw_ifh(2, rc_t::OK);
875 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
876
877 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
879
880 TRY_CHECK_RC(OM::write(cb, itf1));
881
882 std::string itf2_name = "afpacket2";
883 interface itf2(itf2_name,
884 interface::type_t::AFPACKET,
885 interface::admin_state_t::UP);
886
887
888 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
889 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
890 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
891
892 TRY_CHECK_RC(OM::write(cb, itf2));
893
894 std::string bond_name = "bond";
895 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
896 bond_interface::mode_t::LACP);
897
898 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
899 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
900 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
901 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
902
903 TRY_CHECK_RC(OM::write(cb, bond_itf));
904
905 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
906 bond_member::rate_t::SLOW);
907 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
908 bond_member::rate_t::SLOW);
909 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
910
911 HW::item<bool> bond_hw_bind(true, rc_t::OK);
912 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
913 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
914
915 TRY_CHECK_RC(OM::write(cb, *bgb));
916
917 delete bgb;
918 delete bm2;
919 delete bm1;
920
921 STRICT_ORDER_OFF();
922 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
923 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
924 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
925 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
926 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
927 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
928 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
929 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
930 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
931
932 TRY_CHECK(OM::remove(cb));
933}
934
Neale Ranns812ed392017-10-16 04:20:13 -0700935BOOST_AUTO_TEST_CASE(test_bridge) {
936 VppInit vi;
937 const std::string franz = "FranzKafka";
938 const std::string dante = "Dante";
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100939 const std::string jkr = "jkrowling";
Neale Ranns812ed392017-10-16 04:20:13 -0700940 rc_t rc = rc_t::OK;
941
942 /*
943 * Franz creates an interface, Bridge-domain, then binds the two
944 */
945
946 // interface create
947 std::string itf1_name = "afpacket1";
948 interface itf1(itf1_name,
949 interface::type_t::AFPACKET,
950 interface::admin_state_t::UP);
951
952 HW::item<handle_t> hw_ifh(3, rc_t::OK);
953 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
954 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700955 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
956 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700957
958 TRY_CHECK_RC(OM::write(franz, itf1));
959
960 // bridge-domain create
961 bridge_domain bd1(33);
962
963 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -0700964 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
965 bridge_domain::learning_mode_t::ON,
966 bridge_domain::arp_term_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -0400967 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -0700968 bridge_domain::flood_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -0400969 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -0700970 bridge_domain::mac_age_mode_t::OFF));
Neale Ranns812ed392017-10-16 04:20:13 -0700971
972 TRY_CHECK_RC(OM::write(franz, bd1));
973
974 // L2-interface create and bind
975 // this needs to be delete'd before the flush below, since it too maintains
976 // references to the BD and Interface
977 l2_binding *l2itf = new l2_binding(itf1, bd1);
978 HW::item<bool> hw_l2_bind(true, rc_t::OK);
979
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200980 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
981 hw_ifh.data(),
982 hw_bd.data(),
983 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -0700984 TRY_CHECK_RC(OM::write(franz, *l2itf));
985
986 /*
987 * Dante adds an interface to the same BD
988 */
989 std::string itf2_name = "afpacket2";
990 interface itf2(itf2_name,
991 interface::type_t::AFPACKET,
992 interface::admin_state_t::UP);
993
994 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700995 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
996 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700997 TRY_CHECK_RC(OM::write(dante, itf2));
998
999 // BD add is a no-op since it exists
1000 TRY_CHECK_RC(OM::write(dante, bd1));
1001
1002 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
Neale Ranns53322002019-02-22 02:48:25 -08001003 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
1004 l2itf2->set(l2_vtr::option_t::POP_1, 68);
Neale Ranns812ed392017-10-16 04:20:13 -07001005
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001006 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1007 hw_ifh2.data(),
1008 hw_bd.data(),
1009 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns53322002019-02-22 02:48:25 -08001010 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
Neale Ranns812ed392017-10-16 04:20:13 -07001011 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1012
1013 // Add some static entries to the bridge-domain
1014 HW::item<bool> hw_be1(true, rc_t::OK);
1015 mac_address_t mac1({0,1,2,3,4,5});
1016 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001017 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1018 false));
Neale Ranns812ed392017-10-16 04:20:13 -07001019 TRY_CHECK_RC(OM::write(dante, *be1));
1020
1021 // Add some entries to the bridge-domain ARP termination table
1022 HW::item<bool> hw_bea1(true, rc_t::OK);
1023 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1024
Neale Rannsfd920602017-11-23 12:15:00 -08001025 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001026 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
Neale Ranns812ed392017-10-16 04:20:13 -07001027 TRY_CHECK_RC(OM::write(dante, *bea1));
1028
1029 // flush Franz's state
1030 delete l2itf;
1031 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1032 rc_t::OK);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001033 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1034 hw_ifh.data(),
1035 hw_bd.data(),
1036 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001037 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1038 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001039 TRY_CHECK(OM::remove(franz));
1040
1041 // flush Dante's state - the order the interface and BD are deleted
1042 // is an uncontrollable artifact of the C++ object destruction.
1043 delete l2itf2;
1044 delete be1;
1045 delete bea1;
1046 STRICT_ORDER_OFF();
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001047 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1048 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001049 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1050 hw_ifh2.data(),
1051 hw_bd.data(),
1052 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001053
1054 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001055 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1056 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001057 TRY_CHECK(OM::remove(dante));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001058
1059 // test the BVI entry in l2fib
1060 bridge_domain bd2(99);
1061
1062 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001063 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1064 bridge_domain::learning_mode_t::ON,
1065 bridge_domain::arp_term_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -04001066 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -07001067 bridge_domain::flood_mode_t::ON,
Neale Rannsb02d2302019-06-07 03:54:21 -04001068 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns25b04942018-04-04 09:34:50 -07001069 bridge_domain::mac_age_mode_t::OFF));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001070
1071 TRY_CHECK_RC(OM::write(jkr, bd2));
1072
1073 std::string itf3_name = "bvi";
1074 interface itf3(itf3_name,
1075 interface::type_t::BVI,
1076 interface::admin_state_t::UP);
1077
1078 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
Neale Rannsb02d2302019-06-07 03:54:21 -04001079 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh3, itf3_name));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001080 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1081 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1082 TRY_CHECK_RC(OM::write(jkr, itf3));
1083
1084 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001085 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1086 hw_ifh3.data(),
1087 hw_bd2.data(),
1088 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001089 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1090
1091 HW::item<bool> hw_be2(true, rc_t::OK);
1092 mac_address_t mac2({0,1,2,3,4,5});
1093 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1094 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1095 TRY_CHECK_RC(OM::write(jkr, *be2));
1096
1097 delete l2itf3;
1098 delete be2;
1099 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001100 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1101 hw_ifh3.data(),
1102 hw_bd2.data(),
1103 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001104 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1105 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
Neale Rannsb02d2302019-06-07 03:54:21 -04001106 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh3));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001107 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1108 TRY_CHECK(OM::remove(jkr));
Neale Ranns812ed392017-10-16 04:20:13 -07001109}
1110
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +02001111BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1112 VppInit vi;
1113 const std::string nicholas = "NicholasAbercrombie";
1114 rc_t rc = rc_t::OK;
1115
1116 /*
1117 * Interface 1
1118 */
1119 std::string itf1_name = "host1";
1120 interface itf1(itf1_name,
1121 interface::type_t::AFPACKET,
1122 interface::admin_state_t::UP);
1123 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1124 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1125 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1126 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1127 TRY_CHECK_RC(OM::write(nicholas, itf1));
1128
1129 /*
1130 * Interface 2
1131 */
1132 std::string itf2_name = "host2";
1133 interface itf2(itf2_name,
1134 interface::type_t::AFPACKET,
1135 interface::admin_state_t::UP);
1136
1137 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1138 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1139 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1140 TRY_CHECK_RC(OM::write(nicholas, itf2));
1141
1142 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1143 HW::item<bool> xconnect_east(true, rc_t::OK);
1144 HW::item<bool> xconnect_west(true, rc_t::OK);
1145 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1146 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1147 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1148 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1149 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1150
1151 delete l2_xconn;
1152
1153 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1154 STRICT_ORDER_OFF();
1155 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1156 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1157 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1158 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1159 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1160 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1161
1162 TRY_CHECK(OM::remove(nicholas));
1163}
1164
Neale Ranns812ed392017-10-16 04:20:13 -07001165BOOST_AUTO_TEST_CASE(test_vxlan) {
1166 VppInit vi;
1167 const std::string franz = "FranzKafka";
1168 rc_t rc = rc_t::OK;
1169
1170 /*
1171 * Franz creates an interface, Bridge-domain, then binds the two
1172 */
1173
1174 // VXLAN create
1175 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
Neale Ranns25b04942018-04-04 09:34:50 -07001176 boost::asio::ip::address::from_string("10.10.10.11"),
1177 322);
Neale Ranns812ed392017-10-16 04:20:13 -07001178
1179 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1180
1181 HW::item<handle_t> hw_vxt(3, rc_t::OK);
Neale Rannscf3ecb12018-12-11 08:40:20 -08001182 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1183 handle_t::INVALID));
Neale Ranns812ed392017-10-16 04:20:13 -07001184
1185 TRY_CHECK_RC(OM::write(franz, vxt));
1186
1187 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001188 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1189 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001190 bridge_domain::arp_ufwd_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001191 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001192 bridge_domain::uu_flood_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001193 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001194
1195 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001196 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1197 bridge_domain::learning_mode_t::OFF,
1198 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001199 bridge_domain::arp_ufwd_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001200 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04001201 bridge_domain::uu_flood_mode_t::OFF,
Neale Ranns25b04942018-04-04 09:34:50 -07001202 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001203
1204 TRY_CHECK_RC(OM::write(franz, bd1));
1205
1206 // L2-interface create and bind
1207 // this needs to be delete'd before the flush below, since it too maintains
1208 // references to the BD and Interface
1209 l2_binding *l2itf = new l2_binding(vxt, bd1);
1210 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1211
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001212 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1213 hw_vxt.data(),
1214 hw_bd.data(),
1215 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -07001216 TRY_CHECK_RC(OM::write(franz, *l2itf));
1217
1218 // flush Franz's state
1219 delete l2itf;
1220 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1221 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001222 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1223 hw_vxt.data(),
1224 hw_bd.data(),
1225 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001226 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1227 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001228 TRY_CHECK(OM::remove(franz));
1229}
1230
1231BOOST_AUTO_TEST_CASE(test_vlan) {
1232 VppInit vi;
1233 const std::string noam = "NoamChomsky";
1234 rc_t rc = rc_t::OK;
1235
1236 std::string itf1_name = "host1";
1237 interface itf1(itf1_name,
1238 interface::type_t::AFPACKET,
1239 interface::admin_state_t::UP);
1240
1241 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001242 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001243
1244 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001245 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001246
1247 TRY_CHECK_RC(OM::write(noam, itf1));
1248
1249 sub_interface *vl33 = new sub_interface(itf1,
1250 interface::admin_state_t::UP,
1251 33);
1252
1253 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001254 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1255 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001256
1257 TRY_CHECK_RC(OM::write(noam, *vl33));
1258
1259 delete vl33;
1260 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1261 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001262 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1263 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1264 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1265 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001266
1267 TRY_CHECK(OM::remove(noam));
1268}
1269
1270BOOST_AUTO_TEST_CASE(test_acl) {
1271 VppInit vi;
1272 const std::string fyodor = "FyodorDostoyevsky";
1273 const std::string leo = "LeoTolstoy";
1274 rc_t rc = rc_t::OK;
1275
1276 /*
1277 * Fyodor adds an ACL in the input direction
1278 */
1279 std::string itf1_name = "host1";
1280 interface itf1(itf1_name,
1281 interface::type_t::AFPACKET,
1282 interface::admin_state_t::UP);
1283 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1284 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001285 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1286 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001287 TRY_CHECK_RC(OM::write(fyodor, itf1));
1288
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001289 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1290 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1291 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1292 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1293 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1294 HW::item<bool> ae_binding(true, rc_t::OK);
1295 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1296 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1297
Neale Ranns812ed392017-10-16 04:20:13 -07001298 route::prefix_t src("10.10.10.10", 32);
1299 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1300 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1301
1302 std::string acl_name = "acl1";
1303 ACL::l3_list acl1(acl_name);
1304 acl1.insert(r2);
1305 acl1.insert(r1);
1306 ACL::l3_list::rules_t rules = {r1, r2};
1307
1308 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001309 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001310 TRY_CHECK_RC(OM::write(fyodor, acl1));
1311
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001312 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1313 ACL::l3_list acl2(acl_name);
1314 acl2.insert(r3);
1315 ACL::l3_list::rules_t rules2 = {r3};
1316 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1317 TRY_CHECK_RC(OM::write(fyodor, acl2));
1318
Neale Ranns812ed392017-10-16 04:20:13 -07001319 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1320 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001321 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1322 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001323 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1324
1325 /**
1326 * Leo adds an L2 ACL in the output direction
1327 */
1328 TRY_CHECK_RC(OM::write(leo, itf1));
1329
1330 std::string l2_acl_name = "l2_acl1";
1331 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1332 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1333 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1334 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1335
1336 ACL::l2_list l2_acl(l2_acl_name);
1337 l2_acl.insert(l2_r2);
1338 l2_acl.insert(l2_r1);
1339
1340 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1341
1342 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001343 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001344 TRY_CHECK_RC(OM::write(leo, l2_acl));
1345
1346 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1347 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001348 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001349 hw_ifh.data(), l2_hw_acl.data()));
1350 TRY_CHECK_RC(OM::write(leo, *l2b));
1351
1352 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001353 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1354 hw_ifh.data(), l2_hw_acl.data()));
1355 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001356 TRY_CHECK(OM::remove(leo));
1357
1358 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001359 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001360 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1361 rc_t::OK);
1362 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001363 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001364 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001365 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001366 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001367 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1368 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001369
1370 TRY_CHECK(OM::remove(fyodor));
1371}
1372
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001373BOOST_AUTO_TEST_CASE(test_igmp) {
1374 VppInit vi;
1375 const std::string Isaiah = "IsaiahBerlin";
1376 rc_t rc = rc_t::OK;
1377
Ole Troan003d5da2018-12-18 12:23:13 +01001378 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1379 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1380 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001381
1382 std::string itf3_name = "host3";
1383 interface itf3(itf3_name,
1384 interface::type_t::AFPACKET,
1385 interface::admin_state_t::UP);
1386 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1387 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1388 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1389 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1390 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1391
1392 igmp_binding *ib = new igmp_binding(itf3);
1393 HW::item<bool> hw_binding(true, rc_t::OK);
1394 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1395 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1396
1397 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1398
1399 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1400 HW::item<bool> hw_as_listen(true, rc_t::OK);
1401 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1402 TRY_CHECK_RC(OM::write(Isaiah, *il));
1403
1404 delete il;
1405 delete ib;
1406
1407 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1408 rc_t::OK);
1409 STRICT_ORDER_OFF();
1410 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1411 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1412 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1413 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1414
1415 TRY_CHECK(OM::remove(Isaiah));
1416}
1417
Neale Ranns812ed392017-10-16 04:20:13 -07001418BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1419 VppInit vi;
1420 const std::string kurt = "KurtVonnegut";
1421 rc_t rc = rc_t::OK;
1422
1423 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1424 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1425
1426 arp_proxy_config ap(low, high);
1427 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001428 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001429 TRY_CHECK_RC(OM::write(kurt, ap));
1430
1431 std::string itf3_name = "host3";
1432 interface itf3(itf3_name,
1433 interface::type_t::AFPACKET,
1434 interface::admin_state_t::UP);
1435 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1436 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001437 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1438 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001439 TRY_CHECK_RC(OM::write(kurt, itf3));
1440
Neale Ranns0053de62018-05-22 08:40:52 -07001441 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001442 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001443 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001444 TRY_CHECK_RC(OM::write(kurt, *apb));
1445
1446 delete apb;
1447
1448 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1449 rc_t::OK);
1450 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001451 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1452 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1453 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1454 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001455
1456 TRY_CHECK(OM::remove(kurt));
1457}
1458
Mohsin Kazmie23edac2018-09-25 18:26:52 +02001459BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1460 VppInit vi;
1461 const std::string eliot = "EliotReed";
1462 rc_t rc = rc_t::OK;
1463
1464 /*
1465 * Interface 1 is the tx interface
1466 */
1467 std::string itf1_name = "tx-itf";
1468 interface itf1(itf1_name,
1469 interface::type_t::AFPACKET,
1470 interface::admin_state_t::UP);
1471 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1472 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1473 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1474 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1475 TRY_CHECK_RC(OM::write(eliot, itf1));
1476
1477 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1478
1479 /*
1480 * Interface 2 is the rx interface
1481 */
1482 std::string itf2_name = "rx-itf";
1483 interface itf2(itf2_name,
1484 interface::type_t::AFPACKET,
1485 interface::admin_state_t::UP);
1486
1487 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1488 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1489 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1490 TRY_CHECK_RC(OM::write(eliot, itf2));
1491
1492 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1493 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1494 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1495 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1496 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1497
1498 delete ip_punt;
1499
1500 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1501 STRICT_ORDER_OFF();
1502 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1503 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1504 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1505 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1506 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1507
1508 TRY_CHECK(OM::remove(eliot));
1509}
1510
Neale Ranns812ed392017-10-16 04:20:13 -07001511BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1512 VppInit vi;
1513 const std::string eric = "EricAmbler";
1514 rc_t rc = rc_t::OK;
1515
1516 /*
1517 * Interface 1 has the L3 address
1518 */
1519 std::string itf1_name = "host1";
1520 interface itf1(itf1_name,
1521 interface::type_t::AFPACKET,
1522 interface::admin_state_t::UP);
1523 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1524 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001525 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1526 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001527 TRY_CHECK_RC(OM::write(eric, itf1));
1528
1529 route::prefix_t pfx_10("10.10.10.10", 24);
1530 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1531 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1532 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001533 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001534 TRY_CHECK_RC(OM::write(eric, *l3));
1535
1536 /*
1537 * Interface 2 is unnumbered
1538 */
1539 std::string itf2_name = "host2";
1540 interface itf2(itf2_name,
1541 interface::type_t::AFPACKET,
1542 interface::admin_state_t::UP);
1543
1544 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001545 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1546 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001547 TRY_CHECK_RC(OM::write(eric, itf2));
1548
1549 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1550 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1551 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001552 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001553 TRY_CHECK_RC(OM::write(eric, *ipun));
1554
1555 delete l3;
1556 delete ipun;
1557
1558 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1559 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001560 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1561 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1562 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1563 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1564 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1565 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001566
1567 TRY_CHECK(OM::remove(eric));
1568}
1569
1570BOOST_AUTO_TEST_CASE(test_ip6nd) {
1571 VppInit vi;
1572 const std::string paulo = "PauloCoelho";
1573 rc_t rc = rc_t::OK;
1574
1575 /*
1576 * ra config
1577 */
1578 std::string itf_name = "host_ip6nd";
1579 interface itf(itf_name,
1580 interface::type_t::AFPACKET,
1581 interface::admin_state_t::UP);
1582 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1583 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001584 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1585 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001586 TRY_CHECK_RC(OM::write(paulo, itf));
1587
1588 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1589 l3_binding *l3 = new l3_binding(itf, pfx_10);
1590 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1591 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001592 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001593 TRY_CHECK_RC(OM::write(paulo, *l3));
1594
1595 ra_config ra(0, 1, 0, 4);
1596 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1597 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1598 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1599 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1600 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1601
1602 /*
1603 * ra prefix
1604 */
1605 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1606 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1607 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1608 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1609 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1610 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1611
1612 delete ip6pfx;
1613
1614 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1615
1616 delete ip6ra;
1617 delete l3;
1618
1619 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1620
1621 STRICT_ORDER_OFF();
1622 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001623 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1624 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1625 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001626
1627 TRY_CHECK(OM::remove(paulo));
1628}
1629
1630BOOST_AUTO_TEST_CASE(test_interface_span) {
1631 VppInit vi;
1632 const std::string elif = "ElifShafak";
1633 rc_t rc = rc_t::OK;
1634
1635 /*
1636 * Interface 1 to be mirrored
1637 */
1638 std::string itf1_name = "port-from";
1639 interface itf1(itf1_name,
1640 interface::type_t::AFPACKET,
1641 interface::admin_state_t::UP);
1642 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1643 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001644 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1645 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001646 TRY_CHECK_RC(OM::write(elif, itf1));
1647
1648 /*
1649 * Interface 2 where traffic is mirrored
1650 */
1651 std::string itf2_name = "port-to";
1652 interface itf2(itf2_name,
1653 interface::type_t::AFPACKET,
1654 interface::admin_state_t::UP);
1655
1656 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1657 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1658
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001659 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1660 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001661 TRY_CHECK_RC(OM::write(elif, itf2));
1662
1663 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1664 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1665 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001666 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 -07001667 TRY_CHECK_RC(OM::write(elif, *itf_span));
1668
1669 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1670 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1671
1672 delete itf_span;
1673 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001674 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1675 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1676 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1677 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1678 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001679
1680 TRY_CHECK(OM::remove(elif));
1681}
1682
1683BOOST_AUTO_TEST_CASE(test_routing) {
1684 VppInit vi;
1685 const std::string ian = "IanFleming";
1686 rc_t rc = rc_t::OK;
1687
1688 /*
1689 * non-default route domain
1690 */
1691 route_domain rd4(1);
1692 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1693 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1694 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1695 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1696 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1697 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1698 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1699 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001700 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1701 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001702 TRY_CHECK_RC(OM::write(ian, rd4));
1703
1704 /*
1705 * a couple of interfaces
1706 */
1707 std::string itf1_name = "af1";
1708 interface itf1(itf1_name,
1709 interface::type_t::AFPACKET,
1710 interface::admin_state_t::UP);
1711 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1712 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1713 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001714 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1715 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001716 TRY_CHECK_RC(OM::write(ian, itf1));
1717
1718 std::string itf2_name = "af2";
1719 interface *itf2 = new interface(itf2_name,
1720 interface::type_t::AFPACKET,
1721 interface::admin_state_t::UP,
1722 rd4);
1723
1724 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1725 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1726 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001727 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1728 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1729 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1730 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001731 TRY_CHECK_RC(OM::write(ian, *itf2));
1732
1733 /*
1734 * prefix on each interface
1735 */
1736 route::prefix_t pfx_10("10.10.10.10", 24);
1737 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1738 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1739 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001740 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001741 TRY_CHECK_RC(OM::write(ian, *l3_10));
1742 route::prefix_t pfx_11("11.11.11.11", 24);
1743 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1744 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1745 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001746 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001747 TRY_CHECK_RC(OM::write(ian, *l3_11));
1748
1749 /*
1750 * A route via interface 1 in the default table
1751 */
1752 route::prefix_t pfx_5("5.5.5.5", 32);
Neale Ranns6ad72312019-01-10 08:56:38 -08001753 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1754 route::path *path_9 = new route::path(nh_9, itf1);
Neale Ranns812ed392017-10-16 04:20:13 -07001755 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1756 route::path *path_10 = new route::path(nh_10, itf1);
1757 route::ip_route *route_5 = new route::ip_route(pfx_5);
1758 route_5->add(*path_10);
Neale Ranns6ad72312019-01-10 08:56:38 -08001759 route_5->add(*path_9);
Neale Ranns812ed392017-10-16 04:20:13 -07001760 HW::item<bool> hw_route_5(true, rc_t::OK);
Neale Ranns6ad72312019-01-10 08:56:38 -08001761 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_9));
1762 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001763 TRY_CHECK_RC(OM::write(ian, *route_5));
1764
Neale Ranns6ad72312019-01-10 08:56:38 -08001765 route_5->remove(*path_9);
1766 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_9));
1767 TRY_CHECK_RC(OM::write(ian, *route_5));
1768
1769 delete path_9;
1770
Neale Ranns812ed392017-10-16 04:20:13 -07001771 /*
1772 * A route via interface 2 in the non-default table
1773 */
1774 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1775 route::path *path_11 = new route::path(nh_11, *itf2);
Neale Ranns6ad72312019-01-10 08:56:38 -08001776 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1777 route::path *path_12 = new route::path(nh_12, *itf2);
Neale Ranns812ed392017-10-16 04:20:13 -07001778 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1779 route_5_2->add(*path_11);
1780 HW::item<bool> hw_route_5_2(true, rc_t::OK);
Neale Ranns6ad72312019-01-10 08:56:38 -08001781 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1782 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1783
1784 route_5_2->add(*path_12);
1785 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_12));
Neale Ranns812ed392017-10-16 04:20:13 -07001786 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1787
1788 /*
1789 * An ARP entry for the neighbour on itf1
1790 */
1791 HW::item<bool> hw_neighbour(true, rc_t::OK);
1792 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001793 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns6fef74a2019-02-12 06:18:30 -08001794 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1795 mac_n, nh_10,
1796 neighbour::flags_t::STATIC));
Neale Ranns812ed392017-10-16 04:20:13 -07001797 TRY_CHECK_RC(OM::write(ian, *ne));
1798
1799 /*
1800 * A DVR route
1801 */
1802 route::prefix_t pfx_6("6.6.6.6", 32);
1803 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1804 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1805 route_dvr->add(*path_l2);
1806 HW::item<bool> hw_route_dvr(true, rc_t::OK);
Neale Ranns6ad72312019-01-10 08:56:38 -08001807 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
Neale Ranns812ed392017-10-16 04:20:13 -07001808 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1809
Neale Ranns7c03ed42018-12-27 03:21:28 -08001810 /*
1811 * a multicast route
1812 */
1813 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1814 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1815
1816 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1817 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1818 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1819 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1820 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1821 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1822 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1823 *mp1, route::itf_flags_t::FORWARD));
1824 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1825 *mp2, route::itf_flags_t::FORWARD));
1826 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1827 *mp1, route::itf_flags_t::ACCEPT));
1828 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1829
Neale Ranns812ed392017-10-16 04:20:13 -07001830 STRICT_ORDER_OFF();
1831 // delete the stack objects that hold references to others
1832 // so the OM::remove is the call that removes the last reference
1833 delete l3_11;
1834 delete l3_10;
1835 delete itf2;
1836 delete route_5;
Neale Ranns812ed392017-10-16 04:20:13 -07001837 delete route_5_2;
Neale Ranns812ed392017-10-16 04:20:13 -07001838 delete route_dvr;
Neale Ranns812ed392017-10-16 04:20:13 -07001839 delete ne;
Neale Ranns7c03ed42018-12-27 03:21:28 -08001840 delete mroute_4;
1841
1842 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1843 *mp1, route::itf_flags_t::FORWARD));
1844 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1845 *mp2, route::itf_flags_t::FORWARD));
1846 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1847 *mp1, route::itf_flags_t::ACCEPT));
1848
1849 delete mp1;
1850 delete mp2;
1851
Neale Ranns6fef74a2019-02-12 06:18:30 -08001852 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1853 mac_n, nh_10,
1854 neighbour::flags_t::STATIC));
Neale Ranns6ad72312019-01-10 08:56:38 -08001855 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1856 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1857 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1858 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_10));
1859
1860 delete path_10;
1861 delete path_11;
1862 delete path_12;
1863 delete path_l2;
1864
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001865 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1866 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1867 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1868 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1869 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1870 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1871 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1872 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1873 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1874 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001875
1876 TRY_CHECK(OM::remove(ian));
1877}
1878
1879BOOST_AUTO_TEST_CASE(test_nat) {
1880 VppInit vi;
1881 const std::string gs = "GeorgeSimenon";
1882 rc_t rc = rc_t::OK;
1883
1884 /*
1885 * Inside Interface
1886 */
1887 std::string itf_in_name = "inside";
1888 interface itf_in(itf_in_name,
1889 interface::type_t::AFPACKET,
1890 interface::admin_state_t::UP);
1891 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1892 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1893 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001894 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1895 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001896 TRY_CHECK_RC(OM::write(gs, itf_in));
1897
1898 /*
1899 * outside
1900 */
1901 std::string itf_out_name = "port-to";
1902 interface itf_out(itf_out_name,
1903 interface::type_t::AFPACKET,
1904 interface::admin_state_t::UP);
1905
1906 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1907 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1908 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1909
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001910 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1911 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001912 TRY_CHECK_RC(OM::write(gs, itf_out));
1913
1914 /*
1915 * A NAT static mapping
1916 */
1917 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1918 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1919
1920 nat_static ns(in_addr, out_addr);
1921 HW::item<bool> hw_ns(true, rc_t::OK);
1922
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001923 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001924 TRY_CHECK_RC(OM::write(gs, ns));
1925
1926 /*
1927 * bind nat inside and out
1928 */
1929 nat_binding *nb_in = new nat_binding(itf_in,
1930 direction_t::INPUT,
1931 l3_proto_t::IPV4,
1932 nat_binding::zone_t::INSIDE);
1933 HW::item<bool> hw_nb_in(true, rc_t::OK);
1934
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001935 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1936 hw_ifh.data().value(),
1937 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001938 TRY_CHECK_RC(OM::write(gs, *nb_in));
1939
1940 nat_binding *nb_out = new nat_binding(itf_out,
1941 direction_t::INPUT,
1942 l3_proto_t::IPV4,
1943 nat_binding::zone_t::OUTSIDE);
1944 HW::item<bool> hw_nb_out(true, rc_t::OK);
1945
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001946 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1947 hw_ifh2.data().value(),
1948 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001949 TRY_CHECK_RC(OM::write(gs, *nb_out));
1950
1951
1952 STRICT_ORDER_OFF();
1953 delete nb_in;
1954 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001955 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1956 hw_ifh.data().value(),
1957 nat_binding::zone_t::INSIDE));
1958 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1959 hw_ifh2.data().value(),
1960 nat_binding::zone_t::OUTSIDE));
1961 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1962 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1963 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1964 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1965 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001966
1967 TRY_CHECK(OM::remove(gs));
1968}
1969
1970BOOST_AUTO_TEST_CASE(test_interface_events) {
1971 VppInit vi;
1972 MockListener ml;
1973
1974 HW::item<bool> hw_want(true, rc_t::OK);
1975
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001976 ADD_EXPECT(interface_cmds::events_cmd(ml));
1977 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07001978
1979 HW::enqueue(itf);
1980 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07001981}
1982
Neale Ranns352ea0c2017-11-14 11:04:28 -08001983BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1984 VppInit vi;
1985 const std::string rene = "ReneGoscinny";
1986 rc_t rc = rc_t::OK;
1987
1988 /*
1989 * Create an interface with two IP addresses
1990 */
1991 std::string itf1_name = "host1";
1992 interface itf1(itf1_name,
1993 interface::type_t::AFPACKET,
1994 interface::admin_state_t::UP);
1995 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1996 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1997 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1998 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1999 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
2000 TRY_CHECK_RC(OM::write(rene, itf1));
2001
2002 route::prefix_t pfx_10("10.10.10.10", 24);
2003 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
2004 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
2005 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
2006 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2007 TRY_CHECK_RC(OM::write(rene, *l3_1));
2008
2009 route::prefix_t pfx_11("10.10.11.11", 24);
2010 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
2011 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
2012 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
2013 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2014 TRY_CHECK_RC(OM::write(rene, *l3_2));
2015
2016 route_domain rd(1);
2017 HW::item<bool> hw_rd_create(true, rc_t::OK);
2018 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2019 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2020 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2021 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2022 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2023 TRY_CHECK_RC(OM::write(rene, rd));
2024
2025 /*
2026 * update the interface to change to a new route-domain
2027 * expect that the l3-bindings are removed and readded.
2028 */
2029 interface *itf2 = new interface(itf1_name,
2030 interface::type_t::AFPACKET,
2031 interface::admin_state_t::UP,
2032 rd);
2033 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2034 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2035 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2036 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2037 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2038 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2039 TRY_CHECK_RC(OM::write(rene, *itf2));
2040
2041 /*
2042 * mve the interface back to the default route-domain
2043 */
2044 interface itf3(itf1_name,
2045 interface::type_t::AFPACKET,
2046 interface::admin_state_t::UP);
2047 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2048 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2049 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2050 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2051 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2052 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2053 TRY_CHECK_RC(OM::write(rene, itf3));
2054
2055 delete l3_1;
2056 delete l3_2;
2057 delete itf2;
2058
2059 STRICT_ORDER_OFF();
2060 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2061 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2062 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2063 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2064 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2065 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2066
2067 TRY_CHECK(OM::remove(rene));
2068}
2069
Neale Rannsd3464b52017-12-07 08:48:02 -08002070BOOST_AUTO_TEST_CASE(test_prefixes) {
2071 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2072
2073 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2074
2075 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2076
2077 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2078 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2079
2080 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2081 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2082 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2083
2084 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2085
2086 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2087
2088 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2089
2090 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2091 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2092 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2093
2094 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2095
2096 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2097 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2098 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2099
2100 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2101
2102 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2103 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2104 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2105
2106}
2107
Neale Ranns208c29a2018-04-11 08:08:30 -07002108BOOST_AUTO_TEST_CASE(test_pipes) {
2109 VppInit vi;
2110 const std::string gk = "GKChesterton";
2111
2112 const std::string pipe_name_1 = "pipe1";
2113 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2114 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2115 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2116
2117 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2118 rc_t::OK);
2119 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2120 rc_t::OK);
2121 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2122 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2123 TRY_CHECK_RC(OM::write(gk, pipe1));
2124
2125 pipe1.set_ends(hw_hdl_pair.data());
2126
2127 // put each end of the pipe in a BD
2128 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2129 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002130 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002131 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002132 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002133 bridge_domain::mac_age_mode_t::ON);
2134
2135 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2136 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2137 bridge_domain::learning_mode_t::OFF,
2138 bridge_domain::arp_term_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002139 bridge_domain::arp_ufwd_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002140 bridge_domain::flood_mode_t::OFF,
Neale Rannsb02d2302019-06-07 03:54:21 -04002141 bridge_domain::uu_flood_mode_t::ON,
Neale Ranns208c29a2018-04-11 08:08:30 -07002142 bridge_domain::mac_age_mode_t::ON));
2143
2144 TRY_CHECK_RC(OM::write(gk, bd1));
2145
2146 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2147 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2148
2149 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2150 pipe1.east()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002151 hw_bd.data(),
2152 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002153 TRY_CHECK_RC(OM::write(gk, *l2_1));
2154
2155 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2156 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2157
2158 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2159 pipe1.west()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002160 hw_bd.data(),
2161 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002162 TRY_CHECK_RC(OM::write(gk, *l2_2));
2163
2164 STRICT_ORDER_OFF();
2165
2166 delete l2_1;
2167 delete l2_2;
2168 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2169 pipe1.east()->handle(),
2170 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002171 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002172 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2173 pipe1.west()->handle(),
2174 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002175 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002176 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2177 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2178 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2179 TRY_CHECK(OM::remove(gk));
2180}
2181
Neale Ranns812ed392017-10-16 04:20:13 -07002182BOOST_AUTO_TEST_SUITE_END()