blob: 0213c42196ef9bdf0e7a28797cbf8c1a241d1bf8 [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 Ranns812ed392017-10-16 04:20:13 -070070
71using namespace boost;
72using namespace VOM;
73
74/**
75 * An expectation exception
76 */
77class ExpException
78{
79public:
80 ExpException(unsigned int number)
81 {
82 // a neat place to add a break point
83 std::cout << " ExpException here: " << number << std::endl;
84 }
85};
86
87class MockListener : public interface::event_listener,
88 public interface::stat_listener
89{
Neale Rannsa2ee0292017-11-28 22:29:13 -080090 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
Neale Ranns812ed392017-10-16 04:20:13 -070091 {
92 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070093 void handle_interface_event(interface_cmds::events_cmd *cmd)
Neale Ranns812ed392017-10-16 04:20:13 -070094 {
95 }
96};
97
98class MockCmdQ : public HW::cmd_q
99{
100public:
101 MockCmdQ():
102 m_strict_order(true)
103 {
104 }
105 virtual ~MockCmdQ()
106 {
107 }
108 void expect(cmd *f)
109 {
110 m_exp_queue.push_back(f);
111 }
112 void enqueue(cmd *f)
113 {
114 m_act_queue.push_back(f);
115 }
116 void enqueue(std::queue<cmd*> &cmds)
117 {
118 while (cmds.size())
119 {
120 m_act_queue.push_back(cmds.front());
121 cmds.pop();
122 }
123 }
124 void enqueue(std::shared_ptr<cmd> f)
125 {
126 m_act_queue.push_back(f.get());
127 }
128
129 void dequeue(cmd *f)
130 {
131 }
132
133 void dequeue(std::shared_ptr<cmd> cmd)
134 {
135 }
136
137 void strict_order(bool on)
138 {
139 m_strict_order = on;
140 }
141
142 bool is_empty()
143 {
144 return ((0 == m_exp_queue.size()) &&
145 (0 == m_act_queue.size()));
146 }
147
148 rc_t write()
149 {
150 cmd *f_exp, *f_act;
151 rc_t rc = rc_t::OK;
152
153 while (m_act_queue.size())
154 {
155 bool matched = false;
156 auto it_exp = m_exp_queue.begin();
157 auto it_act = m_act_queue.begin();
158
159 f_act = *it_act;
160
161 std::cout << " Act: " << f_act->to_string() << std::endl;
162 while (it_exp != m_exp_queue.end())
163 {
164 f_exp = *it_exp;
165 try
166 {
167 std::cout << " Exp: " << f_exp->to_string() << std::endl;
168
169 if (typeid(*f_exp) != typeid(*f_act))
170 {
171 throw ExpException(1);
172 }
173
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700174 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700175 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700176 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700177 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700178 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700179 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700180 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700181 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800182 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
183 {
184 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
185 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100186 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
187 {
188 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
189 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700190 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700191 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700192 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700193 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700194 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700195 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700196 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700197 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800198 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
199 {
200 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
201 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100202 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
203 {
204 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
205 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700206 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700207 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700208 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700209 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700210 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700211 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700212 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700213 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700214 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700215 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700216 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700217 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700218 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
Neale Ranns812ed392017-10-16 04:20:13 -0700219 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700220 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700221 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100222 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
223 {
224 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
225 }
226 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
227 {
228 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
229 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700230 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700231 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700232 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700233 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700234 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700235 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700236 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700237 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700238 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700239 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700240 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700241 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700242 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700243 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700244 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700245 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700246 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700247 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700248 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700249 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700250 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700251 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700252 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700253 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700254 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700255 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700256 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700257 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700258 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700259 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700260 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700261 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700262 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700263 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700264 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700265 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700266 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700267 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700268 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700269 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700270 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700271 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700272 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700273 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700274 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700275 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700276 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700277 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700278 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700279 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700280 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700281 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700282 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700283 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700284 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700285 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700286 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700287 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700288 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700289 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700290 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700291 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700292 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700293 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700294 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700295 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700296 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700297 }
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +0200298 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
299 {
300 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
301 }
302 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
303 {
304 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
305 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700306 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700307 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700308 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700309 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700310 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700311 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700312 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700313 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700314 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700315 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700316 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700317 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700318 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700319 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700320 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700321 }
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +0100322 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
323 {
324 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
325 }
Mohsin Kazmi04def742018-03-07 19:53:51 +0100326 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
327 {
328 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
329 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700330 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700331 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700332 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700333 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700334 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700335 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700336 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700337 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700338 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700339 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700340 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700341 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700342 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700343 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700344 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700345 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700346 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700347 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700348 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700349 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700350 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700351 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700352 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700353 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700354 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700355 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700356 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700357 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700358 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700359 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700360 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700361 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700362 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700363 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700364 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700365 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700366 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700367 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700368 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700369 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700370 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700371 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700372 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700373 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700374 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700375 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700376 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700377 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700378 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700379 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700380 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700381 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700382 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700383 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700384 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700385 }
386 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
387 {
388 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
389 }
390 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
391 {
392 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
393 }
394 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
395 {
396 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
397 }
398 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
399 {
400 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
401 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700402 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700403 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700404 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700405 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700406 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700407 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700408 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700409 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700410 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700411 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700412 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700413 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700414 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700415 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700416 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700417 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700418 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700419 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700420 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700421 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700422 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700423 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700424 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700425 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700426 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700427 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700428 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700429 }
430 else
431 {
432 throw ExpException(2);
433 }
434
435 // if we get here then we found the match.
436 m_exp_queue.erase(it_exp);
437 m_act_queue.erase(it_act);
438 delete f_exp;
439 delete f_act;
440
441 // return any injected failures to the agent
442 if (rc_t::OK != rc && rc_t::NOOP != rc)
443 {
444 return (rc);
445 }
446
447 matched = true;
448 break;
449 }
450 catch (ExpException &e)
451 {
452 // The expected and actual do not match
453 if (m_strict_order)
454 {
455 // in strict ordering mode this is fatal, so rethrow
456 throw e;
457 }
458 else
459 {
460 // move the iterator onto the next in the expected list and
461 // check for a match
462 ++it_exp;
463 }
464 }
465 }
466
467 if (!matched)
468 throw ExpException(3);
469 }
470
471 return (rc);
472 }
473private:
474
475 template <typename T>
476 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
477 {
478 const T *i_exp;
479 T *i_act;
480
481 i_exp = dynamic_cast<const T*>(f_exp);
482 i_act = dynamic_cast<T*>(f_act);
483 if (!(*i_exp == *i_act))
484 {
485 throw ExpException(4);
486 }
487 // pass the data and return code to the agent
488 i_act->item() = i_exp->item();
489
490 return (i_act->item().rc());
491 }
492
493 // The Q to push the expectations on
494 std::deque<cmd*> m_exp_queue;
495
496 // the queue to push the actual events on
497 std::deque<cmd*> m_act_queue;
498
499 // control whether the expected queue is strictly ordered.
500 bool m_strict_order;
501};
502
503class VppInit {
504public:
505 std::string name;
506 MockCmdQ *f;
507
508 VppInit()
509 : name("vpp-ut"),
510 f(new MockCmdQ())
511 {
512 HW::init(f);
513 OM::init();
514 logger().set(log_level_t::DEBUG);
515 }
516
517 ~VppInit() {
518 delete f;
519 }
520};
521
Neale Rannsd3464b52017-12-07 08:48:02 -0800522BOOST_AUTO_TEST_SUITE(vom)
Neale Ranns812ed392017-10-16 04:20:13 -0700523
524#define TRY_CHECK_RC(stmt) \
525{ \
526 try { \
527 BOOST_CHECK(rc_t::OK == stmt); \
528 } \
529 catch (ExpException &e) \
530 { \
531 BOOST_CHECK(false); \
532 } \
533 BOOST_CHECK(vi.f->is_empty()); \
534}
535
536#define TRY_CHECK(stmt) \
537{ \
538 try { \
539 stmt; \
540 } \
541 catch (ExpException &e) \
542 { \
543 BOOST_CHECK(false); \
544 } \
545 BOOST_CHECK(vi.f->is_empty()); \
546}
547
548#define ADD_EXPECT(stmt) \
549 vi.f->expect(new stmt)
550
551#define STRICT_ORDER_OFF() \
552 vi.f->strict_order(false)
553
554BOOST_AUTO_TEST_CASE(test_interface) {
555 VppInit vi;
556 const std::string go = "GeorgeOrwell";
557 const std::string js = "JohnSteinbeck";
558 rc_t rc = rc_t::OK;
559
560 /*
561 * George creates and deletes the interface
562 */
563 std::string itf1_name = "afpacket1";
564 interface itf1(itf1_name,
565 interface::type_t::AFPACKET,
566 interface::admin_state_t::UP);
567
568 /*
569 * set the expectation for a afpacket interface create.
570 * 2 is the interface handle VPP [mock] assigns
571 */
572 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700573 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700574
575 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700576 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700577
578 TRY_CHECK_RC(OM::write(go, itf1));
579
580 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700581 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
582 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700583
584 TRY_CHECK(OM::remove(go));
585
586 /*
587 * George creates the interface, then John brings it down.
588 * George's remove is a no-op, sice John also owns the interface
589 */
590 interface itf1b(itf1_name,
591 interface::type_t::AFPACKET,
592 interface::admin_state_t::DOWN);
593
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700594 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
595 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700596 TRY_CHECK_RC(OM::write(go, itf1));
597
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700598 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700599 TRY_CHECK_RC(OM::write(js, itf1b));
600
601 TRY_CHECK(OM::remove(go));
602
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700603 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700604 TRY_CHECK(OM::remove(js));
605
606 /*
607 * George adds an interface, then we flush all of Geroge's state
608 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700609 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
610 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700611 TRY_CHECK_RC(OM::write(go, itf1));
612
613 TRY_CHECK(OM::mark(go));
614
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700615 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
616 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700617 TRY_CHECK(OM::sweep(go));
618
619 /*
620 * George adds an interface. mark stale. update the same interface. sweep
621 * and expect no delete
622 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700623 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
624 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700625 TRY_CHECK_RC(OM::write(go, itf1b));
626
627 TRY_CHECK(OM::mark(go));
628
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700629 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700630 TRY_CHECK_RC(OM::write(go, itf1));
631
632 TRY_CHECK(OM::sweep(go));
633
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700634 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
635 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700636 TRY_CHECK(OM::remove(go));
637
638 /*
639 * George adds an insterface, then we mark that state. Add a second interface
640 * an flush the first that is now stale.
641 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700642 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
643 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700644 TRY_CHECK_RC(OM::write(go, itf1));
645
646 TRY_CHECK(OM::mark(go));
647
648 std::string itf2_name = "afpacket2";
Neale Ranns4ef42262018-02-20 08:10:44 -0800649 std::string itf2_tag = "uuid-of-afpacket2-interface";
Neale Ranns812ed392017-10-16 04:20:13 -0700650 interface itf2(itf2_name,
651 interface::type_t::AFPACKET,
Neale Ranns4ef42262018-02-20 08:10:44 -0800652 interface::admin_state_t::UP,
653 itf2_tag);
Neale Ranns812ed392017-10-16 04:20:13 -0700654 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
655
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700656 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
Neale Ranns4ef42262018-02-20 08:10:44 -0800657 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700658 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700659 TRY_CHECK_RC(OM::write(go, itf2));
660
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700661 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
662 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700663 TRY_CHECK(OM::sweep(go));
664
665 TRY_CHECK(OM::mark(go));
666
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700667 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
668 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700669 TRY_CHECK(OM::sweep(go));
Neale Ranns4ef42262018-02-20 08:10:44 -0800670
671
672 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
673 std::string itf3_tag = "uuid-of-vhost_user1-interface";
674 interface itf3(itf3_name,
675 interface::type_t::VHOST,
676 interface::admin_state_t::UP,
677 itf3_tag);
678 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
679
680 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
681 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
682 TRY_CHECK_RC(OM::write(go, itf3));
683
684 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
685 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
686 TRY_CHECK(OM::remove(go));
Neale Ranns812ed392017-10-16 04:20:13 -0700687}
688
689BOOST_AUTO_TEST_CASE(test_bvi) {
690 VppInit vi;
691 const std::string ernest = "ErnestHemmingway";
692 const std::string graham = "GrahamGreene";
693 rc_t rc = rc_t::OK;
694 l3_binding *l3;
695
696 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
697 rc_t::OK);
698 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
699 rc_t::OK);
700
701 /*
702 * Enrest creates a BVI with address 10.10.10.10/24
703 */
704 route::prefix_t pfx_10("10.10.10.10", 24);
705
706 const std::string bvi_name = "bvi1";
707 interface itf(bvi_name,
708 interface::type_t::BVI,
709 interface::admin_state_t::UP);
710 HW::item<handle_t> hw_ifh(4, rc_t::OK);
711 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
712
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700713 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
714 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
715 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700716 TRY_CHECK_RC(OM::write(ernest, itf));
717
718 l3 = new l3_binding(itf, pfx_10);
719 HW::item<bool> hw_l3_bind(true, rc_t::OK);
720 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700721 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700722 TRY_CHECK_RC(OM::write(ernest, *l3));
723
724 // change the MAC address on the BVI
725 interface itf_new_mac(bvi_name,
726 interface::type_t::BVI,
727 interface::admin_state_t::UP);
728 l2_address_t l2_addr({0,1,2,3,4,5});
729 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
730 itf_new_mac.set(l2_addr);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700731 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700732 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
733
734 // create/write the interface to the OM again but with an unset MAC
735 // this should not generate a MAC address update
736 TRY_CHECK_RC(OM::write(ernest, itf));
737
738 // change the MAC address on the BVI - again
739 interface itf_new_mac2(bvi_name,
740 interface::type_t::BVI,
741 interface::admin_state_t::UP);
742 l2_address_t l2_addr2({0,1,2,3,4,6});
743 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
744 itf_new_mac2.set(l2_addr2);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700745 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700746 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
747
748 delete l3;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700749 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
750 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
751 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700752 TRY_CHECK(OM::remove(ernest));
753
754 /*
755 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
756 */
757 route_domain rd(1);
758 HW::item<bool> hw_rd4_create(true, rc_t::OK);
759 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
760 HW::item<bool> hw_rd6_create(true, rc_t::OK);
761 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
762 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
763 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
764 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
765 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700766 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
767 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700768 TRY_CHECK_RC(OM::write(graham, rd));
769
770 const std::string bvi2_name = "bvi2";
771 interface *itf2 = new interface(bvi2_name,
772 interface::type_t::BVI,
773 interface::admin_state_t::UP,
774 rd);
775 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
776
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700777 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
778 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
779 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
780 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
781 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700782
783 TRY_CHECK_RC(OM::write(graham, *itf2));
784
785 l3 = new l3_binding(*itf2, pfx_10);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700786 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700787 TRY_CHECK_RC(OM::write(graham, *l3));
788
789 delete l3;
790 delete itf2;
791
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700792 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
793 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
794 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
795 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
796 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
797 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
798 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700799 TRY_CHECK(OM::remove(graham));
800}
801
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100802BOOST_AUTO_TEST_CASE(test_bond) {
803 VppInit vi;
804 const std::string cb = "CarolBerg";
805 rc_t rc = rc_t::OK;
806
807 /*
808 * creates the interfaces
809 */
810 std::string itf1_name = "afpacket1";
811 interface itf1(itf1_name,
812 interface::type_t::AFPACKET,
813 interface::admin_state_t::UP);
814
815 HW::item<handle_t> hw_ifh(2, rc_t::OK);
816 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
817
818 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
819 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
820
821 TRY_CHECK_RC(OM::write(cb, itf1));
822
823 std::string itf2_name = "afpacket2";
824 interface itf2(itf2_name,
825 interface::type_t::AFPACKET,
826 interface::admin_state_t::UP);
827
828
829 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
830 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
831 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
832
833 TRY_CHECK_RC(OM::write(cb, itf2));
834
835 std::string bond_name = "bond";
836 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
837 bond_interface::mode_t::LACP);
838
839 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
840 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
841 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
842 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
843
844 TRY_CHECK_RC(OM::write(cb, bond_itf));
845
846 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
847 bond_member::rate_t::SLOW);
848 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
849 bond_member::rate_t::SLOW);
850 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
851
852 HW::item<bool> bond_hw_bind(true, rc_t::OK);
853 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
854 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
855
856 TRY_CHECK_RC(OM::write(cb, *bgb));
857
858 delete bgb;
859 delete bm2;
860 delete bm1;
861
862 STRICT_ORDER_OFF();
863 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
864 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
865 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
866 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
867 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
868 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
869 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
870 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
871 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
872
873 TRY_CHECK(OM::remove(cb));
874}
875
Neale Ranns812ed392017-10-16 04:20:13 -0700876BOOST_AUTO_TEST_CASE(test_bridge) {
877 VppInit vi;
878 const std::string franz = "FranzKafka";
879 const std::string dante = "Dante";
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100880 const std::string jkr = "jkrowling";
Neale Ranns812ed392017-10-16 04:20:13 -0700881 rc_t rc = rc_t::OK;
882
883 /*
884 * Franz creates an interface, Bridge-domain, then binds the two
885 */
886
887 // interface create
888 std::string itf1_name = "afpacket1";
889 interface itf1(itf1_name,
890 interface::type_t::AFPACKET,
891 interface::admin_state_t::UP);
892
893 HW::item<handle_t> hw_ifh(3, rc_t::OK);
894 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
895 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700896 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
897 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700898
899 TRY_CHECK_RC(OM::write(franz, itf1));
900
901 // bridge-domain create
902 bridge_domain bd1(33);
903
904 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -0700905 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
906 bridge_domain::learning_mode_t::ON,
907 bridge_domain::arp_term_mode_t::ON,
908 bridge_domain::flood_mode_t::ON,
909 bridge_domain::mac_age_mode_t::OFF));
Neale Ranns812ed392017-10-16 04:20:13 -0700910
911 TRY_CHECK_RC(OM::write(franz, bd1));
912
913 // L2-interface create and bind
914 // this needs to be delete'd before the flush below, since it too maintains
915 // references to the BD and Interface
916 l2_binding *l2itf = new l2_binding(itf1, bd1);
917 HW::item<bool> hw_l2_bind(true, rc_t::OK);
918
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700919 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
Neale Ranns812ed392017-10-16 04:20:13 -0700920 TRY_CHECK_RC(OM::write(franz, *l2itf));
921
922 /*
923 * Dante adds an interface to the same BD
924 */
925 std::string itf2_name = "afpacket2";
926 interface itf2(itf2_name,
927 interface::type_t::AFPACKET,
928 interface::admin_state_t::UP);
929
930 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700931 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
932 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700933 TRY_CHECK_RC(OM::write(dante, itf2));
934
935 // BD add is a no-op since it exists
936 TRY_CHECK_RC(OM::write(dante, bd1));
937
938 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
939 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
940 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
941
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700942 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
943 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
Neale Ranns812ed392017-10-16 04:20:13 -0700944 TRY_CHECK_RC(OM::write(dante, *l2itf2));
945
946 // Add some static entries to the bridge-domain
947 HW::item<bool> hw_be1(true, rc_t::OK);
948 mac_address_t mac1({0,1,2,3,4,5});
949 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100950 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
951 false));
Neale Ranns812ed392017-10-16 04:20:13 -0700952 TRY_CHECK_RC(OM::write(dante, *be1));
953
954 // Add some entries to the bridge-domain ARP termination table
955 HW::item<bool> hw_bea1(true, rc_t::OK);
956 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
957
Neale Rannsfd920602017-11-23 12:15:00 -0800958 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700959 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
Neale Ranns812ed392017-10-16 04:20:13 -0700960 TRY_CHECK_RC(OM::write(dante, *bea1));
961
962 // flush Franz's state
963 delete l2itf;
964 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
965 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700966 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
967 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
968 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700969 TRY_CHECK(OM::remove(franz));
970
971 // flush Dante's state - the order the interface and BD are deleted
972 // is an uncontrollable artifact of the C++ object destruction.
973 delete l2itf2;
974 delete be1;
975 delete bea1;
976 STRICT_ORDER_OFF();
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100977 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
978 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700979 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100980
981 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700982 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
983 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700984 TRY_CHECK(OM::remove(dante));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100985
986 // test the BVI entry in l2fib
987 bridge_domain bd2(99);
988
989 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -0700990 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
991 bridge_domain::learning_mode_t::ON,
992 bridge_domain::arp_term_mode_t::ON,
993 bridge_domain::flood_mode_t::ON,
994 bridge_domain::mac_age_mode_t::OFF));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100995
996 TRY_CHECK_RC(OM::write(jkr, bd2));
997
998 std::string itf3_name = "bvi";
999 interface itf3(itf3_name,
1000 interface::type_t::BVI,
1001 interface::admin_state_t::UP);
1002
1003 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1004 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1005 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1006 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1007 TRY_CHECK_RC(OM::write(jkr, itf3));
1008
1009 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1010 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1011 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1012
1013 HW::item<bool> hw_be2(true, rc_t::OK);
1014 mac_address_t mac2({0,1,2,3,4,5});
1015 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1016 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1017 TRY_CHECK_RC(OM::write(jkr, *be2));
1018
1019 delete l2itf3;
1020 delete be2;
1021 STRICT_ORDER_OFF();
1022 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1023 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1024 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1025 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1026 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1027 TRY_CHECK(OM::remove(jkr));
Neale Ranns812ed392017-10-16 04:20:13 -07001028}
1029
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +02001030BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1031 VppInit vi;
1032 const std::string nicholas = "NicholasAbercrombie";
1033 rc_t rc = rc_t::OK;
1034
1035 /*
1036 * Interface 1
1037 */
1038 std::string itf1_name = "host1";
1039 interface itf1(itf1_name,
1040 interface::type_t::AFPACKET,
1041 interface::admin_state_t::UP);
1042 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1043 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1044 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1045 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1046 TRY_CHECK_RC(OM::write(nicholas, itf1));
1047
1048 /*
1049 * Interface 2
1050 */
1051 std::string itf2_name = "host2";
1052 interface itf2(itf2_name,
1053 interface::type_t::AFPACKET,
1054 interface::admin_state_t::UP);
1055
1056 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1057 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1058 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1059 TRY_CHECK_RC(OM::write(nicholas, itf2));
1060
1061 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1062 HW::item<bool> xconnect_east(true, rc_t::OK);
1063 HW::item<bool> xconnect_west(true, rc_t::OK);
1064 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1065 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1066 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1067 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1068 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1069
1070 delete l2_xconn;
1071
1072 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1073 STRICT_ORDER_OFF();
1074 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1075 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1076 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1077 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1078 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1079 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1080
1081 TRY_CHECK(OM::remove(nicholas));
1082}
1083
Neale Ranns812ed392017-10-16 04:20:13 -07001084BOOST_AUTO_TEST_CASE(test_vxlan) {
1085 VppInit vi;
1086 const std::string franz = "FranzKafka";
1087 rc_t rc = rc_t::OK;
1088
1089 /*
1090 * Franz creates an interface, Bridge-domain, then binds the two
1091 */
1092
1093 // VXLAN create
1094 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
Neale Ranns25b04942018-04-04 09:34:50 -07001095 boost::asio::ip::address::from_string("10.10.10.11"),
1096 322);
Neale Ranns812ed392017-10-16 04:20:13 -07001097
1098 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1099
1100 HW::item<handle_t> hw_vxt(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001101 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001102
1103 TRY_CHECK_RC(OM::write(franz, vxt));
1104
1105 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001106 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1107 bridge_domain::arp_term_mode_t::OFF,
1108 bridge_domain::flood_mode_t::OFF,
1109 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001110
1111 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001112 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1113 bridge_domain::learning_mode_t::OFF,
1114 bridge_domain::arp_term_mode_t::OFF,
1115 bridge_domain::flood_mode_t::OFF,
1116 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001117
1118 TRY_CHECK_RC(OM::write(franz, bd1));
1119
1120 // L2-interface create and bind
1121 // this needs to be delete'd before the flush below, since it too maintains
1122 // references to the BD and Interface
1123 l2_binding *l2itf = new l2_binding(vxt, bd1);
1124 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1125
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001126 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
Neale Ranns812ed392017-10-16 04:20:13 -07001127 TRY_CHECK_RC(OM::write(franz, *l2itf));
1128
1129 // flush Franz's state
1130 delete l2itf;
1131 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1132 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001133 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1134 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1135 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001136 TRY_CHECK(OM::remove(franz));
1137}
1138
1139BOOST_AUTO_TEST_CASE(test_vlan) {
1140 VppInit vi;
1141 const std::string noam = "NoamChomsky";
1142 rc_t rc = rc_t::OK;
1143
1144 std::string itf1_name = "host1";
1145 interface itf1(itf1_name,
1146 interface::type_t::AFPACKET,
1147 interface::admin_state_t::UP);
1148
1149 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001150 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001151
1152 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001153 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001154
1155 TRY_CHECK_RC(OM::write(noam, itf1));
1156
1157 sub_interface *vl33 = new sub_interface(itf1,
1158 interface::admin_state_t::UP,
1159 33);
1160
1161 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001162 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1163 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001164
1165 TRY_CHECK_RC(OM::write(noam, *vl33));
1166
1167 delete vl33;
1168 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1169 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001170 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1171 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1172 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1173 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001174
1175 TRY_CHECK(OM::remove(noam));
1176}
1177
1178BOOST_AUTO_TEST_CASE(test_acl) {
1179 VppInit vi;
1180 const std::string fyodor = "FyodorDostoyevsky";
1181 const std::string leo = "LeoTolstoy";
1182 rc_t rc = rc_t::OK;
1183
1184 /*
1185 * Fyodor adds an ACL in the input direction
1186 */
1187 std::string itf1_name = "host1";
1188 interface itf1(itf1_name,
1189 interface::type_t::AFPACKET,
1190 interface::admin_state_t::UP);
1191 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1192 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001193 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1194 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001195 TRY_CHECK_RC(OM::write(fyodor, itf1));
1196
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001197 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1198 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1199 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1200 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1201 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1202 HW::item<bool> ae_binding(true, rc_t::OK);
1203 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1204 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1205
Neale Ranns812ed392017-10-16 04:20:13 -07001206 route::prefix_t src("10.10.10.10", 32);
1207 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1208 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1209
1210 std::string acl_name = "acl1";
1211 ACL::l3_list acl1(acl_name);
1212 acl1.insert(r2);
1213 acl1.insert(r1);
1214 ACL::l3_list::rules_t rules = {r1, r2};
1215
1216 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001217 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001218 TRY_CHECK_RC(OM::write(fyodor, acl1));
1219
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001220 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1221 ACL::l3_list acl2(acl_name);
1222 acl2.insert(r3);
1223 ACL::l3_list::rules_t rules2 = {r3};
1224 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1225 TRY_CHECK_RC(OM::write(fyodor, acl2));
1226
Neale Ranns812ed392017-10-16 04:20:13 -07001227 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1228 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001229 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1230 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001231 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1232
1233 /**
1234 * Leo adds an L2 ACL in the output direction
1235 */
1236 TRY_CHECK_RC(OM::write(leo, itf1));
1237
1238 std::string l2_acl_name = "l2_acl1";
1239 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1240 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1241 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1242 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1243
1244 ACL::l2_list l2_acl(l2_acl_name);
1245 l2_acl.insert(l2_r2);
1246 l2_acl.insert(l2_r1);
1247
1248 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1249
1250 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001251 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001252 TRY_CHECK_RC(OM::write(leo, l2_acl));
1253
1254 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1255 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001256 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001257 hw_ifh.data(), l2_hw_acl.data()));
1258 TRY_CHECK_RC(OM::write(leo, *l2b));
1259
1260 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001261 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1262 hw_ifh.data(), l2_hw_acl.data()));
1263 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001264 TRY_CHECK(OM::remove(leo));
1265
1266 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001267 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001268 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1269 rc_t::OK);
1270 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001271 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001272 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001273 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001274 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001275 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1276 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001277
1278 TRY_CHECK(OM::remove(fyodor));
1279}
1280
1281BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1282 VppInit vi;
1283 const std::string kurt = "KurtVonnegut";
1284 rc_t rc = rc_t::OK;
1285
1286 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1287 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1288
1289 arp_proxy_config ap(low, high);
1290 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001291 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001292 TRY_CHECK_RC(OM::write(kurt, ap));
1293
1294 std::string itf3_name = "host3";
1295 interface itf3(itf3_name,
1296 interface::type_t::AFPACKET,
1297 interface::admin_state_t::UP);
1298 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1299 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001300 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1301 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001302 TRY_CHECK_RC(OM::write(kurt, itf3));
1303
Neale Ranns0053de62018-05-22 08:40:52 -07001304 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001305 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001306 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001307 TRY_CHECK_RC(OM::write(kurt, *apb));
1308
1309 delete apb;
1310
1311 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1312 rc_t::OK);
1313 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001314 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1315 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1316 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1317 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001318
1319 TRY_CHECK(OM::remove(kurt));
1320}
1321
1322BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1323 VppInit vi;
1324 const std::string eric = "EricAmbler";
1325 rc_t rc = rc_t::OK;
1326
1327 /*
1328 * Interface 1 has the L3 address
1329 */
1330 std::string itf1_name = "host1";
1331 interface itf1(itf1_name,
1332 interface::type_t::AFPACKET,
1333 interface::admin_state_t::UP);
1334 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1335 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001336 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1337 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001338 TRY_CHECK_RC(OM::write(eric, itf1));
1339
1340 route::prefix_t pfx_10("10.10.10.10", 24);
1341 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1342 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1343 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001344 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001345 TRY_CHECK_RC(OM::write(eric, *l3));
1346
1347 /*
1348 * Interface 2 is unnumbered
1349 */
1350 std::string itf2_name = "host2";
1351 interface itf2(itf2_name,
1352 interface::type_t::AFPACKET,
1353 interface::admin_state_t::UP);
1354
1355 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001356 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1357 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001358 TRY_CHECK_RC(OM::write(eric, itf2));
1359
1360 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1361 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1362 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001363 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001364 TRY_CHECK_RC(OM::write(eric, *ipun));
1365
1366 delete l3;
1367 delete ipun;
1368
1369 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1370 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001371 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1372 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1373 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1374 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1375 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1376 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001377
1378 TRY_CHECK(OM::remove(eric));
1379}
1380
1381BOOST_AUTO_TEST_CASE(test_ip6nd) {
1382 VppInit vi;
1383 const std::string paulo = "PauloCoelho";
1384 rc_t rc = rc_t::OK;
1385
1386 /*
1387 * ra config
1388 */
1389 std::string itf_name = "host_ip6nd";
1390 interface itf(itf_name,
1391 interface::type_t::AFPACKET,
1392 interface::admin_state_t::UP);
1393 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1394 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001395 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1396 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001397 TRY_CHECK_RC(OM::write(paulo, itf));
1398
1399 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1400 l3_binding *l3 = new l3_binding(itf, pfx_10);
1401 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1402 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001403 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001404 TRY_CHECK_RC(OM::write(paulo, *l3));
1405
1406 ra_config ra(0, 1, 0, 4);
1407 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1408 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1409 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1410 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1411 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1412
1413 /*
1414 * ra prefix
1415 */
1416 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1417 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1418 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1419 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1420 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1421 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1422
1423 delete ip6pfx;
1424
1425 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1426
1427 delete ip6ra;
1428 delete l3;
1429
1430 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1431
1432 STRICT_ORDER_OFF();
1433 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001434 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1435 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1436 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001437
1438 TRY_CHECK(OM::remove(paulo));
1439}
1440
1441BOOST_AUTO_TEST_CASE(test_interface_span) {
1442 VppInit vi;
1443 const std::string elif = "ElifShafak";
1444 rc_t rc = rc_t::OK;
1445
1446 /*
1447 * Interface 1 to be mirrored
1448 */
1449 std::string itf1_name = "port-from";
1450 interface itf1(itf1_name,
1451 interface::type_t::AFPACKET,
1452 interface::admin_state_t::UP);
1453 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1454 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001455 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1456 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001457 TRY_CHECK_RC(OM::write(elif, itf1));
1458
1459 /*
1460 * Interface 2 where traffic is mirrored
1461 */
1462 std::string itf2_name = "port-to";
1463 interface itf2(itf2_name,
1464 interface::type_t::AFPACKET,
1465 interface::admin_state_t::UP);
1466
1467 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1468 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1469
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001470 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1471 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001472 TRY_CHECK_RC(OM::write(elif, itf2));
1473
1474 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1475 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1476 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001477 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 -07001478 TRY_CHECK_RC(OM::write(elif, *itf_span));
1479
1480 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1481 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1482
1483 delete itf_span;
1484 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001485 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1486 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1487 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1488 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1489 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001490
1491 TRY_CHECK(OM::remove(elif));
1492}
1493
1494BOOST_AUTO_TEST_CASE(test_routing) {
1495 VppInit vi;
1496 const std::string ian = "IanFleming";
1497 rc_t rc = rc_t::OK;
1498
1499 /*
1500 * non-default route domain
1501 */
1502 route_domain rd4(1);
1503 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1504 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1505 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1506 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1507 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1508 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1509 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1510 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001511 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1512 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001513 TRY_CHECK_RC(OM::write(ian, rd4));
1514
1515 /*
1516 * a couple of interfaces
1517 */
1518 std::string itf1_name = "af1";
1519 interface itf1(itf1_name,
1520 interface::type_t::AFPACKET,
1521 interface::admin_state_t::UP);
1522 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1523 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1524 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001525 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1526 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001527 TRY_CHECK_RC(OM::write(ian, itf1));
1528
1529 std::string itf2_name = "af2";
1530 interface *itf2 = new interface(itf2_name,
1531 interface::type_t::AFPACKET,
1532 interface::admin_state_t::UP,
1533 rd4);
1534
1535 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1536 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1537 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001538 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1539 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1540 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1541 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001542 TRY_CHECK_RC(OM::write(ian, *itf2));
1543
1544 /*
1545 * prefix on each interface
1546 */
1547 route::prefix_t pfx_10("10.10.10.10", 24);
1548 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1549 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1550 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001551 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001552 TRY_CHECK_RC(OM::write(ian, *l3_10));
1553 route::prefix_t pfx_11("11.11.11.11", 24);
1554 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1555 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1556 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001557 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001558 TRY_CHECK_RC(OM::write(ian, *l3_11));
1559
1560 /*
1561 * A route via interface 1 in the default table
1562 */
1563 route::prefix_t pfx_5("5.5.5.5", 32);
1564 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1565 route::path *path_10 = new route::path(nh_10, itf1);
1566 route::ip_route *route_5 = new route::ip_route(pfx_5);
1567 route_5->add(*path_10);
1568 HW::item<bool> hw_route_5(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001569 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
Neale Ranns812ed392017-10-16 04:20:13 -07001570 TRY_CHECK_RC(OM::write(ian, *route_5));
1571
1572 /*
1573 * A route via interface 2 in the non-default table
1574 */
1575 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1576 route::path *path_11 = new route::path(nh_11, *itf2);
1577 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1578 route_5_2->add(*path_11);
1579 HW::item<bool> hw_route_5_2(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001580 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
Neale Ranns812ed392017-10-16 04:20:13 -07001581 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1582
1583 /*
1584 * An ARP entry for the neighbour on itf1
1585 */
1586 HW::item<bool> hw_neighbour(true, rc_t::OK);
1587 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001588 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001589 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001590 TRY_CHECK_RC(OM::write(ian, *ne));
1591
1592 /*
1593 * A DVR route
1594 */
1595 route::prefix_t pfx_6("6.6.6.6", 32);
1596 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1597 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1598 route_dvr->add(*path_l2);
1599 HW::item<bool> hw_route_dvr(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001600 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
Neale Ranns812ed392017-10-16 04:20:13 -07001601 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1602
1603 STRICT_ORDER_OFF();
1604 // delete the stack objects that hold references to others
1605 // so the OM::remove is the call that removes the last reference
1606 delete l3_11;
1607 delete l3_10;
1608 delete itf2;
1609 delete route_5;
1610 delete path_10;
1611 delete route_5_2;
1612 delete path_11;
1613 delete route_dvr;
1614 delete path_l2;
1615 delete ne;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001616 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1617 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1618 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1619 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1620 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1621 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1622 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1623 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1624 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1625 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1626 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1627 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1628 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1629 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001630
1631 TRY_CHECK(OM::remove(ian));
1632}
1633
1634BOOST_AUTO_TEST_CASE(test_nat) {
1635 VppInit vi;
1636 const std::string gs = "GeorgeSimenon";
1637 rc_t rc = rc_t::OK;
1638
1639 /*
1640 * Inside Interface
1641 */
1642 std::string itf_in_name = "inside";
1643 interface itf_in(itf_in_name,
1644 interface::type_t::AFPACKET,
1645 interface::admin_state_t::UP);
1646 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1647 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1648 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001649 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1650 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001651 TRY_CHECK_RC(OM::write(gs, itf_in));
1652
1653 /*
1654 * outside
1655 */
1656 std::string itf_out_name = "port-to";
1657 interface itf_out(itf_out_name,
1658 interface::type_t::AFPACKET,
1659 interface::admin_state_t::UP);
1660
1661 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1662 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1663 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1664
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001665 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1666 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001667 TRY_CHECK_RC(OM::write(gs, itf_out));
1668
1669 /*
1670 * A NAT static mapping
1671 */
1672 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1673 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1674
1675 nat_static ns(in_addr, out_addr);
1676 HW::item<bool> hw_ns(true, rc_t::OK);
1677
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001678 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001679 TRY_CHECK_RC(OM::write(gs, ns));
1680
1681 /*
1682 * bind nat inside and out
1683 */
1684 nat_binding *nb_in = new nat_binding(itf_in,
1685 direction_t::INPUT,
1686 l3_proto_t::IPV4,
1687 nat_binding::zone_t::INSIDE);
1688 HW::item<bool> hw_nb_in(true, rc_t::OK);
1689
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001690 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1691 hw_ifh.data().value(),
1692 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001693 TRY_CHECK_RC(OM::write(gs, *nb_in));
1694
1695 nat_binding *nb_out = new nat_binding(itf_out,
1696 direction_t::INPUT,
1697 l3_proto_t::IPV4,
1698 nat_binding::zone_t::OUTSIDE);
1699 HW::item<bool> hw_nb_out(true, rc_t::OK);
1700
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001701 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1702 hw_ifh2.data().value(),
1703 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001704 TRY_CHECK_RC(OM::write(gs, *nb_out));
1705
1706
1707 STRICT_ORDER_OFF();
1708 delete nb_in;
1709 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001710 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1711 hw_ifh.data().value(),
1712 nat_binding::zone_t::INSIDE));
1713 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1714 hw_ifh2.data().value(),
1715 nat_binding::zone_t::OUTSIDE));
1716 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1717 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1718 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1719 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1720 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001721
1722 TRY_CHECK(OM::remove(gs));
1723}
1724
1725BOOST_AUTO_TEST_CASE(test_interface_events) {
1726 VppInit vi;
1727 MockListener ml;
1728
1729 HW::item<bool> hw_want(true, rc_t::OK);
1730
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001731 ADD_EXPECT(interface_cmds::events_cmd(ml));
1732 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07001733
1734 HW::enqueue(itf);
1735 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07001736}
1737
Neale Ranns352ea0c2017-11-14 11:04:28 -08001738BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1739 VppInit vi;
1740 const std::string rene = "ReneGoscinny";
1741 rc_t rc = rc_t::OK;
1742
1743 /*
1744 * Create an interface with two IP addresses
1745 */
1746 std::string itf1_name = "host1";
1747 interface itf1(itf1_name,
1748 interface::type_t::AFPACKET,
1749 interface::admin_state_t::UP);
1750 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1751 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1752 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1753 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1754 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1755 TRY_CHECK_RC(OM::write(rene, itf1));
1756
1757 route::prefix_t pfx_10("10.10.10.10", 24);
1758 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1759 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1760 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1761 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1762 TRY_CHECK_RC(OM::write(rene, *l3_1));
1763
1764 route::prefix_t pfx_11("10.10.11.11", 24);
1765 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1766 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1767 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1768 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1769 TRY_CHECK_RC(OM::write(rene, *l3_2));
1770
1771 route_domain rd(1);
1772 HW::item<bool> hw_rd_create(true, rc_t::OK);
1773 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1774 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1775 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1776 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1777 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1778 TRY_CHECK_RC(OM::write(rene, rd));
1779
1780 /*
1781 * update the interface to change to a new route-domain
1782 * expect that the l3-bindings are removed and readded.
1783 */
1784 interface *itf2 = new interface(itf1_name,
1785 interface::type_t::AFPACKET,
1786 interface::admin_state_t::UP,
1787 rd);
1788 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1789 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1790 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1791 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1792 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1793 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1794 TRY_CHECK_RC(OM::write(rene, *itf2));
1795
1796 /*
1797 * mve the interface back to the default route-domain
1798 */
1799 interface itf3(itf1_name,
1800 interface::type_t::AFPACKET,
1801 interface::admin_state_t::UP);
1802 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1803 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1804 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1805 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1806 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1807 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1808 TRY_CHECK_RC(OM::write(rene, itf3));
1809
1810 delete l3_1;
1811 delete l3_2;
1812 delete itf2;
1813
1814 STRICT_ORDER_OFF();
1815 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1816 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1817 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1818 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1819 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1820 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1821
1822 TRY_CHECK(OM::remove(rene));
1823}
1824
Neale Rannsd3464b52017-12-07 08:48:02 -08001825BOOST_AUTO_TEST_CASE(test_prefixes) {
1826 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1827
1828 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1829
1830 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1831
1832 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1833 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1834
1835 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1836 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1837 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1838
1839 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1840
1841 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1842
1843 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1844
1845 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1846 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1847 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1848
1849 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1850
1851 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1852 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1853 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1854
1855 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1856
1857 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1858 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1859 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1860
1861}
1862
Neale Ranns812ed392017-10-16 04:20:13 -07001863BOOST_AUTO_TEST_SUITE_END()