blob: 3374259cd609ff144df232bcee191d4ac2293cc6 [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"
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +020028#include "vom/l2_xconnect.hpp"
29#include "vom/l2_xconnect_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070030#include "vom/l3_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070031#include "vom/l3_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070032#include "vom/bridge_domain.hpp"
33#include "vom/bridge_domain_entry.hpp"
34#include "vom/bridge_domain_arp_entry.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070035#include "vom/bridge_domain_cmds.hpp"
36#include "vom/bridge_domain_entry_cmds.hpp"
37#include "vom/bridge_domain_arp_entry_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070038#include "vom/prefix.hpp"
39#include "vom/route.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070040#include "vom/route_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070041#include "vom/route_domain.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070042#include "vom/route_domain_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070043#include "vom/vxlan_tunnel.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070044#include "vom/vxlan_tunnel_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070045#include "vom/sub_interface.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070046#include "vom/sub_interface_cmds.hpp"
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +010047#include "vom/acl_ethertype.hpp"
48#include "vom/acl_ethertype_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070049#include "vom/acl_list.hpp"
50#include "vom/acl_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070051#include "vom/acl_list_cmds.hpp"
52#include "vom/acl_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070053#include "vom/acl_l3_rule.hpp"
54#include "vom/acl_l2_rule.hpp"
55#include "vom/arp_proxy_config.hpp"
56#include "vom/arp_proxy_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070057#include "vom/arp_proxy_config_cmds.hpp"
58#include "vom/arp_proxy_binding_cmds.hpp"
Mohsin Kazmie23edac2018-09-25 18:26:52 +020059#include "vom/ip_punt_redirect.hpp"
60#include "vom/ip_punt_redirect_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070061#include "vom/ip_unnumbered.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070062#include "vom/ip_unnumbered_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070063#include "vom/interface_ip6_nd.hpp"
64#include "vom/interface_span.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070065#include "vom/interface_span_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070066#include "vom/neighbour.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070067#include "vom/neighbour_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070068#include "vom/nat_static.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070069#include "vom/nat_static_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070070#include "vom/nat_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070071#include "vom/nat_binding_cmds.hpp"
Neale Ranns208c29a2018-04-11 08:08:30 -070072#include "vom/pipe.hpp"
73#include "vom/pipe_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070074
75using namespace boost;
76using namespace VOM;
77
78/**
79 * An expectation exception
80 */
81class ExpException
82{
83public:
84 ExpException(unsigned int number)
85 {
86 // a neat place to add a break point
87 std::cout << " ExpException here: " << number << std::endl;
88 }
89};
90
91class MockListener : public interface::event_listener,
92 public interface::stat_listener
93{
Neale Rannsa2ee0292017-11-28 22:29:13 -080094 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
Neale Ranns812ed392017-10-16 04:20:13 -070095 {
96 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070097 void handle_interface_event(interface_cmds::events_cmd *cmd)
Neale Ranns812ed392017-10-16 04:20:13 -070098 {
99 }
100};
101
102class MockCmdQ : public HW::cmd_q
103{
104public:
105 MockCmdQ():
106 m_strict_order(true)
107 {
108 }
109 virtual ~MockCmdQ()
110 {
111 }
112 void expect(cmd *f)
113 {
114 m_exp_queue.push_back(f);
115 }
116 void enqueue(cmd *f)
117 {
118 m_act_queue.push_back(f);
119 }
120 void enqueue(std::queue<cmd*> &cmds)
121 {
122 while (cmds.size())
123 {
124 m_act_queue.push_back(cmds.front());
125 cmds.pop();
126 }
127 }
128 void enqueue(std::shared_ptr<cmd> f)
129 {
130 m_act_queue.push_back(f.get());
131 }
132
133 void dequeue(cmd *f)
134 {
135 }
136
137 void dequeue(std::shared_ptr<cmd> cmd)
138 {
139 }
140
141 void strict_order(bool on)
142 {
143 m_strict_order = on;
144 }
145
146 bool is_empty()
147 {
148 return ((0 == m_exp_queue.size()) &&
149 (0 == m_act_queue.size()));
150 }
151
152 rc_t write()
153 {
154 cmd *f_exp, *f_act;
155 rc_t rc = rc_t::OK;
156
157 while (m_act_queue.size())
158 {
159 bool matched = false;
160 auto it_exp = m_exp_queue.begin();
161 auto it_act = m_act_queue.begin();
162
163 f_act = *it_act;
164
165 std::cout << " Act: " << f_act->to_string() << std::endl;
166 while (it_exp != m_exp_queue.end())
167 {
168 f_exp = *it_exp;
169 try
170 {
171 std::cout << " Exp: " << f_exp->to_string() << std::endl;
172
173 if (typeid(*f_exp) != typeid(*f_act))
174 {
175 throw ExpException(1);
176 }
177
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700178 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700179 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700180 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700181 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700182 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700183 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700184 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700185 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800186 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
187 {
188 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
189 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100190 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
191 {
192 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
193 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700194 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700195 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700196 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700197 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700198 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700199 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700200 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700201 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800202 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
203 {
204 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
205 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100206 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
207 {
208 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
209 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700210 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700211 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700212 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700213 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700214 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700215 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700216 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700217 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700218 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700219 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700220 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700221 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700222 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
Neale Ranns812ed392017-10-16 04:20:13 -0700223 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700224 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700225 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100226 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
227 {
228 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
229 }
230 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
231 {
232 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
233 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700234 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700235 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700236 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700237 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700238 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700239 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700240 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700241 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700242 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700243 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700244 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700245 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700246 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700247 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700248 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700249 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700250 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700251 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700252 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700253 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700254 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700255 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700256 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700257 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700258 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700259 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700260 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700261 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700262 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700263 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700264 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700265 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700266 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700267 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700268 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700269 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700270 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700271 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700272 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700273 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700274 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700275 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700276 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700277 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700278 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700279 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700280 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700281 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700282 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700283 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700284 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700285 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700286 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700287 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700288 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700289 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700290 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700291 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700292 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700293 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700294 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700295 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700296 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700297 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700298 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700299 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700300 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700301 }
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +0200302 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
303 {
304 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
305 }
306 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
307 {
308 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
309 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700310 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700311 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700312 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700313 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700314 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700315 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700316 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700317 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700318 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700319 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700320 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700321 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700322 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700323 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700324 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700325 }
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +0100326 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
327 {
328 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
329 }
Mohsin Kazmi04def742018-03-07 19:53:51 +0100330 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
331 {
332 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
333 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700334 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700335 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700336 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700337 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700338 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700339 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700340 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700341 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700342 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700343 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700344 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700345 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700346 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700347 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700348 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700349 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700350 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700351 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700352 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700353 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700354 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700355 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700356 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700357 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700358 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700359 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700360 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700361 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700362 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700363 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700364 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700365 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700366 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700367 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700368 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700369 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700370 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700371 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700372 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700373 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700374 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700375 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700376 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700377 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700378 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700379 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700380 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700381 }
Mohsin Kazmie23edac2018-09-25 18:26:52 +0200382 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
383 {
384 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
385 }
386 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
387 {
388 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
389 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700390 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700391 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700392 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700393 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700394 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700395 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700396 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700397 }
398 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
399 {
400 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
401 }
402 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
403 {
404 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
405 }
406 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
407 {
408 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
409 }
410 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
411 {
412 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
413 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700414 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700415 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700416 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700417 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700418 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700419 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700420 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700421 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700422 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700423 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700424 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700425 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700426 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700427 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700428 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700429 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700430 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700431 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700432 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700433 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700434 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700435 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700436 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700437 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700438 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700439 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700440 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700441 }
Neale Ranns208c29a2018-04-11 08:08:30 -0700442 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
443 {
444 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
445 }
446 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
447 {
448 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
449 }
Neale Ranns812ed392017-10-16 04:20:13 -0700450 else
451 {
452 throw ExpException(2);
453 }
454
455 // if we get here then we found the match.
456 m_exp_queue.erase(it_exp);
457 m_act_queue.erase(it_act);
458 delete f_exp;
459 delete f_act;
460
461 // return any injected failures to the agent
462 if (rc_t::OK != rc && rc_t::NOOP != rc)
463 {
464 return (rc);
465 }
466
467 matched = true;
468 break;
469 }
470 catch (ExpException &e)
471 {
472 // The expected and actual do not match
473 if (m_strict_order)
474 {
475 // in strict ordering mode this is fatal, so rethrow
476 throw e;
477 }
478 else
479 {
480 // move the iterator onto the next in the expected list and
481 // check for a match
482 ++it_exp;
483 }
484 }
485 }
486
487 if (!matched)
488 throw ExpException(3);
489 }
490
491 return (rc);
492 }
493private:
494
495 template <typename T>
496 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
497 {
498 const T *i_exp;
499 T *i_act;
500
501 i_exp = dynamic_cast<const T*>(f_exp);
502 i_act = dynamic_cast<T*>(f_act);
503 if (!(*i_exp == *i_act))
504 {
505 throw ExpException(4);
506 }
507 // pass the data and return code to the agent
508 i_act->item() = i_exp->item();
509
510 return (i_act->item().rc());
511 }
512
513 // The Q to push the expectations on
514 std::deque<cmd*> m_exp_queue;
515
516 // the queue to push the actual events on
517 std::deque<cmd*> m_act_queue;
518
519 // control whether the expected queue is strictly ordered.
520 bool m_strict_order;
521};
522
523class VppInit {
524public:
525 std::string name;
526 MockCmdQ *f;
527
528 VppInit()
529 : name("vpp-ut"),
530 f(new MockCmdQ())
531 {
532 HW::init(f);
533 OM::init();
534 logger().set(log_level_t::DEBUG);
535 }
536
537 ~VppInit() {
538 delete f;
539 }
540};
541
Neale Rannsd3464b52017-12-07 08:48:02 -0800542BOOST_AUTO_TEST_SUITE(vom)
Neale Ranns812ed392017-10-16 04:20:13 -0700543
544#define TRY_CHECK_RC(stmt) \
545{ \
546 try { \
547 BOOST_CHECK(rc_t::OK == stmt); \
548 } \
549 catch (ExpException &e) \
550 { \
551 BOOST_CHECK(false); \
552 } \
553 BOOST_CHECK(vi.f->is_empty()); \
554}
555
556#define TRY_CHECK(stmt) \
557{ \
558 try { \
559 stmt; \
560 } \
561 catch (ExpException &e) \
562 { \
563 BOOST_CHECK(false); \
564 } \
565 BOOST_CHECK(vi.f->is_empty()); \
566}
567
568#define ADD_EXPECT(stmt) \
569 vi.f->expect(new stmt)
570
571#define STRICT_ORDER_OFF() \
572 vi.f->strict_order(false)
573
574BOOST_AUTO_TEST_CASE(test_interface) {
575 VppInit vi;
576 const std::string go = "GeorgeOrwell";
577 const std::string js = "JohnSteinbeck";
578 rc_t rc = rc_t::OK;
579
580 /*
581 * George creates and deletes the interface
582 */
583 std::string itf1_name = "afpacket1";
584 interface itf1(itf1_name,
585 interface::type_t::AFPACKET,
586 interface::admin_state_t::UP);
587
588 /*
589 * set the expectation for a afpacket interface create.
590 * 2 is the interface handle VPP [mock] assigns
591 */
592 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700593 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700594
595 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700596 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700597
598 TRY_CHECK_RC(OM::write(go, itf1));
599
600 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700601 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
602 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700603
604 TRY_CHECK(OM::remove(go));
605
606 /*
607 * George creates the interface, then John brings it down.
608 * George's remove is a no-op, sice John also owns the interface
609 */
610 interface itf1b(itf1_name,
611 interface::type_t::AFPACKET,
612 interface::admin_state_t::DOWN);
613
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700614 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
615 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700616 TRY_CHECK_RC(OM::write(go, itf1));
617
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700618 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700619 TRY_CHECK_RC(OM::write(js, itf1b));
620
621 TRY_CHECK(OM::remove(go));
622
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700623 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700624 TRY_CHECK(OM::remove(js));
625
626 /*
627 * George adds an interface, then we flush all of Geroge's state
628 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700629 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
630 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700631 TRY_CHECK_RC(OM::write(go, itf1));
632
633 TRY_CHECK(OM::mark(go));
634
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700635 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
636 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700637 TRY_CHECK(OM::sweep(go));
638
639 /*
640 * George adds an interface. mark stale. update the same interface. sweep
641 * and expect no delete
642 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700643 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
644 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700645 TRY_CHECK_RC(OM::write(go, itf1b));
646
647 TRY_CHECK(OM::mark(go));
648
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700649 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700650 TRY_CHECK_RC(OM::write(go, itf1));
651
652 TRY_CHECK(OM::sweep(go));
653
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700654 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
655 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700656 TRY_CHECK(OM::remove(go));
657
658 /*
659 * George adds an insterface, then we mark that state. Add a second interface
660 * an flush the first that is now stale.
661 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700662 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
663 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700664 TRY_CHECK_RC(OM::write(go, itf1));
665
666 TRY_CHECK(OM::mark(go));
667
668 std::string itf2_name = "afpacket2";
Neale Ranns4ef42262018-02-20 08:10:44 -0800669 std::string itf2_tag = "uuid-of-afpacket2-interface";
Neale Ranns812ed392017-10-16 04:20:13 -0700670 interface itf2(itf2_name,
671 interface::type_t::AFPACKET,
Neale Ranns4ef42262018-02-20 08:10:44 -0800672 interface::admin_state_t::UP,
673 itf2_tag);
Neale Ranns812ed392017-10-16 04:20:13 -0700674 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
675
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700676 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
Neale Ranns4ef42262018-02-20 08:10:44 -0800677 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700678 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700679 TRY_CHECK_RC(OM::write(go, itf2));
680
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700681 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
682 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700683 TRY_CHECK(OM::sweep(go));
684
685 TRY_CHECK(OM::mark(go));
686
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700687 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
688 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700689 TRY_CHECK(OM::sweep(go));
Neale Ranns4ef42262018-02-20 08:10:44 -0800690
691
692 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
693 std::string itf3_tag = "uuid-of-vhost_user1-interface";
694 interface itf3(itf3_name,
695 interface::type_t::VHOST,
696 interface::admin_state_t::UP,
697 itf3_tag);
698 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
699
700 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
701 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
702 TRY_CHECK_RC(OM::write(go, itf3));
703
704 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
705 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
706 TRY_CHECK(OM::remove(go));
Neale Ranns812ed392017-10-16 04:20:13 -0700707}
708
709BOOST_AUTO_TEST_CASE(test_bvi) {
710 VppInit vi;
711 const std::string ernest = "ErnestHemmingway";
712 const std::string graham = "GrahamGreene";
713 rc_t rc = rc_t::OK;
714 l3_binding *l3;
715
716 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
717 rc_t::OK);
718 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
719 rc_t::OK);
720
721 /*
722 * Enrest creates a BVI with address 10.10.10.10/24
723 */
724 route::prefix_t pfx_10("10.10.10.10", 24);
725
726 const std::string bvi_name = "bvi1";
727 interface itf(bvi_name,
728 interface::type_t::BVI,
729 interface::admin_state_t::UP);
730 HW::item<handle_t> hw_ifh(4, rc_t::OK);
731 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
732
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700733 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
734 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
735 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700736 TRY_CHECK_RC(OM::write(ernest, itf));
737
738 l3 = new l3_binding(itf, pfx_10);
739 HW::item<bool> hw_l3_bind(true, rc_t::OK);
740 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700741 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700742 TRY_CHECK_RC(OM::write(ernest, *l3));
743
744 // change the MAC address on the BVI
745 interface itf_new_mac(bvi_name,
746 interface::type_t::BVI,
747 interface::admin_state_t::UP);
748 l2_address_t l2_addr({0,1,2,3,4,5});
749 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
750 itf_new_mac.set(l2_addr);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700751 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700752 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
753
754 // create/write the interface to the OM again but with an unset MAC
755 // this should not generate a MAC address update
756 TRY_CHECK_RC(OM::write(ernest, itf));
757
758 // change the MAC address on the BVI - again
759 interface itf_new_mac2(bvi_name,
760 interface::type_t::BVI,
761 interface::admin_state_t::UP);
762 l2_address_t l2_addr2({0,1,2,3,4,6});
763 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
764 itf_new_mac2.set(l2_addr2);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700765 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700766 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
767
768 delete l3;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700769 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
770 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
771 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700772 TRY_CHECK(OM::remove(ernest));
773
774 /*
775 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
776 */
777 route_domain rd(1);
778 HW::item<bool> hw_rd4_create(true, rc_t::OK);
779 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
780 HW::item<bool> hw_rd6_create(true, rc_t::OK);
781 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
782 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
783 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
784 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
785 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700786 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
787 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700788 TRY_CHECK_RC(OM::write(graham, rd));
789
790 const std::string bvi2_name = "bvi2";
791 interface *itf2 = new interface(bvi2_name,
792 interface::type_t::BVI,
793 interface::admin_state_t::UP,
794 rd);
795 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
796
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700797 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
798 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
799 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
800 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
801 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700802
803 TRY_CHECK_RC(OM::write(graham, *itf2));
804
805 l3 = new l3_binding(*itf2, pfx_10);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700806 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700807 TRY_CHECK_RC(OM::write(graham, *l3));
808
809 delete l3;
810 delete itf2;
811
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700812 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
813 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
814 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
815 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
816 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
817 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
818 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700819 TRY_CHECK(OM::remove(graham));
820}
821
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100822BOOST_AUTO_TEST_CASE(test_bond) {
823 VppInit vi;
824 const std::string cb = "CarolBerg";
825 rc_t rc = rc_t::OK;
826
827 /*
828 * creates the interfaces
829 */
830 std::string itf1_name = "afpacket1";
831 interface itf1(itf1_name,
832 interface::type_t::AFPACKET,
833 interface::admin_state_t::UP);
834
835 HW::item<handle_t> hw_ifh(2, rc_t::OK);
836 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
837
838 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
839 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
840
841 TRY_CHECK_RC(OM::write(cb, itf1));
842
843 std::string itf2_name = "afpacket2";
844 interface itf2(itf2_name,
845 interface::type_t::AFPACKET,
846 interface::admin_state_t::UP);
847
848
849 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
850 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
851 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
852
853 TRY_CHECK_RC(OM::write(cb, itf2));
854
855 std::string bond_name = "bond";
856 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
857 bond_interface::mode_t::LACP);
858
859 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
860 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
861 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
862 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
863
864 TRY_CHECK_RC(OM::write(cb, bond_itf));
865
866 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
867 bond_member::rate_t::SLOW);
868 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
869 bond_member::rate_t::SLOW);
870 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
871
872 HW::item<bool> bond_hw_bind(true, rc_t::OK);
873 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
874 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
875
876 TRY_CHECK_RC(OM::write(cb, *bgb));
877
878 delete bgb;
879 delete bm2;
880 delete bm1;
881
882 STRICT_ORDER_OFF();
883 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
884 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
885 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
886 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
887 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
888 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
889 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
890 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
891 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
892
893 TRY_CHECK(OM::remove(cb));
894}
895
Neale Ranns812ed392017-10-16 04:20:13 -0700896BOOST_AUTO_TEST_CASE(test_bridge) {
897 VppInit vi;
898 const std::string franz = "FranzKafka";
899 const std::string dante = "Dante";
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100900 const std::string jkr = "jkrowling";
Neale Ranns812ed392017-10-16 04:20:13 -0700901 rc_t rc = rc_t::OK;
902
903 /*
904 * Franz creates an interface, Bridge-domain, then binds the two
905 */
906
907 // interface create
908 std::string itf1_name = "afpacket1";
909 interface itf1(itf1_name,
910 interface::type_t::AFPACKET,
911 interface::admin_state_t::UP);
912
913 HW::item<handle_t> hw_ifh(3, rc_t::OK);
914 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
915 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700916 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
917 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700918
919 TRY_CHECK_RC(OM::write(franz, itf1));
920
921 // bridge-domain create
922 bridge_domain bd1(33);
923
924 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -0700925 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
926 bridge_domain::learning_mode_t::ON,
927 bridge_domain::arp_term_mode_t::ON,
928 bridge_domain::flood_mode_t::ON,
929 bridge_domain::mac_age_mode_t::OFF));
Neale Ranns812ed392017-10-16 04:20:13 -0700930
931 TRY_CHECK_RC(OM::write(franz, bd1));
932
933 // L2-interface create and bind
934 // this needs to be delete'd before the flush below, since it too maintains
935 // references to the BD and Interface
936 l2_binding *l2itf = new l2_binding(itf1, bd1);
937 HW::item<bool> hw_l2_bind(true, rc_t::OK);
938
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200939 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
940 hw_ifh.data(),
941 hw_bd.data(),
942 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -0700943 TRY_CHECK_RC(OM::write(franz, *l2itf));
944
945 /*
946 * Dante adds an interface to the same BD
947 */
948 std::string itf2_name = "afpacket2";
949 interface itf2(itf2_name,
950 interface::type_t::AFPACKET,
951 interface::admin_state_t::UP);
952
953 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700954 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
955 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700956 TRY_CHECK_RC(OM::write(dante, itf2));
957
958 // BD add is a no-op since it exists
959 TRY_CHECK_RC(OM::write(dante, bd1));
960
961 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
962 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
963 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
964
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200965 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
966 hw_ifh2.data(),
967 hw_bd.data(),
968 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700969 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
Neale Ranns812ed392017-10-16 04:20:13 -0700970 TRY_CHECK_RC(OM::write(dante, *l2itf2));
971
972 // Add some static entries to the bridge-domain
973 HW::item<bool> hw_be1(true, rc_t::OK);
974 mac_address_t mac1({0,1,2,3,4,5});
975 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100976 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
977 false));
Neale Ranns812ed392017-10-16 04:20:13 -0700978 TRY_CHECK_RC(OM::write(dante, *be1));
979
980 // Add some entries to the bridge-domain ARP termination table
981 HW::item<bool> hw_bea1(true, rc_t::OK);
982 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
983
Neale Rannsfd920602017-11-23 12:15:00 -0800984 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700985 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
Neale Ranns812ed392017-10-16 04:20:13 -0700986 TRY_CHECK_RC(OM::write(dante, *bea1));
987
988 // flush Franz's state
989 delete l2itf;
990 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
991 rc_t::OK);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200992 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
993 hw_ifh.data(),
994 hw_bd.data(),
995 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700996 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
997 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700998 TRY_CHECK(OM::remove(franz));
999
1000 // flush Dante's state - the order the interface and BD are deleted
1001 // is an uncontrollable artifact of the C++ object destruction.
1002 delete l2itf2;
1003 delete be1;
1004 delete bea1;
1005 STRICT_ORDER_OFF();
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001006 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1007 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001008 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1009 hw_ifh2.data(),
1010 hw_bd.data(),
1011 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001012
1013 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001014 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1015 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001016 TRY_CHECK(OM::remove(dante));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001017
1018 // test the BVI entry in l2fib
1019 bridge_domain bd2(99);
1020
1021 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001022 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1023 bridge_domain::learning_mode_t::ON,
1024 bridge_domain::arp_term_mode_t::ON,
1025 bridge_domain::flood_mode_t::ON,
1026 bridge_domain::mac_age_mode_t::OFF));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001027
1028 TRY_CHECK_RC(OM::write(jkr, bd2));
1029
1030 std::string itf3_name = "bvi";
1031 interface itf3(itf3_name,
1032 interface::type_t::BVI,
1033 interface::admin_state_t::UP);
1034
1035 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1036 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1037 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1038 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1039 TRY_CHECK_RC(OM::write(jkr, itf3));
1040
1041 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001042 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1043 hw_ifh3.data(),
1044 hw_bd2.data(),
1045 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001046 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1047
1048 HW::item<bool> hw_be2(true, rc_t::OK);
1049 mac_address_t mac2({0,1,2,3,4,5});
1050 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1051 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1052 TRY_CHECK_RC(OM::write(jkr, *be2));
1053
1054 delete l2itf3;
1055 delete be2;
1056 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001057 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1058 hw_ifh3.data(),
1059 hw_bd2.data(),
1060 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001061 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1062 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1063 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1064 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1065 TRY_CHECK(OM::remove(jkr));
Neale Ranns812ed392017-10-16 04:20:13 -07001066}
1067
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +02001068BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1069 VppInit vi;
1070 const std::string nicholas = "NicholasAbercrombie";
1071 rc_t rc = rc_t::OK;
1072
1073 /*
1074 * Interface 1
1075 */
1076 std::string itf1_name = "host1";
1077 interface itf1(itf1_name,
1078 interface::type_t::AFPACKET,
1079 interface::admin_state_t::UP);
1080 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1081 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1082 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1083 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1084 TRY_CHECK_RC(OM::write(nicholas, itf1));
1085
1086 /*
1087 * Interface 2
1088 */
1089 std::string itf2_name = "host2";
1090 interface itf2(itf2_name,
1091 interface::type_t::AFPACKET,
1092 interface::admin_state_t::UP);
1093
1094 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1095 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1096 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1097 TRY_CHECK_RC(OM::write(nicholas, itf2));
1098
1099 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1100 HW::item<bool> xconnect_east(true, rc_t::OK);
1101 HW::item<bool> xconnect_west(true, rc_t::OK);
1102 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1103 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1104 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1105 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1106 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1107
1108 delete l2_xconn;
1109
1110 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1111 STRICT_ORDER_OFF();
1112 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1113 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1114 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1115 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1116 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1117 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1118
1119 TRY_CHECK(OM::remove(nicholas));
1120}
1121
Neale Ranns812ed392017-10-16 04:20:13 -07001122BOOST_AUTO_TEST_CASE(test_vxlan) {
1123 VppInit vi;
1124 const std::string franz = "FranzKafka";
1125 rc_t rc = rc_t::OK;
1126
1127 /*
1128 * Franz creates an interface, Bridge-domain, then binds the two
1129 */
1130
1131 // VXLAN create
1132 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
Neale Ranns25b04942018-04-04 09:34:50 -07001133 boost::asio::ip::address::from_string("10.10.10.11"),
1134 322);
Neale Ranns812ed392017-10-16 04:20:13 -07001135
1136 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1137
1138 HW::item<handle_t> hw_vxt(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001139 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001140
1141 TRY_CHECK_RC(OM::write(franz, vxt));
1142
1143 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001144 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1145 bridge_domain::arp_term_mode_t::OFF,
1146 bridge_domain::flood_mode_t::OFF,
1147 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001148
1149 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001150 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1151 bridge_domain::learning_mode_t::OFF,
1152 bridge_domain::arp_term_mode_t::OFF,
1153 bridge_domain::flood_mode_t::OFF,
1154 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001155
1156 TRY_CHECK_RC(OM::write(franz, bd1));
1157
1158 // L2-interface create and bind
1159 // this needs to be delete'd before the flush below, since it too maintains
1160 // references to the BD and Interface
1161 l2_binding *l2itf = new l2_binding(vxt, bd1);
1162 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1163
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001164 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1165 hw_vxt.data(),
1166 hw_bd.data(),
1167 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -07001168 TRY_CHECK_RC(OM::write(franz, *l2itf));
1169
1170 // flush Franz's state
1171 delete l2itf;
1172 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1173 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001174 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1175 hw_vxt.data(),
1176 hw_bd.data(),
1177 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001178 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1179 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001180 TRY_CHECK(OM::remove(franz));
1181}
1182
1183BOOST_AUTO_TEST_CASE(test_vlan) {
1184 VppInit vi;
1185 const std::string noam = "NoamChomsky";
1186 rc_t rc = rc_t::OK;
1187
1188 std::string itf1_name = "host1";
1189 interface itf1(itf1_name,
1190 interface::type_t::AFPACKET,
1191 interface::admin_state_t::UP);
1192
1193 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001194 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001195
1196 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001197 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001198
1199 TRY_CHECK_RC(OM::write(noam, itf1));
1200
1201 sub_interface *vl33 = new sub_interface(itf1,
1202 interface::admin_state_t::UP,
1203 33);
1204
1205 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001206 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1207 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001208
1209 TRY_CHECK_RC(OM::write(noam, *vl33));
1210
1211 delete vl33;
1212 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1213 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001214 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1215 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1216 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1217 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001218
1219 TRY_CHECK(OM::remove(noam));
1220}
1221
1222BOOST_AUTO_TEST_CASE(test_acl) {
1223 VppInit vi;
1224 const std::string fyodor = "FyodorDostoyevsky";
1225 const std::string leo = "LeoTolstoy";
1226 rc_t rc = rc_t::OK;
1227
1228 /*
1229 * Fyodor adds an ACL in the input direction
1230 */
1231 std::string itf1_name = "host1";
1232 interface itf1(itf1_name,
1233 interface::type_t::AFPACKET,
1234 interface::admin_state_t::UP);
1235 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1236 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001237 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1238 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001239 TRY_CHECK_RC(OM::write(fyodor, itf1));
1240
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001241 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1242 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1243 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1244 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1245 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1246 HW::item<bool> ae_binding(true, rc_t::OK);
1247 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1248 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1249
Neale Ranns812ed392017-10-16 04:20:13 -07001250 route::prefix_t src("10.10.10.10", 32);
1251 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1252 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1253
1254 std::string acl_name = "acl1";
1255 ACL::l3_list acl1(acl_name);
1256 acl1.insert(r2);
1257 acl1.insert(r1);
1258 ACL::l3_list::rules_t rules = {r1, r2};
1259
1260 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001261 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001262 TRY_CHECK_RC(OM::write(fyodor, acl1));
1263
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001264 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1265 ACL::l3_list acl2(acl_name);
1266 acl2.insert(r3);
1267 ACL::l3_list::rules_t rules2 = {r3};
1268 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1269 TRY_CHECK_RC(OM::write(fyodor, acl2));
1270
Neale Ranns812ed392017-10-16 04:20:13 -07001271 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1272 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001273 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1274 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001275 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1276
1277 /**
1278 * Leo adds an L2 ACL in the output direction
1279 */
1280 TRY_CHECK_RC(OM::write(leo, itf1));
1281
1282 std::string l2_acl_name = "l2_acl1";
1283 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1284 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1285 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1286 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1287
1288 ACL::l2_list l2_acl(l2_acl_name);
1289 l2_acl.insert(l2_r2);
1290 l2_acl.insert(l2_r1);
1291
1292 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1293
1294 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001295 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001296 TRY_CHECK_RC(OM::write(leo, l2_acl));
1297
1298 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1299 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001300 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001301 hw_ifh.data(), l2_hw_acl.data()));
1302 TRY_CHECK_RC(OM::write(leo, *l2b));
1303
1304 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001305 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1306 hw_ifh.data(), l2_hw_acl.data()));
1307 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001308 TRY_CHECK(OM::remove(leo));
1309
1310 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001311 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001312 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1313 rc_t::OK);
1314 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001315 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001316 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001317 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001318 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001319 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1320 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001321
1322 TRY_CHECK(OM::remove(fyodor));
1323}
1324
1325BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1326 VppInit vi;
1327 const std::string kurt = "KurtVonnegut";
1328 rc_t rc = rc_t::OK;
1329
1330 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1331 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1332
1333 arp_proxy_config ap(low, high);
1334 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001335 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001336 TRY_CHECK_RC(OM::write(kurt, ap));
1337
1338 std::string itf3_name = "host3";
1339 interface itf3(itf3_name,
1340 interface::type_t::AFPACKET,
1341 interface::admin_state_t::UP);
1342 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1343 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001344 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1345 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001346 TRY_CHECK_RC(OM::write(kurt, itf3));
1347
Neale Ranns0053de62018-05-22 08:40:52 -07001348 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001349 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001350 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001351 TRY_CHECK_RC(OM::write(kurt, *apb));
1352
1353 delete apb;
1354
1355 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1356 rc_t::OK);
1357 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001358 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1359 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1360 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1361 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001362
1363 TRY_CHECK(OM::remove(kurt));
1364}
1365
Mohsin Kazmie23edac2018-09-25 18:26:52 +02001366BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1367 VppInit vi;
1368 const std::string eliot = "EliotReed";
1369 rc_t rc = rc_t::OK;
1370
1371 /*
1372 * Interface 1 is the tx interface
1373 */
1374 std::string itf1_name = "tx-itf";
1375 interface itf1(itf1_name,
1376 interface::type_t::AFPACKET,
1377 interface::admin_state_t::UP);
1378 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1379 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1380 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1381 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1382 TRY_CHECK_RC(OM::write(eliot, itf1));
1383
1384 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1385
1386 /*
1387 * Interface 2 is the rx interface
1388 */
1389 std::string itf2_name = "rx-itf";
1390 interface itf2(itf2_name,
1391 interface::type_t::AFPACKET,
1392 interface::admin_state_t::UP);
1393
1394 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1395 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1396 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1397 TRY_CHECK_RC(OM::write(eliot, itf2));
1398
1399 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1400 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1401 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1402 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1403 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1404
1405 delete ip_punt;
1406
1407 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1408 STRICT_ORDER_OFF();
1409 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1410 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1411 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1412 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1413 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1414
1415 TRY_CHECK(OM::remove(eliot));
1416}
1417
Neale Ranns812ed392017-10-16 04:20:13 -07001418BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1419 VppInit vi;
1420 const std::string eric = "EricAmbler";
1421 rc_t rc = rc_t::OK;
1422
1423 /*
1424 * Interface 1 has the L3 address
1425 */
1426 std::string itf1_name = "host1";
1427 interface itf1(itf1_name,
1428 interface::type_t::AFPACKET,
1429 interface::admin_state_t::UP);
1430 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1431 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001432 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1433 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001434 TRY_CHECK_RC(OM::write(eric, itf1));
1435
1436 route::prefix_t pfx_10("10.10.10.10", 24);
1437 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1438 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1439 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001440 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001441 TRY_CHECK_RC(OM::write(eric, *l3));
1442
1443 /*
1444 * Interface 2 is unnumbered
1445 */
1446 std::string itf2_name = "host2";
1447 interface itf2(itf2_name,
1448 interface::type_t::AFPACKET,
1449 interface::admin_state_t::UP);
1450
1451 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001452 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1453 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001454 TRY_CHECK_RC(OM::write(eric, itf2));
1455
1456 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1457 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1458 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001459 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001460 TRY_CHECK_RC(OM::write(eric, *ipun));
1461
1462 delete l3;
1463 delete ipun;
1464
1465 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1466 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001467 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1468 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1469 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1470 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1471 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1472 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001473
1474 TRY_CHECK(OM::remove(eric));
1475}
1476
1477BOOST_AUTO_TEST_CASE(test_ip6nd) {
1478 VppInit vi;
1479 const std::string paulo = "PauloCoelho";
1480 rc_t rc = rc_t::OK;
1481
1482 /*
1483 * ra config
1484 */
1485 std::string itf_name = "host_ip6nd";
1486 interface itf(itf_name,
1487 interface::type_t::AFPACKET,
1488 interface::admin_state_t::UP);
1489 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1490 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001491 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1492 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001493 TRY_CHECK_RC(OM::write(paulo, itf));
1494
1495 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1496 l3_binding *l3 = new l3_binding(itf, pfx_10);
1497 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1498 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001499 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001500 TRY_CHECK_RC(OM::write(paulo, *l3));
1501
1502 ra_config ra(0, 1, 0, 4);
1503 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1504 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1505 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1506 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1507 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1508
1509 /*
1510 * ra prefix
1511 */
1512 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1513 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1514 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1515 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1516 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1517 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1518
1519 delete ip6pfx;
1520
1521 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1522
1523 delete ip6ra;
1524 delete l3;
1525
1526 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1527
1528 STRICT_ORDER_OFF();
1529 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001530 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1531 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1532 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001533
1534 TRY_CHECK(OM::remove(paulo));
1535}
1536
1537BOOST_AUTO_TEST_CASE(test_interface_span) {
1538 VppInit vi;
1539 const std::string elif = "ElifShafak";
1540 rc_t rc = rc_t::OK;
1541
1542 /*
1543 * Interface 1 to be mirrored
1544 */
1545 std::string itf1_name = "port-from";
1546 interface itf1(itf1_name,
1547 interface::type_t::AFPACKET,
1548 interface::admin_state_t::UP);
1549 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1550 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001551 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1552 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001553 TRY_CHECK_RC(OM::write(elif, itf1));
1554
1555 /*
1556 * Interface 2 where traffic is mirrored
1557 */
1558 std::string itf2_name = "port-to";
1559 interface itf2(itf2_name,
1560 interface::type_t::AFPACKET,
1561 interface::admin_state_t::UP);
1562
1563 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1564 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1565
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001566 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1567 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001568 TRY_CHECK_RC(OM::write(elif, itf2));
1569
1570 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1571 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1572 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001573 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 -07001574 TRY_CHECK_RC(OM::write(elif, *itf_span));
1575
1576 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1577 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1578
1579 delete itf_span;
1580 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001581 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1582 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1583 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1584 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1585 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001586
1587 TRY_CHECK(OM::remove(elif));
1588}
1589
1590BOOST_AUTO_TEST_CASE(test_routing) {
1591 VppInit vi;
1592 const std::string ian = "IanFleming";
1593 rc_t rc = rc_t::OK;
1594
1595 /*
1596 * non-default route domain
1597 */
1598 route_domain rd4(1);
1599 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1600 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1601 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1602 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1603 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1604 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1605 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1606 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001607 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1608 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001609 TRY_CHECK_RC(OM::write(ian, rd4));
1610
1611 /*
1612 * a couple of interfaces
1613 */
1614 std::string itf1_name = "af1";
1615 interface itf1(itf1_name,
1616 interface::type_t::AFPACKET,
1617 interface::admin_state_t::UP);
1618 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1619 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1620 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001621 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1622 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001623 TRY_CHECK_RC(OM::write(ian, itf1));
1624
1625 std::string itf2_name = "af2";
1626 interface *itf2 = new interface(itf2_name,
1627 interface::type_t::AFPACKET,
1628 interface::admin_state_t::UP,
1629 rd4);
1630
1631 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1632 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1633 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001634 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1635 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1636 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1637 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001638 TRY_CHECK_RC(OM::write(ian, *itf2));
1639
1640 /*
1641 * prefix on each interface
1642 */
1643 route::prefix_t pfx_10("10.10.10.10", 24);
1644 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1645 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1646 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001647 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001648 TRY_CHECK_RC(OM::write(ian, *l3_10));
1649 route::prefix_t pfx_11("11.11.11.11", 24);
1650 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1651 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1652 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001653 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001654 TRY_CHECK_RC(OM::write(ian, *l3_11));
1655
1656 /*
1657 * A route via interface 1 in the default table
1658 */
1659 route::prefix_t pfx_5("5.5.5.5", 32);
1660 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1661 route::path *path_10 = new route::path(nh_10, itf1);
1662 route::ip_route *route_5 = new route::ip_route(pfx_5);
1663 route_5->add(*path_10);
1664 HW::item<bool> hw_route_5(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001665 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
Neale Ranns812ed392017-10-16 04:20:13 -07001666 TRY_CHECK_RC(OM::write(ian, *route_5));
1667
1668 /*
1669 * A route via interface 2 in the non-default table
1670 */
1671 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1672 route::path *path_11 = new route::path(nh_11, *itf2);
1673 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1674 route_5_2->add(*path_11);
1675 HW::item<bool> hw_route_5_2(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001676 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
Neale Ranns812ed392017-10-16 04:20:13 -07001677 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1678
1679 /*
1680 * An ARP entry for the neighbour on itf1
1681 */
1682 HW::item<bool> hw_neighbour(true, rc_t::OK);
1683 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001684 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001685 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001686 TRY_CHECK_RC(OM::write(ian, *ne));
1687
1688 /*
1689 * A DVR route
1690 */
1691 route::prefix_t pfx_6("6.6.6.6", 32);
1692 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1693 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1694 route_dvr->add(*path_l2);
1695 HW::item<bool> hw_route_dvr(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001696 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
Neale Ranns812ed392017-10-16 04:20:13 -07001697 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1698
1699 STRICT_ORDER_OFF();
1700 // delete the stack objects that hold references to others
1701 // so the OM::remove is the call that removes the last reference
1702 delete l3_11;
1703 delete l3_10;
1704 delete itf2;
1705 delete route_5;
1706 delete path_10;
1707 delete route_5_2;
1708 delete path_11;
1709 delete route_dvr;
1710 delete path_l2;
1711 delete ne;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001712 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1713 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1714 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1715 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1716 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1717 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1718 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1719 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1720 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1721 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1722 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1723 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1724 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1725 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001726
1727 TRY_CHECK(OM::remove(ian));
1728}
1729
1730BOOST_AUTO_TEST_CASE(test_nat) {
1731 VppInit vi;
1732 const std::string gs = "GeorgeSimenon";
1733 rc_t rc = rc_t::OK;
1734
1735 /*
1736 * Inside Interface
1737 */
1738 std::string itf_in_name = "inside";
1739 interface itf_in(itf_in_name,
1740 interface::type_t::AFPACKET,
1741 interface::admin_state_t::UP);
1742 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1743 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1744 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001745 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1746 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001747 TRY_CHECK_RC(OM::write(gs, itf_in));
1748
1749 /*
1750 * outside
1751 */
1752 std::string itf_out_name = "port-to";
1753 interface itf_out(itf_out_name,
1754 interface::type_t::AFPACKET,
1755 interface::admin_state_t::UP);
1756
1757 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1758 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1759 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1760
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001761 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1762 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001763 TRY_CHECK_RC(OM::write(gs, itf_out));
1764
1765 /*
1766 * A NAT static mapping
1767 */
1768 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1769 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1770
1771 nat_static ns(in_addr, out_addr);
1772 HW::item<bool> hw_ns(true, rc_t::OK);
1773
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001774 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001775 TRY_CHECK_RC(OM::write(gs, ns));
1776
1777 /*
1778 * bind nat inside and out
1779 */
1780 nat_binding *nb_in = new nat_binding(itf_in,
1781 direction_t::INPUT,
1782 l3_proto_t::IPV4,
1783 nat_binding::zone_t::INSIDE);
1784 HW::item<bool> hw_nb_in(true, rc_t::OK);
1785
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001786 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1787 hw_ifh.data().value(),
1788 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001789 TRY_CHECK_RC(OM::write(gs, *nb_in));
1790
1791 nat_binding *nb_out = new nat_binding(itf_out,
1792 direction_t::INPUT,
1793 l3_proto_t::IPV4,
1794 nat_binding::zone_t::OUTSIDE);
1795 HW::item<bool> hw_nb_out(true, rc_t::OK);
1796
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001797 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1798 hw_ifh2.data().value(),
1799 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001800 TRY_CHECK_RC(OM::write(gs, *nb_out));
1801
1802
1803 STRICT_ORDER_OFF();
1804 delete nb_in;
1805 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001806 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1807 hw_ifh.data().value(),
1808 nat_binding::zone_t::INSIDE));
1809 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1810 hw_ifh2.data().value(),
1811 nat_binding::zone_t::OUTSIDE));
1812 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1813 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1814 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1815 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1816 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001817
1818 TRY_CHECK(OM::remove(gs));
1819}
1820
1821BOOST_AUTO_TEST_CASE(test_interface_events) {
1822 VppInit vi;
1823 MockListener ml;
1824
1825 HW::item<bool> hw_want(true, rc_t::OK);
1826
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001827 ADD_EXPECT(interface_cmds::events_cmd(ml));
1828 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07001829
1830 HW::enqueue(itf);
1831 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07001832}
1833
Neale Ranns352ea0c2017-11-14 11:04:28 -08001834BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1835 VppInit vi;
1836 const std::string rene = "ReneGoscinny";
1837 rc_t rc = rc_t::OK;
1838
1839 /*
1840 * Create an interface with two IP addresses
1841 */
1842 std::string itf1_name = "host1";
1843 interface itf1(itf1_name,
1844 interface::type_t::AFPACKET,
1845 interface::admin_state_t::UP);
1846 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1847 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1848 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1849 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1850 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1851 TRY_CHECK_RC(OM::write(rene, itf1));
1852
1853 route::prefix_t pfx_10("10.10.10.10", 24);
1854 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1855 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1856 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1857 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1858 TRY_CHECK_RC(OM::write(rene, *l3_1));
1859
1860 route::prefix_t pfx_11("10.10.11.11", 24);
1861 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1862 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1863 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1864 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1865 TRY_CHECK_RC(OM::write(rene, *l3_2));
1866
1867 route_domain rd(1);
1868 HW::item<bool> hw_rd_create(true, rc_t::OK);
1869 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1870 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1871 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1872 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1873 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1874 TRY_CHECK_RC(OM::write(rene, rd));
1875
1876 /*
1877 * update the interface to change to a new route-domain
1878 * expect that the l3-bindings are removed and readded.
1879 */
1880 interface *itf2 = new interface(itf1_name,
1881 interface::type_t::AFPACKET,
1882 interface::admin_state_t::UP,
1883 rd);
1884 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1885 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1886 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1887 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1888 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1889 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1890 TRY_CHECK_RC(OM::write(rene, *itf2));
1891
1892 /*
1893 * mve the interface back to the default route-domain
1894 */
1895 interface itf3(itf1_name,
1896 interface::type_t::AFPACKET,
1897 interface::admin_state_t::UP);
1898 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1899 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1900 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1901 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1902 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1903 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1904 TRY_CHECK_RC(OM::write(rene, itf3));
1905
1906 delete l3_1;
1907 delete l3_2;
1908 delete itf2;
1909
1910 STRICT_ORDER_OFF();
1911 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1912 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1913 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1914 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1915 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1916 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1917
1918 TRY_CHECK(OM::remove(rene));
1919}
1920
Neale Rannsd3464b52017-12-07 08:48:02 -08001921BOOST_AUTO_TEST_CASE(test_prefixes) {
1922 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1923
1924 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1925
1926 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1927
1928 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1929 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1930
1931 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1932 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1933 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1934
1935 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1936
1937 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1938
1939 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1940
1941 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1942 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1943 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1944
1945 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1946
1947 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1948 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1949 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1950
1951 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1952
1953 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1954 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1955 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1956
1957}
1958
Neale Ranns208c29a2018-04-11 08:08:30 -07001959BOOST_AUTO_TEST_CASE(test_pipes) {
1960 VppInit vi;
1961 const std::string gk = "GKChesterton";
1962
1963 const std::string pipe_name_1 = "pipe1";
1964 VOM::pipe pipe1(1, interface::admin_state_t::UP);
1965 HW::item<handle_t> hw_hdl(4, rc_t::OK);
1966 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
1967
1968 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
1969 rc_t::OK);
1970 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1971 rc_t::OK);
1972 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
1973 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
1974 TRY_CHECK_RC(OM::write(gk, pipe1));
1975
1976 pipe1.set_ends(hw_hdl_pair.data());
1977
1978 // put each end of the pipe in a BD
1979 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1980 bridge_domain::arp_term_mode_t::OFF,
1981 bridge_domain::flood_mode_t::OFF,
1982 bridge_domain::mac_age_mode_t::ON);
1983
1984 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1985 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1986 bridge_domain::learning_mode_t::OFF,
1987 bridge_domain::arp_term_mode_t::OFF,
1988 bridge_domain::flood_mode_t::OFF,
1989 bridge_domain::mac_age_mode_t::ON));
1990
1991 TRY_CHECK_RC(OM::write(gk, bd1));
1992
1993 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
1994 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
1995
1996 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
1997 pipe1.east()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001998 hw_bd.data(),
1999 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002000 TRY_CHECK_RC(OM::write(gk, *l2_1));
2001
2002 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2003 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2004
2005 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2006 pipe1.west()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002007 hw_bd.data(),
2008 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002009 TRY_CHECK_RC(OM::write(gk, *l2_2));
2010
2011 STRICT_ORDER_OFF();
2012
2013 delete l2_1;
2014 delete l2_2;
2015 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2016 pipe1.east()->handle(),
2017 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002018 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002019 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2020 pipe1.west()->handle(),
2021 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002022 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002023 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2024 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2025 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2026 TRY_CHECK(OM::remove(gk));
2027}
2028
Neale Ranns812ed392017-10-16 04:20:13 -07002029BOOST_AUTO_TEST_SUITE_END()