blob: 5ccdf55f5da6fd394340b9b8bc7280e8ed7f731e [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"
Neale Ranns812ed392017-10-16 04:20:13 -070059#include "vom/ip_unnumbered.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070060#include "vom/ip_unnumbered_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070061#include "vom/interface_ip6_nd.hpp"
62#include "vom/interface_span.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070063#include "vom/interface_span_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070064#include "vom/neighbour.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070065#include "vom/neighbour_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070066#include "vom/nat_static.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070067#include "vom/nat_static_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070068#include "vom/nat_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070069#include "vom/nat_binding_cmds.hpp"
Neale Ranns208c29a2018-04-11 08:08:30 -070070#include "vom/pipe.hpp"
71#include "vom/pipe_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070072
73using namespace boost;
74using namespace VOM;
75
76/**
77 * An expectation exception
78 */
79class ExpException
80{
81public:
82 ExpException(unsigned int number)
83 {
84 // a neat place to add a break point
85 std::cout << " ExpException here: " << number << std::endl;
86 }
87};
88
89class MockListener : public interface::event_listener,
90 public interface::stat_listener
91{
Neale Rannsa2ee0292017-11-28 22:29:13 -080092 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
Neale Ranns812ed392017-10-16 04:20:13 -070093 {
94 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070095 void handle_interface_event(interface_cmds::events_cmd *cmd)
Neale Ranns812ed392017-10-16 04:20:13 -070096 {
97 }
98};
99
100class MockCmdQ : public HW::cmd_q
101{
102public:
103 MockCmdQ():
104 m_strict_order(true)
105 {
106 }
107 virtual ~MockCmdQ()
108 {
109 }
110 void expect(cmd *f)
111 {
112 m_exp_queue.push_back(f);
113 }
114 void enqueue(cmd *f)
115 {
116 m_act_queue.push_back(f);
117 }
118 void enqueue(std::queue<cmd*> &cmds)
119 {
120 while (cmds.size())
121 {
122 m_act_queue.push_back(cmds.front());
123 cmds.pop();
124 }
125 }
126 void enqueue(std::shared_ptr<cmd> f)
127 {
128 m_act_queue.push_back(f.get());
129 }
130
131 void dequeue(cmd *f)
132 {
133 }
134
135 void dequeue(std::shared_ptr<cmd> cmd)
136 {
137 }
138
139 void strict_order(bool on)
140 {
141 m_strict_order = on;
142 }
143
144 bool is_empty()
145 {
146 return ((0 == m_exp_queue.size()) &&
147 (0 == m_act_queue.size()));
148 }
149
150 rc_t write()
151 {
152 cmd *f_exp, *f_act;
153 rc_t rc = rc_t::OK;
154
155 while (m_act_queue.size())
156 {
157 bool matched = false;
158 auto it_exp = m_exp_queue.begin();
159 auto it_act = m_act_queue.begin();
160
161 f_act = *it_act;
162
163 std::cout << " Act: " << f_act->to_string() << std::endl;
164 while (it_exp != m_exp_queue.end())
165 {
166 f_exp = *it_exp;
167 try
168 {
169 std::cout << " Exp: " << f_exp->to_string() << std::endl;
170
171 if (typeid(*f_exp) != typeid(*f_act))
172 {
173 throw ExpException(1);
174 }
175
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700176 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700177 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700178 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700179 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700180 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700181 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700182 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700183 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800184 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
185 {
186 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
187 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100188 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
189 {
190 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
191 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700192 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700193 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700194 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700195 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700196 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700197 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700198 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700199 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800200 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
201 {
202 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
203 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100204 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
205 {
206 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
207 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700208 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700209 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700210 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700211 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700212 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700213 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700214 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700215 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700216 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700217 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700218 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700219 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700220 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
Neale Ranns812ed392017-10-16 04:20:13 -0700221 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700222 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700223 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100224 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
225 {
226 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
227 }
228 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
229 {
230 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
231 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700232 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700233 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700234 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700235 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700236 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700237 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700238 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700239 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700240 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700241 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700242 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700243 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700244 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700245 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700246 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700247 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700248 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700249 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700250 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700251 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700252 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700253 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700254 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700255 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700256 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700257 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700258 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700259 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700260 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700261 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700262 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700263 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700264 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700265 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700266 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700267 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700268 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700269 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700270 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700271 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700272 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700273 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700274 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700275 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700276 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700277 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700278 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700279 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700280 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700281 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700282 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700283 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700284 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700285 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700286 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700287 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700288 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700289 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700290 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700291 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700292 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700293 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700294 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700295 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700296 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700297 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700298 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700299 }
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +0200300 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
301 {
302 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
303 }
304 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
305 {
306 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
307 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700308 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700309 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700310 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700311 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700312 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700313 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700314 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700315 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700316 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700317 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700318 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700319 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700320 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700321 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700322 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700323 }
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +0100324 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
325 {
326 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
327 }
Mohsin Kazmi04def742018-03-07 19:53:51 +0100328 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
329 {
330 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
331 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700332 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700333 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700334 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700335 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700336 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700337 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700338 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700339 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700340 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700341 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700342 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700343 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700344 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700345 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700346 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700347 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700348 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700349 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700350 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700351 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700352 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700353 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700354 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700355 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700356 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700357 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700358 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700359 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700360 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700361 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700362 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700363 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700364 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700365 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700366 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700367 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700368 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700369 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700370 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700371 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700372 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700373 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700374 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700375 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700376 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700377 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700378 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700379 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700380 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700381 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700382 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700383 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700384 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700385 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700386 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700387 }
388 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
389 {
390 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
391 }
392 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
393 {
394 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
395 }
396 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
397 {
398 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
399 }
400 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
401 {
402 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
403 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700404 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700405 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700406 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700407 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700408 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700409 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700410 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700411 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700412 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700413 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700414 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700415 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700416 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700417 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700418 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700419 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700420 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700421 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700422 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700423 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700424 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700425 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700426 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700427 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700428 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700429 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700430 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700431 }
Neale Ranns208c29a2018-04-11 08:08:30 -0700432 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
433 {
434 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
435 }
436 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
437 {
438 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
439 }
Neale Ranns812ed392017-10-16 04:20:13 -0700440 else
441 {
442 throw ExpException(2);
443 }
444
445 // if we get here then we found the match.
446 m_exp_queue.erase(it_exp);
447 m_act_queue.erase(it_act);
448 delete f_exp;
449 delete f_act;
450
451 // return any injected failures to the agent
452 if (rc_t::OK != rc && rc_t::NOOP != rc)
453 {
454 return (rc);
455 }
456
457 matched = true;
458 break;
459 }
460 catch (ExpException &e)
461 {
462 // The expected and actual do not match
463 if (m_strict_order)
464 {
465 // in strict ordering mode this is fatal, so rethrow
466 throw e;
467 }
468 else
469 {
470 // move the iterator onto the next in the expected list and
471 // check for a match
472 ++it_exp;
473 }
474 }
475 }
476
477 if (!matched)
478 throw ExpException(3);
479 }
480
481 return (rc);
482 }
483private:
484
485 template <typename T>
486 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
487 {
488 const T *i_exp;
489 T *i_act;
490
491 i_exp = dynamic_cast<const T*>(f_exp);
492 i_act = dynamic_cast<T*>(f_act);
493 if (!(*i_exp == *i_act))
494 {
495 throw ExpException(4);
496 }
497 // pass the data and return code to the agent
498 i_act->item() = i_exp->item();
499
500 return (i_act->item().rc());
501 }
502
503 // The Q to push the expectations on
504 std::deque<cmd*> m_exp_queue;
505
506 // the queue to push the actual events on
507 std::deque<cmd*> m_act_queue;
508
509 // control whether the expected queue is strictly ordered.
510 bool m_strict_order;
511};
512
513class VppInit {
514public:
515 std::string name;
516 MockCmdQ *f;
517
518 VppInit()
519 : name("vpp-ut"),
520 f(new MockCmdQ())
521 {
522 HW::init(f);
523 OM::init();
524 logger().set(log_level_t::DEBUG);
525 }
526
527 ~VppInit() {
528 delete f;
529 }
530};
531
Neale Rannsd3464b52017-12-07 08:48:02 -0800532BOOST_AUTO_TEST_SUITE(vom)
Neale Ranns812ed392017-10-16 04:20:13 -0700533
534#define TRY_CHECK_RC(stmt) \
535{ \
536 try { \
537 BOOST_CHECK(rc_t::OK == stmt); \
538 } \
539 catch (ExpException &e) \
540 { \
541 BOOST_CHECK(false); \
542 } \
543 BOOST_CHECK(vi.f->is_empty()); \
544}
545
546#define TRY_CHECK(stmt) \
547{ \
548 try { \
549 stmt; \
550 } \
551 catch (ExpException &e) \
552 { \
553 BOOST_CHECK(false); \
554 } \
555 BOOST_CHECK(vi.f->is_empty()); \
556}
557
558#define ADD_EXPECT(stmt) \
559 vi.f->expect(new stmt)
560
561#define STRICT_ORDER_OFF() \
562 vi.f->strict_order(false)
563
564BOOST_AUTO_TEST_CASE(test_interface) {
565 VppInit vi;
566 const std::string go = "GeorgeOrwell";
567 const std::string js = "JohnSteinbeck";
568 rc_t rc = rc_t::OK;
569
570 /*
571 * George creates and deletes the interface
572 */
573 std::string itf1_name = "afpacket1";
574 interface itf1(itf1_name,
575 interface::type_t::AFPACKET,
576 interface::admin_state_t::UP);
577
578 /*
579 * set the expectation for a afpacket interface create.
580 * 2 is the interface handle VPP [mock] assigns
581 */
582 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700583 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700584
585 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700586 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700587
588 TRY_CHECK_RC(OM::write(go, itf1));
589
590 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700591 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
592 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700593
594 TRY_CHECK(OM::remove(go));
595
596 /*
597 * George creates the interface, then John brings it down.
598 * George's remove is a no-op, sice John also owns the interface
599 */
600 interface itf1b(itf1_name,
601 interface::type_t::AFPACKET,
602 interface::admin_state_t::DOWN);
603
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700604 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
605 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700606 TRY_CHECK_RC(OM::write(go, itf1));
607
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700608 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700609 TRY_CHECK_RC(OM::write(js, itf1b));
610
611 TRY_CHECK(OM::remove(go));
612
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700613 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700614 TRY_CHECK(OM::remove(js));
615
616 /*
617 * George adds an interface, then we flush all of Geroge's state
618 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700619 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
620 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700621 TRY_CHECK_RC(OM::write(go, itf1));
622
623 TRY_CHECK(OM::mark(go));
624
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700625 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
626 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700627 TRY_CHECK(OM::sweep(go));
628
629 /*
630 * George adds an interface. mark stale. update the same interface. sweep
631 * and expect no delete
632 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700633 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
634 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700635 TRY_CHECK_RC(OM::write(go, itf1b));
636
637 TRY_CHECK(OM::mark(go));
638
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700639 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700640 TRY_CHECK_RC(OM::write(go, itf1));
641
642 TRY_CHECK(OM::sweep(go));
643
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700644 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
645 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700646 TRY_CHECK(OM::remove(go));
647
648 /*
649 * George adds an insterface, then we mark that state. Add a second interface
650 * an flush the first that is now stale.
651 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700652 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
653 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700654 TRY_CHECK_RC(OM::write(go, itf1));
655
656 TRY_CHECK(OM::mark(go));
657
658 std::string itf2_name = "afpacket2";
Neale Ranns4ef42262018-02-20 08:10:44 -0800659 std::string itf2_tag = "uuid-of-afpacket2-interface";
Neale Ranns812ed392017-10-16 04:20:13 -0700660 interface itf2(itf2_name,
661 interface::type_t::AFPACKET,
Neale Ranns4ef42262018-02-20 08:10:44 -0800662 interface::admin_state_t::UP,
663 itf2_tag);
Neale Ranns812ed392017-10-16 04:20:13 -0700664 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
665
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700666 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
Neale Ranns4ef42262018-02-20 08:10:44 -0800667 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700668 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700669 TRY_CHECK_RC(OM::write(go, itf2));
670
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700671 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
672 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700673 TRY_CHECK(OM::sweep(go));
674
675 TRY_CHECK(OM::mark(go));
676
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700677 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
678 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700679 TRY_CHECK(OM::sweep(go));
Neale Ranns4ef42262018-02-20 08:10:44 -0800680
681
682 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
683 std::string itf3_tag = "uuid-of-vhost_user1-interface";
684 interface itf3(itf3_name,
685 interface::type_t::VHOST,
686 interface::admin_state_t::UP,
687 itf3_tag);
688 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
689
690 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
691 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
692 TRY_CHECK_RC(OM::write(go, itf3));
693
694 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
695 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
696 TRY_CHECK(OM::remove(go));
Neale Ranns812ed392017-10-16 04:20:13 -0700697}
698
699BOOST_AUTO_TEST_CASE(test_bvi) {
700 VppInit vi;
701 const std::string ernest = "ErnestHemmingway";
702 const std::string graham = "GrahamGreene";
703 rc_t rc = rc_t::OK;
704 l3_binding *l3;
705
706 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
707 rc_t::OK);
708 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
709 rc_t::OK);
710
711 /*
712 * Enrest creates a BVI with address 10.10.10.10/24
713 */
714 route::prefix_t pfx_10("10.10.10.10", 24);
715
716 const std::string bvi_name = "bvi1";
717 interface itf(bvi_name,
718 interface::type_t::BVI,
719 interface::admin_state_t::UP);
720 HW::item<handle_t> hw_ifh(4, rc_t::OK);
721 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
722
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700723 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
724 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
725 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700726 TRY_CHECK_RC(OM::write(ernest, itf));
727
728 l3 = new l3_binding(itf, pfx_10);
729 HW::item<bool> hw_l3_bind(true, rc_t::OK);
730 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700731 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700732 TRY_CHECK_RC(OM::write(ernest, *l3));
733
734 // change the MAC address on the BVI
735 interface itf_new_mac(bvi_name,
736 interface::type_t::BVI,
737 interface::admin_state_t::UP);
738 l2_address_t l2_addr({0,1,2,3,4,5});
739 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
740 itf_new_mac.set(l2_addr);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700741 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700742 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
743
744 // create/write the interface to the OM again but with an unset MAC
745 // this should not generate a MAC address update
746 TRY_CHECK_RC(OM::write(ernest, itf));
747
748 // change the MAC address on the BVI - again
749 interface itf_new_mac2(bvi_name,
750 interface::type_t::BVI,
751 interface::admin_state_t::UP);
752 l2_address_t l2_addr2({0,1,2,3,4,6});
753 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
754 itf_new_mac2.set(l2_addr2);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700755 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700756 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
757
758 delete l3;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700759 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
760 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
761 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700762 TRY_CHECK(OM::remove(ernest));
763
764 /*
765 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
766 */
767 route_domain rd(1);
768 HW::item<bool> hw_rd4_create(true, rc_t::OK);
769 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
770 HW::item<bool> hw_rd6_create(true, rc_t::OK);
771 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
772 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
773 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
774 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
775 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700776 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
777 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700778 TRY_CHECK_RC(OM::write(graham, rd));
779
780 const std::string bvi2_name = "bvi2";
781 interface *itf2 = new interface(bvi2_name,
782 interface::type_t::BVI,
783 interface::admin_state_t::UP,
784 rd);
785 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
786
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700787 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
788 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
789 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
790 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
791 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700792
793 TRY_CHECK_RC(OM::write(graham, *itf2));
794
795 l3 = new l3_binding(*itf2, pfx_10);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700796 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700797 TRY_CHECK_RC(OM::write(graham, *l3));
798
799 delete l3;
800 delete itf2;
801
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700802 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
803 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
804 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
805 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
806 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
807 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
808 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700809 TRY_CHECK(OM::remove(graham));
810}
811
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100812BOOST_AUTO_TEST_CASE(test_bond) {
813 VppInit vi;
814 const std::string cb = "CarolBerg";
815 rc_t rc = rc_t::OK;
816
817 /*
818 * creates the interfaces
819 */
820 std::string itf1_name = "afpacket1";
821 interface itf1(itf1_name,
822 interface::type_t::AFPACKET,
823 interface::admin_state_t::UP);
824
825 HW::item<handle_t> hw_ifh(2, rc_t::OK);
826 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
827
828 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
829 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
830
831 TRY_CHECK_RC(OM::write(cb, itf1));
832
833 std::string itf2_name = "afpacket2";
834 interface itf2(itf2_name,
835 interface::type_t::AFPACKET,
836 interface::admin_state_t::UP);
837
838
839 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
840 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
841 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
842
843 TRY_CHECK_RC(OM::write(cb, itf2));
844
845 std::string bond_name = "bond";
846 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
847 bond_interface::mode_t::LACP);
848
849 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
850 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
851 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
852 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
853
854 TRY_CHECK_RC(OM::write(cb, bond_itf));
855
856 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
857 bond_member::rate_t::SLOW);
858 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
859 bond_member::rate_t::SLOW);
860 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
861
862 HW::item<bool> bond_hw_bind(true, rc_t::OK);
863 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
864 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
865
866 TRY_CHECK_RC(OM::write(cb, *bgb));
867
868 delete bgb;
869 delete bm2;
870 delete bm1;
871
872 STRICT_ORDER_OFF();
873 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
874 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
875 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
876 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
877 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
879 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
880 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
881 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
882
883 TRY_CHECK(OM::remove(cb));
884}
885
Neale Ranns812ed392017-10-16 04:20:13 -0700886BOOST_AUTO_TEST_CASE(test_bridge) {
887 VppInit vi;
888 const std::string franz = "FranzKafka";
889 const std::string dante = "Dante";
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100890 const std::string jkr = "jkrowling";
Neale Ranns812ed392017-10-16 04:20:13 -0700891 rc_t rc = rc_t::OK;
892
893 /*
894 * Franz creates an interface, Bridge-domain, then binds the two
895 */
896
897 // interface create
898 std::string itf1_name = "afpacket1";
899 interface itf1(itf1_name,
900 interface::type_t::AFPACKET,
901 interface::admin_state_t::UP);
902
903 HW::item<handle_t> hw_ifh(3, rc_t::OK);
904 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
905 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700906 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
907 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700908
909 TRY_CHECK_RC(OM::write(franz, itf1));
910
911 // bridge-domain create
912 bridge_domain bd1(33);
913
914 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -0700915 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
916 bridge_domain::learning_mode_t::ON,
917 bridge_domain::arp_term_mode_t::ON,
918 bridge_domain::flood_mode_t::ON,
919 bridge_domain::mac_age_mode_t::OFF));
Neale Ranns812ed392017-10-16 04:20:13 -0700920
921 TRY_CHECK_RC(OM::write(franz, bd1));
922
923 // L2-interface create and bind
924 // this needs to be delete'd before the flush below, since it too maintains
925 // references to the BD and Interface
926 l2_binding *l2itf = new l2_binding(itf1, bd1);
927 HW::item<bool> hw_l2_bind(true, rc_t::OK);
928
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700929 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
Neale Ranns812ed392017-10-16 04:20:13 -0700930 TRY_CHECK_RC(OM::write(franz, *l2itf));
931
932 /*
933 * Dante adds an interface to the same BD
934 */
935 std::string itf2_name = "afpacket2";
936 interface itf2(itf2_name,
937 interface::type_t::AFPACKET,
938 interface::admin_state_t::UP);
939
940 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700941 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
942 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700943 TRY_CHECK_RC(OM::write(dante, itf2));
944
945 // BD add is a no-op since it exists
946 TRY_CHECK_RC(OM::write(dante, bd1));
947
948 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
949 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
950 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
951
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700952 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
953 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
Neale Ranns812ed392017-10-16 04:20:13 -0700954 TRY_CHECK_RC(OM::write(dante, *l2itf2));
955
956 // Add some static entries to the bridge-domain
957 HW::item<bool> hw_be1(true, rc_t::OK);
958 mac_address_t mac1({0,1,2,3,4,5});
959 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100960 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
961 false));
Neale Ranns812ed392017-10-16 04:20:13 -0700962 TRY_CHECK_RC(OM::write(dante, *be1));
963
964 // Add some entries to the bridge-domain ARP termination table
965 HW::item<bool> hw_bea1(true, rc_t::OK);
966 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
967
Neale Rannsfd920602017-11-23 12:15:00 -0800968 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700969 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
Neale Ranns812ed392017-10-16 04:20:13 -0700970 TRY_CHECK_RC(OM::write(dante, *bea1));
971
972 // flush Franz's state
973 delete l2itf;
974 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
975 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700976 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
977 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
978 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700979 TRY_CHECK(OM::remove(franz));
980
981 // flush Dante's state - the order the interface and BD are deleted
982 // is an uncontrollable artifact of the C++ object destruction.
983 delete l2itf2;
984 delete be1;
985 delete bea1;
986 STRICT_ORDER_OFF();
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100987 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
988 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700989 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100990
991 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700992 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
993 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700994 TRY_CHECK(OM::remove(dante));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100995
996 // test the BVI entry in l2fib
997 bridge_domain bd2(99);
998
999 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001000 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1001 bridge_domain::learning_mode_t::ON,
1002 bridge_domain::arp_term_mode_t::ON,
1003 bridge_domain::flood_mode_t::ON,
1004 bridge_domain::mac_age_mode_t::OFF));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001005
1006 TRY_CHECK_RC(OM::write(jkr, bd2));
1007
1008 std::string itf3_name = "bvi";
1009 interface itf3(itf3_name,
1010 interface::type_t::BVI,
1011 interface::admin_state_t::UP);
1012
1013 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1014 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1015 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1016 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1017 TRY_CHECK_RC(OM::write(jkr, itf3));
1018
1019 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1020 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1021 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1022
1023 HW::item<bool> hw_be2(true, rc_t::OK);
1024 mac_address_t mac2({0,1,2,3,4,5});
1025 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1026 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1027 TRY_CHECK_RC(OM::write(jkr, *be2));
1028
1029 delete l2itf3;
1030 delete be2;
1031 STRICT_ORDER_OFF();
1032 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1033 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1034 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1035 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1036 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1037 TRY_CHECK(OM::remove(jkr));
Neale Ranns812ed392017-10-16 04:20:13 -07001038}
1039
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +02001040BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1041 VppInit vi;
1042 const std::string nicholas = "NicholasAbercrombie";
1043 rc_t rc = rc_t::OK;
1044
1045 /*
1046 * Interface 1
1047 */
1048 std::string itf1_name = "host1";
1049 interface itf1(itf1_name,
1050 interface::type_t::AFPACKET,
1051 interface::admin_state_t::UP);
1052 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1053 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1054 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1055 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1056 TRY_CHECK_RC(OM::write(nicholas, itf1));
1057
1058 /*
1059 * Interface 2
1060 */
1061 std::string itf2_name = "host2";
1062 interface itf2(itf2_name,
1063 interface::type_t::AFPACKET,
1064 interface::admin_state_t::UP);
1065
1066 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1067 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1068 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1069 TRY_CHECK_RC(OM::write(nicholas, itf2));
1070
1071 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1072 HW::item<bool> xconnect_east(true, rc_t::OK);
1073 HW::item<bool> xconnect_west(true, rc_t::OK);
1074 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1075 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1076 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1077 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1078 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1079
1080 delete l2_xconn;
1081
1082 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1083 STRICT_ORDER_OFF();
1084 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1085 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1086 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1087 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1088 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1089 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1090
1091 TRY_CHECK(OM::remove(nicholas));
1092}
1093
Neale Ranns812ed392017-10-16 04:20:13 -07001094BOOST_AUTO_TEST_CASE(test_vxlan) {
1095 VppInit vi;
1096 const std::string franz = "FranzKafka";
1097 rc_t rc = rc_t::OK;
1098
1099 /*
1100 * Franz creates an interface, Bridge-domain, then binds the two
1101 */
1102
1103 // VXLAN create
1104 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
Neale Ranns25b04942018-04-04 09:34:50 -07001105 boost::asio::ip::address::from_string("10.10.10.11"),
1106 322);
Neale Ranns812ed392017-10-16 04:20:13 -07001107
1108 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1109
1110 HW::item<handle_t> hw_vxt(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001111 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001112
1113 TRY_CHECK_RC(OM::write(franz, vxt));
1114
1115 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001116 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1117 bridge_domain::arp_term_mode_t::OFF,
1118 bridge_domain::flood_mode_t::OFF,
1119 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001120
1121 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001122 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1123 bridge_domain::learning_mode_t::OFF,
1124 bridge_domain::arp_term_mode_t::OFF,
1125 bridge_domain::flood_mode_t::OFF,
1126 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001127
1128 TRY_CHECK_RC(OM::write(franz, bd1));
1129
1130 // L2-interface create and bind
1131 // this needs to be delete'd before the flush below, since it too maintains
1132 // references to the BD and Interface
1133 l2_binding *l2itf = new l2_binding(vxt, bd1);
1134 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1135
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001136 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
Neale Ranns812ed392017-10-16 04:20:13 -07001137 TRY_CHECK_RC(OM::write(franz, *l2itf));
1138
1139 // flush Franz's state
1140 delete l2itf;
1141 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1142 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001143 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1144 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1145 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001146 TRY_CHECK(OM::remove(franz));
1147}
1148
1149BOOST_AUTO_TEST_CASE(test_vlan) {
1150 VppInit vi;
1151 const std::string noam = "NoamChomsky";
1152 rc_t rc = rc_t::OK;
1153
1154 std::string itf1_name = "host1";
1155 interface itf1(itf1_name,
1156 interface::type_t::AFPACKET,
1157 interface::admin_state_t::UP);
1158
1159 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001160 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001161
1162 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001163 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001164
1165 TRY_CHECK_RC(OM::write(noam, itf1));
1166
1167 sub_interface *vl33 = new sub_interface(itf1,
1168 interface::admin_state_t::UP,
1169 33);
1170
1171 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001172 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1173 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001174
1175 TRY_CHECK_RC(OM::write(noam, *vl33));
1176
1177 delete vl33;
1178 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1179 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001180 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1181 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1182 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1183 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001184
1185 TRY_CHECK(OM::remove(noam));
1186}
1187
1188BOOST_AUTO_TEST_CASE(test_acl) {
1189 VppInit vi;
1190 const std::string fyodor = "FyodorDostoyevsky";
1191 const std::string leo = "LeoTolstoy";
1192 rc_t rc = rc_t::OK;
1193
1194 /*
1195 * Fyodor adds an ACL in the input direction
1196 */
1197 std::string itf1_name = "host1";
1198 interface itf1(itf1_name,
1199 interface::type_t::AFPACKET,
1200 interface::admin_state_t::UP);
1201 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1202 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001203 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1204 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001205 TRY_CHECK_RC(OM::write(fyodor, itf1));
1206
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001207 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1208 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1209 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1210 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1211 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1212 HW::item<bool> ae_binding(true, rc_t::OK);
1213 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1214 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1215
Neale Ranns812ed392017-10-16 04:20:13 -07001216 route::prefix_t src("10.10.10.10", 32);
1217 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1218 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1219
1220 std::string acl_name = "acl1";
1221 ACL::l3_list acl1(acl_name);
1222 acl1.insert(r2);
1223 acl1.insert(r1);
1224 ACL::l3_list::rules_t rules = {r1, r2};
1225
1226 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001227 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001228 TRY_CHECK_RC(OM::write(fyodor, acl1));
1229
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001230 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1231 ACL::l3_list acl2(acl_name);
1232 acl2.insert(r3);
1233 ACL::l3_list::rules_t rules2 = {r3};
1234 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1235 TRY_CHECK_RC(OM::write(fyodor, acl2));
1236
Neale Ranns812ed392017-10-16 04:20:13 -07001237 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1238 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001239 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1240 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001241 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1242
1243 /**
1244 * Leo adds an L2 ACL in the output direction
1245 */
1246 TRY_CHECK_RC(OM::write(leo, itf1));
1247
1248 std::string l2_acl_name = "l2_acl1";
1249 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1250 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1251 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1252 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1253
1254 ACL::l2_list l2_acl(l2_acl_name);
1255 l2_acl.insert(l2_r2);
1256 l2_acl.insert(l2_r1);
1257
1258 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1259
1260 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001261 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001262 TRY_CHECK_RC(OM::write(leo, l2_acl));
1263
1264 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1265 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001266 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001267 hw_ifh.data(), l2_hw_acl.data()));
1268 TRY_CHECK_RC(OM::write(leo, *l2b));
1269
1270 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001271 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1272 hw_ifh.data(), l2_hw_acl.data()));
1273 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001274 TRY_CHECK(OM::remove(leo));
1275
1276 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001277 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001278 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1279 rc_t::OK);
1280 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001281 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001282 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001283 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001284 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001285 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1286 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001287
1288 TRY_CHECK(OM::remove(fyodor));
1289}
1290
1291BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1292 VppInit vi;
1293 const std::string kurt = "KurtVonnegut";
1294 rc_t rc = rc_t::OK;
1295
1296 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1297 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1298
1299 arp_proxy_config ap(low, high);
1300 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001301 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001302 TRY_CHECK_RC(OM::write(kurt, ap));
1303
1304 std::string itf3_name = "host3";
1305 interface itf3(itf3_name,
1306 interface::type_t::AFPACKET,
1307 interface::admin_state_t::UP);
1308 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1309 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001310 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1311 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001312 TRY_CHECK_RC(OM::write(kurt, itf3));
1313
Neale Ranns0053de62018-05-22 08:40:52 -07001314 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001315 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001316 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001317 TRY_CHECK_RC(OM::write(kurt, *apb));
1318
1319 delete apb;
1320
1321 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1322 rc_t::OK);
1323 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001324 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1325 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1326 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1327 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001328
1329 TRY_CHECK(OM::remove(kurt));
1330}
1331
1332BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1333 VppInit vi;
1334 const std::string eric = "EricAmbler";
1335 rc_t rc = rc_t::OK;
1336
1337 /*
1338 * Interface 1 has the L3 address
1339 */
1340 std::string itf1_name = "host1";
1341 interface itf1(itf1_name,
1342 interface::type_t::AFPACKET,
1343 interface::admin_state_t::UP);
1344 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1345 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001346 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1347 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001348 TRY_CHECK_RC(OM::write(eric, itf1));
1349
1350 route::prefix_t pfx_10("10.10.10.10", 24);
1351 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1352 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1353 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001354 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001355 TRY_CHECK_RC(OM::write(eric, *l3));
1356
1357 /*
1358 * Interface 2 is unnumbered
1359 */
1360 std::string itf2_name = "host2";
1361 interface itf2(itf2_name,
1362 interface::type_t::AFPACKET,
1363 interface::admin_state_t::UP);
1364
1365 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001366 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1367 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001368 TRY_CHECK_RC(OM::write(eric, itf2));
1369
1370 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1371 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1372 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001373 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001374 TRY_CHECK_RC(OM::write(eric, *ipun));
1375
1376 delete l3;
1377 delete ipun;
1378
1379 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1380 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001381 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1382 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1383 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1384 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1385 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1386 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001387
1388 TRY_CHECK(OM::remove(eric));
1389}
1390
1391BOOST_AUTO_TEST_CASE(test_ip6nd) {
1392 VppInit vi;
1393 const std::string paulo = "PauloCoelho";
1394 rc_t rc = rc_t::OK;
1395
1396 /*
1397 * ra config
1398 */
1399 std::string itf_name = "host_ip6nd";
1400 interface itf(itf_name,
1401 interface::type_t::AFPACKET,
1402 interface::admin_state_t::UP);
1403 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1404 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001405 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1406 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001407 TRY_CHECK_RC(OM::write(paulo, itf));
1408
1409 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1410 l3_binding *l3 = new l3_binding(itf, pfx_10);
1411 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1412 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001413 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001414 TRY_CHECK_RC(OM::write(paulo, *l3));
1415
1416 ra_config ra(0, 1, 0, 4);
1417 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1418 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1419 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1420 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1421 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1422
1423 /*
1424 * ra prefix
1425 */
1426 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1427 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1428 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1429 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1430 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1431 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1432
1433 delete ip6pfx;
1434
1435 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1436
1437 delete ip6ra;
1438 delete l3;
1439
1440 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1441
1442 STRICT_ORDER_OFF();
1443 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001444 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1445 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1446 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001447
1448 TRY_CHECK(OM::remove(paulo));
1449}
1450
1451BOOST_AUTO_TEST_CASE(test_interface_span) {
1452 VppInit vi;
1453 const std::string elif = "ElifShafak";
1454 rc_t rc = rc_t::OK;
1455
1456 /*
1457 * Interface 1 to be mirrored
1458 */
1459 std::string itf1_name = "port-from";
1460 interface itf1(itf1_name,
1461 interface::type_t::AFPACKET,
1462 interface::admin_state_t::UP);
1463 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1464 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001465 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1466 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001467 TRY_CHECK_RC(OM::write(elif, itf1));
1468
1469 /*
1470 * Interface 2 where traffic is mirrored
1471 */
1472 std::string itf2_name = "port-to";
1473 interface itf2(itf2_name,
1474 interface::type_t::AFPACKET,
1475 interface::admin_state_t::UP);
1476
1477 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1478 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1479
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001480 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1481 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001482 TRY_CHECK_RC(OM::write(elif, itf2));
1483
1484 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1485 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1486 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001487 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 -07001488 TRY_CHECK_RC(OM::write(elif, *itf_span));
1489
1490 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1491 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1492
1493 delete itf_span;
1494 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001495 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1496 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1497 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1498 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1499 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001500
1501 TRY_CHECK(OM::remove(elif));
1502}
1503
1504BOOST_AUTO_TEST_CASE(test_routing) {
1505 VppInit vi;
1506 const std::string ian = "IanFleming";
1507 rc_t rc = rc_t::OK;
1508
1509 /*
1510 * non-default route domain
1511 */
1512 route_domain rd4(1);
1513 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1514 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1515 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1516 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1517 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1518 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1519 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1520 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001521 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1522 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001523 TRY_CHECK_RC(OM::write(ian, rd4));
1524
1525 /*
1526 * a couple of interfaces
1527 */
1528 std::string itf1_name = "af1";
1529 interface itf1(itf1_name,
1530 interface::type_t::AFPACKET,
1531 interface::admin_state_t::UP);
1532 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1533 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1534 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001535 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1536 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001537 TRY_CHECK_RC(OM::write(ian, itf1));
1538
1539 std::string itf2_name = "af2";
1540 interface *itf2 = new interface(itf2_name,
1541 interface::type_t::AFPACKET,
1542 interface::admin_state_t::UP,
1543 rd4);
1544
1545 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1546 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1547 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001548 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1549 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1550 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1551 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001552 TRY_CHECK_RC(OM::write(ian, *itf2));
1553
1554 /*
1555 * prefix on each interface
1556 */
1557 route::prefix_t pfx_10("10.10.10.10", 24);
1558 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1559 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1560 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001561 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001562 TRY_CHECK_RC(OM::write(ian, *l3_10));
1563 route::prefix_t pfx_11("11.11.11.11", 24);
1564 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1565 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1566 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001567 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001568 TRY_CHECK_RC(OM::write(ian, *l3_11));
1569
1570 /*
1571 * A route via interface 1 in the default table
1572 */
1573 route::prefix_t pfx_5("5.5.5.5", 32);
1574 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1575 route::path *path_10 = new route::path(nh_10, itf1);
1576 route::ip_route *route_5 = new route::ip_route(pfx_5);
1577 route_5->add(*path_10);
1578 HW::item<bool> hw_route_5(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001579 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
Neale Ranns812ed392017-10-16 04:20:13 -07001580 TRY_CHECK_RC(OM::write(ian, *route_5));
1581
1582 /*
1583 * A route via interface 2 in the non-default table
1584 */
1585 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1586 route::path *path_11 = new route::path(nh_11, *itf2);
1587 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1588 route_5_2->add(*path_11);
1589 HW::item<bool> hw_route_5_2(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001590 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
Neale Ranns812ed392017-10-16 04:20:13 -07001591 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1592
1593 /*
1594 * An ARP entry for the neighbour on itf1
1595 */
1596 HW::item<bool> hw_neighbour(true, rc_t::OK);
1597 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001598 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001599 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001600 TRY_CHECK_RC(OM::write(ian, *ne));
1601
1602 /*
1603 * A DVR route
1604 */
1605 route::prefix_t pfx_6("6.6.6.6", 32);
1606 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1607 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1608 route_dvr->add(*path_l2);
1609 HW::item<bool> hw_route_dvr(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001610 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
Neale Ranns812ed392017-10-16 04:20:13 -07001611 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1612
1613 STRICT_ORDER_OFF();
1614 // delete the stack objects that hold references to others
1615 // so the OM::remove is the call that removes the last reference
1616 delete l3_11;
1617 delete l3_10;
1618 delete itf2;
1619 delete route_5;
1620 delete path_10;
1621 delete route_5_2;
1622 delete path_11;
1623 delete route_dvr;
1624 delete path_l2;
1625 delete ne;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001626 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1627 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1628 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1629 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1630 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1631 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1632 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1633 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1634 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1635 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1636 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1637 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1638 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1639 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001640
1641 TRY_CHECK(OM::remove(ian));
1642}
1643
1644BOOST_AUTO_TEST_CASE(test_nat) {
1645 VppInit vi;
1646 const std::string gs = "GeorgeSimenon";
1647 rc_t rc = rc_t::OK;
1648
1649 /*
1650 * Inside Interface
1651 */
1652 std::string itf_in_name = "inside";
1653 interface itf_in(itf_in_name,
1654 interface::type_t::AFPACKET,
1655 interface::admin_state_t::UP);
1656 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1657 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1658 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001659 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1660 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001661 TRY_CHECK_RC(OM::write(gs, itf_in));
1662
1663 /*
1664 * outside
1665 */
1666 std::string itf_out_name = "port-to";
1667 interface itf_out(itf_out_name,
1668 interface::type_t::AFPACKET,
1669 interface::admin_state_t::UP);
1670
1671 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1672 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1673 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1674
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001675 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1676 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001677 TRY_CHECK_RC(OM::write(gs, itf_out));
1678
1679 /*
1680 * A NAT static mapping
1681 */
1682 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1683 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1684
1685 nat_static ns(in_addr, out_addr);
1686 HW::item<bool> hw_ns(true, rc_t::OK);
1687
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001688 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001689 TRY_CHECK_RC(OM::write(gs, ns));
1690
1691 /*
1692 * bind nat inside and out
1693 */
1694 nat_binding *nb_in = new nat_binding(itf_in,
1695 direction_t::INPUT,
1696 l3_proto_t::IPV4,
1697 nat_binding::zone_t::INSIDE);
1698 HW::item<bool> hw_nb_in(true, rc_t::OK);
1699
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001700 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1701 hw_ifh.data().value(),
1702 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001703 TRY_CHECK_RC(OM::write(gs, *nb_in));
1704
1705 nat_binding *nb_out = new nat_binding(itf_out,
1706 direction_t::INPUT,
1707 l3_proto_t::IPV4,
1708 nat_binding::zone_t::OUTSIDE);
1709 HW::item<bool> hw_nb_out(true, rc_t::OK);
1710
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001711 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1712 hw_ifh2.data().value(),
1713 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001714 TRY_CHECK_RC(OM::write(gs, *nb_out));
1715
1716
1717 STRICT_ORDER_OFF();
1718 delete nb_in;
1719 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001720 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1721 hw_ifh.data().value(),
1722 nat_binding::zone_t::INSIDE));
1723 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1724 hw_ifh2.data().value(),
1725 nat_binding::zone_t::OUTSIDE));
1726 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1727 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1728 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1729 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1730 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001731
1732 TRY_CHECK(OM::remove(gs));
1733}
1734
1735BOOST_AUTO_TEST_CASE(test_interface_events) {
1736 VppInit vi;
1737 MockListener ml;
1738
1739 HW::item<bool> hw_want(true, rc_t::OK);
1740
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001741 ADD_EXPECT(interface_cmds::events_cmd(ml));
1742 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07001743
1744 HW::enqueue(itf);
1745 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07001746}
1747
Neale Ranns352ea0c2017-11-14 11:04:28 -08001748BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1749 VppInit vi;
1750 const std::string rene = "ReneGoscinny";
1751 rc_t rc = rc_t::OK;
1752
1753 /*
1754 * Create an interface with two IP addresses
1755 */
1756 std::string itf1_name = "host1";
1757 interface itf1(itf1_name,
1758 interface::type_t::AFPACKET,
1759 interface::admin_state_t::UP);
1760 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1761 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1762 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1763 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1764 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1765 TRY_CHECK_RC(OM::write(rene, itf1));
1766
1767 route::prefix_t pfx_10("10.10.10.10", 24);
1768 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1769 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1770 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1771 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1772 TRY_CHECK_RC(OM::write(rene, *l3_1));
1773
1774 route::prefix_t pfx_11("10.10.11.11", 24);
1775 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1776 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1777 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1778 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1779 TRY_CHECK_RC(OM::write(rene, *l3_2));
1780
1781 route_domain rd(1);
1782 HW::item<bool> hw_rd_create(true, rc_t::OK);
1783 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1784 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1785 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1786 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1787 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1788 TRY_CHECK_RC(OM::write(rene, rd));
1789
1790 /*
1791 * update the interface to change to a new route-domain
1792 * expect that the l3-bindings are removed and readded.
1793 */
1794 interface *itf2 = new interface(itf1_name,
1795 interface::type_t::AFPACKET,
1796 interface::admin_state_t::UP,
1797 rd);
1798 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1799 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1800 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1801 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1802 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1803 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1804 TRY_CHECK_RC(OM::write(rene, *itf2));
1805
1806 /*
1807 * mve the interface back to the default route-domain
1808 */
1809 interface itf3(itf1_name,
1810 interface::type_t::AFPACKET,
1811 interface::admin_state_t::UP);
1812 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1813 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1814 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1815 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1816 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1817 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1818 TRY_CHECK_RC(OM::write(rene, itf3));
1819
1820 delete l3_1;
1821 delete l3_2;
1822 delete itf2;
1823
1824 STRICT_ORDER_OFF();
1825 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1826 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1827 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1828 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1829 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1830 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1831
1832 TRY_CHECK(OM::remove(rene));
1833}
1834
Neale Rannsd3464b52017-12-07 08:48:02 -08001835BOOST_AUTO_TEST_CASE(test_prefixes) {
1836 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1837
1838 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1839
1840 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1841
1842 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1843 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1844
1845 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1846 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1847 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1848
1849 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1850
1851 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1852
1853 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1854
1855 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1856 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1857 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1858
1859 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1860
1861 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1862 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1863 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1864
1865 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1866
1867 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1868 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1869 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1870
1871}
1872
Neale Ranns208c29a2018-04-11 08:08:30 -07001873BOOST_AUTO_TEST_CASE(test_pipes) {
1874 VppInit vi;
1875 const std::string gk = "GKChesterton";
1876
1877 const std::string pipe_name_1 = "pipe1";
1878 VOM::pipe pipe1(1, interface::admin_state_t::UP);
1879 HW::item<handle_t> hw_hdl(4, rc_t::OK);
1880 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
1881
1882 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
1883 rc_t::OK);
1884 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1885 rc_t::OK);
1886 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
1887 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
1888 TRY_CHECK_RC(OM::write(gk, pipe1));
1889
1890 pipe1.set_ends(hw_hdl_pair.data());
1891
1892 // put each end of the pipe in a BD
1893 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1894 bridge_domain::arp_term_mode_t::OFF,
1895 bridge_domain::flood_mode_t::OFF,
1896 bridge_domain::mac_age_mode_t::ON);
1897
1898 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1899 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1900 bridge_domain::learning_mode_t::OFF,
1901 bridge_domain::arp_term_mode_t::OFF,
1902 bridge_domain::flood_mode_t::OFF,
1903 bridge_domain::mac_age_mode_t::ON));
1904
1905 TRY_CHECK_RC(OM::write(gk, bd1));
1906
1907 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
1908 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
1909
1910 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
1911 pipe1.east()->handle(),
1912 hw_bd.data(), false));
1913 TRY_CHECK_RC(OM::write(gk, *l2_1));
1914
1915 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
1916 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
1917
1918 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
1919 pipe1.west()->handle(),
1920 hw_bd.data(), false));
1921 TRY_CHECK_RC(OM::write(gk, *l2_2));
1922
1923 STRICT_ORDER_OFF();
1924
1925 delete l2_1;
1926 delete l2_2;
1927 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
1928 pipe1.east()->handle(),
1929 hw_bd.data(),
1930 false));
1931 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
1932 pipe1.west()->handle(),
1933 hw_bd.data(),
1934 false));
1935 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
1936 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
1937 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1938 TRY_CHECK(OM::remove(gk));
1939}
1940
Neale Ranns812ed392017-10-16 04:20:13 -07001941BOOST_AUTO_TEST_SUITE_END()