blob: f17d749f3f3aefa8abb23be57380774eaedcb288 [file] [log] [blame]
Neale Ranns812ed392017-10-16 04:20:13 -07001/*
2 * Test suite for class VppOM
3 *
4 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
5 *
6 * This program and the accompanying materials are made available under the
7 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 */
10#define BOOST_TEST_MODULE "VPP OBJECT MODEL"
11#define BOOST_TEST_DYN_LINK
12
13#include <boost/test/unit_test.hpp>
14#include <boost/assign/list_inserter.hpp>
15
16
17#include <iostream>
18#include <deque>
19
20#include "vom/om.hpp"
21#include "vom/interface.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070022#include "vom/interface_cmds.hpp"
Mohsin Kazmied76ee22018-03-02 12:31:37 +010023#include "vom/bond_interface_cmds.hpp"
24#include "vom/bond_group_binding.hpp"
25#include "vom/bond_group_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070026#include "vom/l2_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070027#include "vom/l2_binding_cmds.hpp"
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +020028#include "vom/l2_xconnect.hpp"
29#include "vom/l2_xconnect_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070030#include "vom/l3_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070031#include "vom/l3_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070032#include "vom/bridge_domain.hpp"
33#include "vom/bridge_domain_entry.hpp"
34#include "vom/bridge_domain_arp_entry.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070035#include "vom/bridge_domain_cmds.hpp"
36#include "vom/bridge_domain_entry_cmds.hpp"
37#include "vom/bridge_domain_arp_entry_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070038#include "vom/prefix.hpp"
39#include "vom/route.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070040#include "vom/route_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070041#include "vom/route_domain.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070042#include "vom/route_domain_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070043#include "vom/vxlan_tunnel.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070044#include "vom/vxlan_tunnel_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070045#include "vom/sub_interface.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070046#include "vom/sub_interface_cmds.hpp"
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +010047#include "vom/acl_ethertype.hpp"
48#include "vom/acl_ethertype_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070049#include "vom/acl_list.hpp"
50#include "vom/acl_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070051#include "vom/acl_list_cmds.hpp"
52#include "vom/acl_binding_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070053#include "vom/acl_l3_rule.hpp"
54#include "vom/acl_l2_rule.hpp"
55#include "vom/arp_proxy_config.hpp"
56#include "vom/arp_proxy_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070057#include "vom/arp_proxy_config_cmds.hpp"
58#include "vom/arp_proxy_binding_cmds.hpp"
Mohsin Kazmi12fe8782018-10-30 19:24:34 +010059#include "vom/igmp_binding.hpp"
60#include "vom/igmp_binding_cmds.hpp"
61#include "vom/igmp_listen.hpp"
62#include "vom/igmp_listen_cmds.hpp"
Mohsin Kazmie23edac2018-09-25 18:26:52 +020063#include "vom/ip_punt_redirect.hpp"
64#include "vom/ip_punt_redirect_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070065#include "vom/ip_unnumbered.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070066#include "vom/ip_unnumbered_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070067#include "vom/interface_ip6_nd.hpp"
68#include "vom/interface_span.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070069#include "vom/interface_span_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070070#include "vom/neighbour.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070071#include "vom/neighbour_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070072#include "vom/nat_static.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070073#include "vom/nat_static_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070074#include "vom/nat_binding.hpp"
Neale Ranns9ef1c0a2017-11-03 04:39:05 -070075#include "vom/nat_binding_cmds.hpp"
Neale Ranns208c29a2018-04-11 08:08:30 -070076#include "vom/pipe.hpp"
77#include "vom/pipe_cmds.hpp"
Neale Ranns812ed392017-10-16 04:20:13 -070078
79using namespace boost;
80using namespace VOM;
81
82/**
83 * An expectation exception
84 */
85class ExpException
86{
87public:
88 ExpException(unsigned int number)
89 {
90 // a neat place to add a break point
91 std::cout << " ExpException here: " << number << std::endl;
92 }
93};
94
95class MockListener : public interface::event_listener,
96 public interface::stat_listener
97{
Neale Rannsa2ee0292017-11-28 22:29:13 -080098 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
Neale Ranns812ed392017-10-16 04:20:13 -070099 {
100 }
Neale Ranns193c47d2018-12-10 06:01:46 -0800101 void handle_interface_event(std::vector<VOM::interface::event> events)
Neale Ranns812ed392017-10-16 04:20:13 -0700102 {
103 }
104};
105
106class MockCmdQ : public HW::cmd_q
107{
108public:
109 MockCmdQ():
110 m_strict_order(true)
111 {
112 }
113 virtual ~MockCmdQ()
114 {
115 }
116 void expect(cmd *f)
117 {
118 m_exp_queue.push_back(f);
119 }
120 void enqueue(cmd *f)
121 {
122 m_act_queue.push_back(f);
123 }
124 void enqueue(std::queue<cmd*> &cmds)
125 {
126 while (cmds.size())
127 {
128 m_act_queue.push_back(cmds.front());
129 cmds.pop();
130 }
131 }
132 void enqueue(std::shared_ptr<cmd> f)
133 {
134 m_act_queue.push_back(f.get());
135 }
136
137 void dequeue(cmd *f)
138 {
139 }
140
141 void dequeue(std::shared_ptr<cmd> cmd)
142 {
143 }
144
145 void strict_order(bool on)
146 {
147 m_strict_order = on;
148 }
149
150 bool is_empty()
151 {
152 return ((0 == m_exp_queue.size()) &&
153 (0 == m_act_queue.size()));
154 }
155
156 rc_t write()
157 {
158 cmd *f_exp, *f_act;
159 rc_t rc = rc_t::OK;
160
161 while (m_act_queue.size())
162 {
163 bool matched = false;
164 auto it_exp = m_exp_queue.begin();
165 auto it_act = m_act_queue.begin();
166
167 f_act = *it_act;
168
169 std::cout << " Act: " << f_act->to_string() << std::endl;
170 while (it_exp != m_exp_queue.end())
171 {
172 f_exp = *it_exp;
173 try
174 {
175 std::cout << " Exp: " << f_exp->to_string() << std::endl;
176
177 if (typeid(*f_exp) != typeid(*f_act))
178 {
179 throw ExpException(1);
180 }
181
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700182 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700183 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700184 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700185 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700186 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700187 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700188 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700189 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800190 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
191 {
192 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
193 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100194 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
195 {
196 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
197 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700198 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700199 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700200 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700201 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700202 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700203 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700204 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700205 }
Neale Ranns4ef42262018-02-20 08:10:44 -0800206 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
207 {
208 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
209 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100210 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
211 {
212 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
213 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700214 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700215 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700216 rc = handle_derived<interface_cmds::state_change_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_table_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700219 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700220 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700221 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700222 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700223 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700224 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700225 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700226 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
Neale Ranns812ed392017-10-16 04:20:13 -0700227 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700228 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700229 }
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100230 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
231 {
232 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
233 }
234 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
235 {
236 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
237 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700238 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700239 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700240 rc = handle_derived<route_domain_cmds::create_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_domain_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700243 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700244 rc = handle_derived<route_domain_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(route::ip_route_cmds::update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700247 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700248 rc = handle_derived<route::ip_route_cmds::update_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(route::ip_route_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700251 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700252 rc = handle_derived<route::ip_route_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(neighbour_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700255 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700256 rc = handle_derived<neighbour_cmds::create_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(neighbour_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700259 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700260 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700261 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700262 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700263 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700264 rc = handle_derived<l3_binding_cmds::bind_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(l3_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700267 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700268 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700269 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700270 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700271 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700272 rc = handle_derived<bridge_domain_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_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700275 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700276 rc = handle_derived<bridge_domain_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_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_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_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_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(bridge_domain_arp_entry_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700287 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700288 rc = handle_derived<bridge_domain_arp_entry_cmds::create_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(bridge_domain_arp_entry_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700291 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700292 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_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::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700295 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700296 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700297 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700298 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700299 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700300 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700301 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700302 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700303 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700304 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700305 }
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +0200306 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
307 {
308 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
309 }
310 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
311 {
312 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
313 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700314 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700315 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700316 rc = handle_derived<vxlan_tunnel_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(vxlan_tunnel_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700319 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700320 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700321 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700322 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700323 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700324 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700325 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700326 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700327 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700328 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700329 }
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +0100330 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
331 {
332 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
333 }
Mohsin Kazmi04def742018-03-07 19:53:51 +0100334 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
335 {
336 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
337 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700338 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700339 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700340 rc = handle_derived<ACL::list_cmds::l3_update_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::list_cmds::l3_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700343 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700344 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700345 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700346 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700347 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700348 rc = handle_derived<ACL::binding_cmds::l3_bind_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::binding_cmds::l3_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700351 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700352 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700353 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700354 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700355 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700356 rc = handle_derived<ACL::list_cmds::l2_update_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::list_cmds::l2_delete_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700359 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700360 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700361 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700362 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700363 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700364 rc = handle_derived<ACL::binding_cmds::l2_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(ACL::binding_cmds::l2_unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700367 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700368 rc = handle_derived<ACL::binding_cmds::l2_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_binding_cmds::bind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700371 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700372 rc = handle_derived<arp_proxy_binding_cmds::bind_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_binding_cmds::unbind_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700375 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700376 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700377 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700378 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700379 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700380 rc = handle_derived<arp_proxy_config_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(arp_proxy_config_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700383 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700384 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700385 }
Mohsin Kazmi12fe8782018-10-30 19:24:34 +0100386 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
387 {
388 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
389 }
390 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
391 {
392 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
393 }
394 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
395 {
396 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
397 }
398 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
399 {
400 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
401 }
Mohsin Kazmie23edac2018-09-25 18:26:52 +0200402 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
403 {
404 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
405 }
406 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
407 {
408 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
409 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700410 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700411 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700412 rc = handle_derived<ip_unnumbered_cmds::config_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(ip_unnumbered_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700415 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700416 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700417 }
418 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
419 {
420 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
421 }
422 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
423 {
424 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
425 }
426 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
427 {
428 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
429 }
430 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
431 {
432 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
433 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700434 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700435 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700436 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700437 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700438 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700439 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700440 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700441 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700442 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700443 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700444 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700445 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700446 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700447 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700448 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700449 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700450 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700451 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700452 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700453 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700454 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700455 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700456 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700457 }
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700458 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
Neale Ranns812ed392017-10-16 04:20:13 -0700459 {
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700460 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
Neale Ranns812ed392017-10-16 04:20:13 -0700461 }
Neale Ranns208c29a2018-04-11 08:08:30 -0700462 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
463 {
464 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
465 }
466 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
467 {
468 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
469 }
Neale Ranns812ed392017-10-16 04:20:13 -0700470 else
471 {
472 throw ExpException(2);
473 }
474
475 // if we get here then we found the match.
476 m_exp_queue.erase(it_exp);
477 m_act_queue.erase(it_act);
478 delete f_exp;
479 delete f_act;
480
481 // return any injected failures to the agent
482 if (rc_t::OK != rc && rc_t::NOOP != rc)
483 {
484 return (rc);
485 }
486
487 matched = true;
488 break;
489 }
490 catch (ExpException &e)
491 {
492 // The expected and actual do not match
493 if (m_strict_order)
494 {
495 // in strict ordering mode this is fatal, so rethrow
496 throw e;
497 }
498 else
499 {
500 // move the iterator onto the next in the expected list and
501 // check for a match
502 ++it_exp;
503 }
504 }
505 }
506
507 if (!matched)
508 throw ExpException(3);
509 }
510
511 return (rc);
512 }
513private:
514
515 template <typename T>
516 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
517 {
518 const T *i_exp;
519 T *i_act;
520
521 i_exp = dynamic_cast<const T*>(f_exp);
522 i_act = dynamic_cast<T*>(f_act);
523 if (!(*i_exp == *i_act))
524 {
525 throw ExpException(4);
526 }
527 // pass the data and return code to the agent
528 i_act->item() = i_exp->item();
529
530 return (i_act->item().rc());
531 }
532
533 // The Q to push the expectations on
534 std::deque<cmd*> m_exp_queue;
535
536 // the queue to push the actual events on
537 std::deque<cmd*> m_act_queue;
538
539 // control whether the expected queue is strictly ordered.
540 bool m_strict_order;
541};
542
543class VppInit {
544public:
545 std::string name;
546 MockCmdQ *f;
547
548 VppInit()
549 : name("vpp-ut"),
550 f(new MockCmdQ())
551 {
552 HW::init(f);
553 OM::init();
554 logger().set(log_level_t::DEBUG);
555 }
556
557 ~VppInit() {
558 delete f;
559 }
560};
561
Neale Rannsd3464b52017-12-07 08:48:02 -0800562BOOST_AUTO_TEST_SUITE(vom)
Neale Ranns812ed392017-10-16 04:20:13 -0700563
564#define TRY_CHECK_RC(stmt) \
565{ \
566 try { \
567 BOOST_CHECK(rc_t::OK == stmt); \
568 } \
569 catch (ExpException &e) \
570 { \
571 BOOST_CHECK(false); \
572 } \
573 BOOST_CHECK(vi.f->is_empty()); \
574}
575
576#define TRY_CHECK(stmt) \
577{ \
578 try { \
579 stmt; \
580 } \
581 catch (ExpException &e) \
582 { \
583 BOOST_CHECK(false); \
584 } \
585 BOOST_CHECK(vi.f->is_empty()); \
586}
587
588#define ADD_EXPECT(stmt) \
589 vi.f->expect(new stmt)
590
591#define STRICT_ORDER_OFF() \
592 vi.f->strict_order(false)
593
594BOOST_AUTO_TEST_CASE(test_interface) {
595 VppInit vi;
596 const std::string go = "GeorgeOrwell";
597 const std::string js = "JohnSteinbeck";
598 rc_t rc = rc_t::OK;
599
600 /*
601 * George creates and deletes the interface
602 */
603 std::string itf1_name = "afpacket1";
604 interface itf1(itf1_name,
605 interface::type_t::AFPACKET,
606 interface::admin_state_t::UP);
607
608 /*
609 * set the expectation for a afpacket interface create.
610 * 2 is the interface handle VPP [mock] assigns
611 */
612 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700613 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700614
615 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700616 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700617
618 TRY_CHECK_RC(OM::write(go, itf1));
619
620 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700621 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
622 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700623
624 TRY_CHECK(OM::remove(go));
625
626 /*
627 * George creates the interface, then John brings it down.
628 * George's remove is a no-op, sice John also owns the interface
629 */
630 interface itf1b(itf1_name,
631 interface::type_t::AFPACKET,
632 interface::admin_state_t::DOWN);
633
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700634 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
635 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700636 TRY_CHECK_RC(OM::write(go, itf1));
637
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700638 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700639 TRY_CHECK_RC(OM::write(js, itf1b));
640
641 TRY_CHECK(OM::remove(go));
642
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700643 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700644 TRY_CHECK(OM::remove(js));
645
646 /*
647 * George adds an interface, then we flush all of Geroge's state
648 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700649 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
650 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700651 TRY_CHECK_RC(OM::write(go, itf1));
652
653 TRY_CHECK(OM::mark(go));
654
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700655 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
656 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700657 TRY_CHECK(OM::sweep(go));
658
659 /*
660 * George adds an interface. mark stale. update the same interface. sweep
661 * and expect no delete
662 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700663 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
664 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700665 TRY_CHECK_RC(OM::write(go, itf1b));
666
667 TRY_CHECK(OM::mark(go));
668
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700669 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700670 TRY_CHECK_RC(OM::write(go, itf1));
671
672 TRY_CHECK(OM::sweep(go));
673
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700674 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
675 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700676 TRY_CHECK(OM::remove(go));
677
678 /*
679 * George adds an insterface, then we mark that state. Add a second interface
680 * an flush the first that is now stale.
681 */
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700682 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
683 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700684 TRY_CHECK_RC(OM::write(go, itf1));
685
686 TRY_CHECK(OM::mark(go));
687
688 std::string itf2_name = "afpacket2";
Neale Ranns4ef42262018-02-20 08:10:44 -0800689 std::string itf2_tag = "uuid-of-afpacket2-interface";
Neale Ranns812ed392017-10-16 04:20:13 -0700690 interface itf2(itf2_name,
691 interface::type_t::AFPACKET,
Neale Ranns4ef42262018-02-20 08:10:44 -0800692 interface::admin_state_t::UP,
693 itf2_tag);
Neale Ranns812ed392017-10-16 04:20:13 -0700694 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
695
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700696 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
Neale Ranns4ef42262018-02-20 08:10:44 -0800697 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700698 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700699 TRY_CHECK_RC(OM::write(go, itf2));
700
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700701 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
702 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700703 TRY_CHECK(OM::sweep(go));
704
705 TRY_CHECK(OM::mark(go));
706
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700707 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
708 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -0700709 TRY_CHECK(OM::sweep(go));
Neale Ranns4ef42262018-02-20 08:10:44 -0800710
711
712 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
713 std::string itf3_tag = "uuid-of-vhost_user1-interface";
714 interface itf3(itf3_name,
715 interface::type_t::VHOST,
716 interface::admin_state_t::UP,
717 itf3_tag);
718 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
719
720 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
721 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
722 TRY_CHECK_RC(OM::write(go, itf3));
723
724 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
725 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
726 TRY_CHECK(OM::remove(go));
Neale Ranns812ed392017-10-16 04:20:13 -0700727}
728
729BOOST_AUTO_TEST_CASE(test_bvi) {
730 VppInit vi;
731 const std::string ernest = "ErnestHemmingway";
732 const std::string graham = "GrahamGreene";
733 rc_t rc = rc_t::OK;
734 l3_binding *l3;
735
736 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
737 rc_t::OK);
738 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
739 rc_t::OK);
740
741 /*
742 * Enrest creates a BVI with address 10.10.10.10/24
743 */
744 route::prefix_t pfx_10("10.10.10.10", 24);
745
746 const std::string bvi_name = "bvi1";
747 interface itf(bvi_name,
748 interface::type_t::BVI,
749 interface::admin_state_t::UP);
750 HW::item<handle_t> hw_ifh(4, rc_t::OK);
751 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
752
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700753 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
754 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
755 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700756 TRY_CHECK_RC(OM::write(ernest, itf));
757
758 l3 = new l3_binding(itf, pfx_10);
759 HW::item<bool> hw_l3_bind(true, rc_t::OK);
760 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700761 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700762 TRY_CHECK_RC(OM::write(ernest, *l3));
763
764 // change the MAC address on the BVI
765 interface itf_new_mac(bvi_name,
766 interface::type_t::BVI,
767 interface::admin_state_t::UP);
768 l2_address_t l2_addr({0,1,2,3,4,5});
769 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
770 itf_new_mac.set(l2_addr);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700771 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700772 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
773
774 // create/write the interface to the OM again but with an unset MAC
775 // this should not generate a MAC address update
776 TRY_CHECK_RC(OM::write(ernest, itf));
777
778 // change the MAC address on the BVI - again
779 interface itf_new_mac2(bvi_name,
780 interface::type_t::BVI,
781 interface::admin_state_t::UP);
782 l2_address_t l2_addr2({0,1,2,3,4,6});
783 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
784 itf_new_mac2.set(l2_addr2);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700785 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700786 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
787
788 delete l3;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700789 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
790 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
791 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700792 TRY_CHECK(OM::remove(ernest));
793
794 /*
795 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
796 */
797 route_domain rd(1);
798 HW::item<bool> hw_rd4_create(true, rc_t::OK);
799 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
800 HW::item<bool> hw_rd6_create(true, rc_t::OK);
801 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
802 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
803 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
804 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
805 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700806 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
807 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700808 TRY_CHECK_RC(OM::write(graham, rd));
809
810 const std::string bvi2_name = "bvi2";
811 interface *itf2 = new interface(bvi2_name,
812 interface::type_t::BVI,
813 interface::admin_state_t::UP,
814 rd);
815 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
816
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700817 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
818 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
819 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
820 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
821 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700822
823 TRY_CHECK_RC(OM::write(graham, *itf2));
824
825 l3 = new l3_binding(*itf2, pfx_10);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700826 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -0700827 TRY_CHECK_RC(OM::write(graham, *l3));
828
829 delete l3;
830 delete itf2;
831
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700832 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
833 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
834 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
835 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
836 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
837 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
838 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -0700839 TRY_CHECK(OM::remove(graham));
840}
841
Mohsin Kazmied76ee22018-03-02 12:31:37 +0100842BOOST_AUTO_TEST_CASE(test_bond) {
843 VppInit vi;
844 const std::string cb = "CarolBerg";
845 rc_t rc = rc_t::OK;
846
847 /*
848 * creates the interfaces
849 */
850 std::string itf1_name = "afpacket1";
851 interface itf1(itf1_name,
852 interface::type_t::AFPACKET,
853 interface::admin_state_t::UP);
854
855 HW::item<handle_t> hw_ifh(2, rc_t::OK);
856 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
857
858 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
859 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
860
861 TRY_CHECK_RC(OM::write(cb, itf1));
862
863 std::string itf2_name = "afpacket2";
864 interface itf2(itf2_name,
865 interface::type_t::AFPACKET,
866 interface::admin_state_t::UP);
867
868
869 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
870 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
871 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
872
873 TRY_CHECK_RC(OM::write(cb, itf2));
874
875 std::string bond_name = "bond";
876 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
877 bond_interface::mode_t::LACP);
878
879 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
880 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
881 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
882 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
883
884 TRY_CHECK_RC(OM::write(cb, bond_itf));
885
886 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
887 bond_member::rate_t::SLOW);
888 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
889 bond_member::rate_t::SLOW);
890 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
891
892 HW::item<bool> bond_hw_bind(true, rc_t::OK);
893 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
894 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
895
896 TRY_CHECK_RC(OM::write(cb, *bgb));
897
898 delete bgb;
899 delete bm2;
900 delete bm1;
901
902 STRICT_ORDER_OFF();
903 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
904 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
905 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
906 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
907 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
908 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
909 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
910 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
911 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
912
913 TRY_CHECK(OM::remove(cb));
914}
915
Neale Ranns812ed392017-10-16 04:20:13 -0700916BOOST_AUTO_TEST_CASE(test_bridge) {
917 VppInit vi;
918 const std::string franz = "FranzKafka";
919 const std::string dante = "Dante";
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100920 const std::string jkr = "jkrowling";
Neale Ranns812ed392017-10-16 04:20:13 -0700921 rc_t rc = rc_t::OK;
922
923 /*
924 * Franz creates an interface, Bridge-domain, then binds the two
925 */
926
927 // interface create
928 std::string itf1_name = "afpacket1";
929 interface itf1(itf1_name,
930 interface::type_t::AFPACKET,
931 interface::admin_state_t::UP);
932
933 HW::item<handle_t> hw_ifh(3, rc_t::OK);
934 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
935 rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700936 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
937 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -0700938
939 TRY_CHECK_RC(OM::write(franz, itf1));
940
941 // bridge-domain create
942 bridge_domain bd1(33);
943
944 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -0700945 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
946 bridge_domain::learning_mode_t::ON,
947 bridge_domain::arp_term_mode_t::ON,
948 bridge_domain::flood_mode_t::ON,
949 bridge_domain::mac_age_mode_t::OFF));
Neale Ranns812ed392017-10-16 04:20:13 -0700950
951 TRY_CHECK_RC(OM::write(franz, bd1));
952
953 // L2-interface create and bind
954 // this needs to be delete'd before the flush below, since it too maintains
955 // references to the BD and Interface
956 l2_binding *l2itf = new l2_binding(itf1, bd1);
957 HW::item<bool> hw_l2_bind(true, rc_t::OK);
958
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200959 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
960 hw_ifh.data(),
961 hw_bd.data(),
962 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -0700963 TRY_CHECK_RC(OM::write(franz, *l2itf));
964
965 /*
966 * Dante adds an interface to the same BD
967 */
968 std::string itf2_name = "afpacket2";
969 interface itf2(itf2_name,
970 interface::type_t::AFPACKET,
971 interface::admin_state_t::UP);
972
973 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700974 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
975 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -0700976 TRY_CHECK_RC(OM::write(dante, itf2));
977
978 // BD add is a no-op since it exists
979 TRY_CHECK_RC(OM::write(dante, bd1));
980
981 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
982 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
983 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
984
Mohsin Kazmi762d83c2018-09-27 15:00:32 +0200985 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
986 hw_ifh2.data(),
987 hw_bd.data(),
988 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -0700989 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
Neale Ranns812ed392017-10-16 04:20:13 -0700990 TRY_CHECK_RC(OM::write(dante, *l2itf2));
991
992 // Add some static entries to the bridge-domain
993 HW::item<bool> hw_be1(true, rc_t::OK);
994 mac_address_t mac1({0,1,2,3,4,5});
995 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +0100996 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
997 false));
Neale Ranns812ed392017-10-16 04:20:13 -0700998 TRY_CHECK_RC(OM::write(dante, *be1));
999
1000 // Add some entries to the bridge-domain ARP termination table
1001 HW::item<bool> hw_bea1(true, rc_t::OK);
1002 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1003
Neale Rannsfd920602017-11-23 12:15:00 -08001004 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001005 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
Neale Ranns812ed392017-10-16 04:20:13 -07001006 TRY_CHECK_RC(OM::write(dante, *bea1));
1007
1008 // flush Franz's state
1009 delete l2itf;
1010 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1011 rc_t::OK);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001012 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1013 hw_ifh.data(),
1014 hw_bd.data(),
1015 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001016 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1017 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001018 TRY_CHECK(OM::remove(franz));
1019
1020 // flush Dante's state - the order the interface and BD are deleted
1021 // is an uncontrollable artifact of the C++ object destruction.
1022 delete l2itf2;
1023 delete be1;
1024 delete bea1;
1025 STRICT_ORDER_OFF();
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001026 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1027 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001028 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1029 hw_ifh2.data(),
1030 hw_bd.data(),
1031 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001032
1033 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001034 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1035 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001036 TRY_CHECK(OM::remove(dante));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001037
1038 // test the BVI entry in l2fib
1039 bridge_domain bd2(99);
1040
1041 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001042 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1043 bridge_domain::learning_mode_t::ON,
1044 bridge_domain::arp_term_mode_t::ON,
1045 bridge_domain::flood_mode_t::ON,
1046 bridge_domain::mac_age_mode_t::OFF));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001047
1048 TRY_CHECK_RC(OM::write(jkr, bd2));
1049
1050 std::string itf3_name = "bvi";
1051 interface itf3(itf3_name,
1052 interface::type_t::BVI,
1053 interface::admin_state_t::UP);
1054
1055 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1056 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1057 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1058 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1059 TRY_CHECK_RC(OM::write(jkr, itf3));
1060
1061 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001062 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1063 hw_ifh3.data(),
1064 hw_bd2.data(),
1065 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001066 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1067
1068 HW::item<bool> hw_be2(true, rc_t::OK);
1069 mac_address_t mac2({0,1,2,3,4,5});
1070 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1071 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1072 TRY_CHECK_RC(OM::write(jkr, *be2));
1073
1074 delete l2itf3;
1075 delete be2;
1076 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001077 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1078 hw_ifh3.data(),
1079 hw_bd2.data(),
1080 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
Mohsin Kazmie2e9ce52017-12-01 15:12:57 +01001081 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1082 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1083 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1084 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1085 TRY_CHECK(OM::remove(jkr));
Neale Ranns812ed392017-10-16 04:20:13 -07001086}
1087
Mohsin Kazmi6b1cdd32018-06-29 17:04:23 +02001088BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1089 VppInit vi;
1090 const std::string nicholas = "NicholasAbercrombie";
1091 rc_t rc = rc_t::OK;
1092
1093 /*
1094 * Interface 1
1095 */
1096 std::string itf1_name = "host1";
1097 interface itf1(itf1_name,
1098 interface::type_t::AFPACKET,
1099 interface::admin_state_t::UP);
1100 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1101 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1102 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1103 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1104 TRY_CHECK_RC(OM::write(nicholas, itf1));
1105
1106 /*
1107 * Interface 2
1108 */
1109 std::string itf2_name = "host2";
1110 interface itf2(itf2_name,
1111 interface::type_t::AFPACKET,
1112 interface::admin_state_t::UP);
1113
1114 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1115 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1116 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1117 TRY_CHECK_RC(OM::write(nicholas, itf2));
1118
1119 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1120 HW::item<bool> xconnect_east(true, rc_t::OK);
1121 HW::item<bool> xconnect_west(true, rc_t::OK);
1122 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1123 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1124 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1125 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1126 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1127
1128 delete l2_xconn;
1129
1130 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1131 STRICT_ORDER_OFF();
1132 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1133 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1134 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1135 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1136 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1137 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1138
1139 TRY_CHECK(OM::remove(nicholas));
1140}
1141
Neale Ranns812ed392017-10-16 04:20:13 -07001142BOOST_AUTO_TEST_CASE(test_vxlan) {
1143 VppInit vi;
1144 const std::string franz = "FranzKafka";
1145 rc_t rc = rc_t::OK;
1146
1147 /*
1148 * Franz creates an interface, Bridge-domain, then binds the two
1149 */
1150
1151 // VXLAN create
1152 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
Neale Ranns25b04942018-04-04 09:34:50 -07001153 boost::asio::ip::address::from_string("10.10.10.11"),
1154 322);
Neale Ranns812ed392017-10-16 04:20:13 -07001155
1156 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1157
1158 HW::item<handle_t> hw_vxt(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001159 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001160
1161 TRY_CHECK_RC(OM::write(franz, vxt));
1162
1163 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001164 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1165 bridge_domain::arp_term_mode_t::OFF,
1166 bridge_domain::flood_mode_t::OFF,
1167 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001168
1169 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001170 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1171 bridge_domain::learning_mode_t::OFF,
1172 bridge_domain::arp_term_mode_t::OFF,
1173 bridge_domain::flood_mode_t::OFF,
1174 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001175
1176 TRY_CHECK_RC(OM::write(franz, bd1));
1177
1178 // L2-interface create and bind
1179 // this needs to be delete'd before the flush below, since it too maintains
1180 // references to the BD and Interface
1181 l2_binding *l2itf = new l2_binding(vxt, bd1);
1182 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1183
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001184 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1185 hw_vxt.data(),
1186 hw_bd.data(),
1187 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -07001188 TRY_CHECK_RC(OM::write(franz, *l2itf));
1189
1190 // flush Franz's state
1191 delete l2itf;
1192 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1193 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001194 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1195 hw_vxt.data(),
1196 hw_bd.data(),
1197 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001198 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1199 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001200 TRY_CHECK(OM::remove(franz));
1201}
1202
1203BOOST_AUTO_TEST_CASE(test_vlan) {
1204 VppInit vi;
1205 const std::string noam = "NoamChomsky";
1206 rc_t rc = rc_t::OK;
1207
1208 std::string itf1_name = "host1";
1209 interface itf1(itf1_name,
1210 interface::type_t::AFPACKET,
1211 interface::admin_state_t::UP);
1212
1213 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001214 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001215
1216 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001217 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001218
1219 TRY_CHECK_RC(OM::write(noam, itf1));
1220
1221 sub_interface *vl33 = new sub_interface(itf1,
1222 interface::admin_state_t::UP,
1223 33);
1224
1225 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001226 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1227 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001228
1229 TRY_CHECK_RC(OM::write(noam, *vl33));
1230
1231 delete vl33;
1232 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1233 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001234 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1235 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1236 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1237 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001238
1239 TRY_CHECK(OM::remove(noam));
1240}
1241
1242BOOST_AUTO_TEST_CASE(test_acl) {
1243 VppInit vi;
1244 const std::string fyodor = "FyodorDostoyevsky";
1245 const std::string leo = "LeoTolstoy";
1246 rc_t rc = rc_t::OK;
1247
1248 /*
1249 * Fyodor adds an ACL in the input direction
1250 */
1251 std::string itf1_name = "host1";
1252 interface itf1(itf1_name,
1253 interface::type_t::AFPACKET,
1254 interface::admin_state_t::UP);
1255 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1256 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001257 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1258 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001259 TRY_CHECK_RC(OM::write(fyodor, itf1));
1260
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001261 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1262 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1263 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1264 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1265 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1266 HW::item<bool> ae_binding(true, rc_t::OK);
1267 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1268 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1269
Neale Ranns812ed392017-10-16 04:20:13 -07001270 route::prefix_t src("10.10.10.10", 32);
1271 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1272 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1273
1274 std::string acl_name = "acl1";
1275 ACL::l3_list acl1(acl_name);
1276 acl1.insert(r2);
1277 acl1.insert(r1);
1278 ACL::l3_list::rules_t rules = {r1, r2};
1279
1280 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001281 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001282 TRY_CHECK_RC(OM::write(fyodor, acl1));
1283
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001284 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1285 ACL::l3_list acl2(acl_name);
1286 acl2.insert(r3);
1287 ACL::l3_list::rules_t rules2 = {r3};
1288 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1289 TRY_CHECK_RC(OM::write(fyodor, acl2));
1290
Neale Ranns812ed392017-10-16 04:20:13 -07001291 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1292 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001293 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1294 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001295 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1296
1297 /**
1298 * Leo adds an L2 ACL in the output direction
1299 */
1300 TRY_CHECK_RC(OM::write(leo, itf1));
1301
1302 std::string l2_acl_name = "l2_acl1";
1303 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1304 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1305 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1306 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1307
1308 ACL::l2_list l2_acl(l2_acl_name);
1309 l2_acl.insert(l2_r2);
1310 l2_acl.insert(l2_r1);
1311
1312 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1313
1314 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001315 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001316 TRY_CHECK_RC(OM::write(leo, l2_acl));
1317
1318 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1319 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001320 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001321 hw_ifh.data(), l2_hw_acl.data()));
1322 TRY_CHECK_RC(OM::write(leo, *l2b));
1323
1324 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001325 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1326 hw_ifh.data(), l2_hw_acl.data()));
1327 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001328 TRY_CHECK(OM::remove(leo));
1329
1330 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001331 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001332 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1333 rc_t::OK);
1334 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001335 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001336 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001337 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001338 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001339 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1340 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001341
1342 TRY_CHECK(OM::remove(fyodor));
1343}
1344
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001345BOOST_AUTO_TEST_CASE(test_igmp) {
1346 VppInit vi;
1347 const std::string Isaiah = "IsaiahBerlin";
1348 rc_t rc = rc_t::OK;
1349
1350 boost::asio::ip::address gaddr = boost::asio::ip::address::from_string("232.0.0.1");
1351 boost::asio::ip::address saddr1 = boost::asio::ip::address::from_string("192.168.0.20");
1352 boost::asio::ip::address saddr2 = boost::asio::ip::address::from_string("192.168.0.30");
1353
1354 std::string itf3_name = "host3";
1355 interface itf3(itf3_name,
1356 interface::type_t::AFPACKET,
1357 interface::admin_state_t::UP);
1358 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1359 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1360 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1361 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1362 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1363
1364 igmp_binding *ib = new igmp_binding(itf3);
1365 HW::item<bool> hw_binding(true, rc_t::OK);
1366 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1367 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1368
1369 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1370
1371 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1372 HW::item<bool> hw_as_listen(true, rc_t::OK);
1373 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1374 TRY_CHECK_RC(OM::write(Isaiah, *il));
1375
1376 delete il;
1377 delete ib;
1378
1379 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1380 rc_t::OK);
1381 STRICT_ORDER_OFF();
1382 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1383 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1384 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1385 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1386
1387 TRY_CHECK(OM::remove(Isaiah));
1388}
1389
Neale Ranns812ed392017-10-16 04:20:13 -07001390BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1391 VppInit vi;
1392 const std::string kurt = "KurtVonnegut";
1393 rc_t rc = rc_t::OK;
1394
1395 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1396 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1397
1398 arp_proxy_config ap(low, high);
1399 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001400 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001401 TRY_CHECK_RC(OM::write(kurt, ap));
1402
1403 std::string itf3_name = "host3";
1404 interface itf3(itf3_name,
1405 interface::type_t::AFPACKET,
1406 interface::admin_state_t::UP);
1407 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1408 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001409 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1410 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001411 TRY_CHECK_RC(OM::write(kurt, itf3));
1412
Neale Ranns0053de62018-05-22 08:40:52 -07001413 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001414 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001415 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001416 TRY_CHECK_RC(OM::write(kurt, *apb));
1417
1418 delete apb;
1419
1420 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1421 rc_t::OK);
1422 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001423 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1424 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1425 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1426 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001427
1428 TRY_CHECK(OM::remove(kurt));
1429}
1430
Mohsin Kazmie23edac2018-09-25 18:26:52 +02001431BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1432 VppInit vi;
1433 const std::string eliot = "EliotReed";
1434 rc_t rc = rc_t::OK;
1435
1436 /*
1437 * Interface 1 is the tx interface
1438 */
1439 std::string itf1_name = "tx-itf";
1440 interface itf1(itf1_name,
1441 interface::type_t::AFPACKET,
1442 interface::admin_state_t::UP);
1443 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1444 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1445 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1446 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1447 TRY_CHECK_RC(OM::write(eliot, itf1));
1448
1449 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1450
1451 /*
1452 * Interface 2 is the rx interface
1453 */
1454 std::string itf2_name = "rx-itf";
1455 interface itf2(itf2_name,
1456 interface::type_t::AFPACKET,
1457 interface::admin_state_t::UP);
1458
1459 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1460 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1461 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1462 TRY_CHECK_RC(OM::write(eliot, itf2));
1463
1464 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1465 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1466 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1467 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1468 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1469
1470 delete ip_punt;
1471
1472 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1473 STRICT_ORDER_OFF();
1474 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1475 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1476 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1477 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1478 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1479
1480 TRY_CHECK(OM::remove(eliot));
1481}
1482
Neale Ranns812ed392017-10-16 04:20:13 -07001483BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1484 VppInit vi;
1485 const std::string eric = "EricAmbler";
1486 rc_t rc = rc_t::OK;
1487
1488 /*
1489 * Interface 1 has the L3 address
1490 */
1491 std::string itf1_name = "host1";
1492 interface itf1(itf1_name,
1493 interface::type_t::AFPACKET,
1494 interface::admin_state_t::UP);
1495 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1496 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001497 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1498 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001499 TRY_CHECK_RC(OM::write(eric, itf1));
1500
1501 route::prefix_t pfx_10("10.10.10.10", 24);
1502 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1503 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1504 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001505 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001506 TRY_CHECK_RC(OM::write(eric, *l3));
1507
1508 /*
1509 * Interface 2 is unnumbered
1510 */
1511 std::string itf2_name = "host2";
1512 interface itf2(itf2_name,
1513 interface::type_t::AFPACKET,
1514 interface::admin_state_t::UP);
1515
1516 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001517 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1518 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001519 TRY_CHECK_RC(OM::write(eric, itf2));
1520
1521 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1522 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1523 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001524 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001525 TRY_CHECK_RC(OM::write(eric, *ipun));
1526
1527 delete l3;
1528 delete ipun;
1529
1530 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1531 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001532 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1533 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1534 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1535 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1536 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1537 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001538
1539 TRY_CHECK(OM::remove(eric));
1540}
1541
1542BOOST_AUTO_TEST_CASE(test_ip6nd) {
1543 VppInit vi;
1544 const std::string paulo = "PauloCoelho";
1545 rc_t rc = rc_t::OK;
1546
1547 /*
1548 * ra config
1549 */
1550 std::string itf_name = "host_ip6nd";
1551 interface itf(itf_name,
1552 interface::type_t::AFPACKET,
1553 interface::admin_state_t::UP);
1554 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1555 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001556 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1557 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001558 TRY_CHECK_RC(OM::write(paulo, itf));
1559
1560 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1561 l3_binding *l3 = new l3_binding(itf, pfx_10);
1562 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1563 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001564 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001565 TRY_CHECK_RC(OM::write(paulo, *l3));
1566
1567 ra_config ra(0, 1, 0, 4);
1568 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1569 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1570 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1571 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1572 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1573
1574 /*
1575 * ra prefix
1576 */
1577 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1578 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1579 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1580 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1581 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1582 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1583
1584 delete ip6pfx;
1585
1586 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1587
1588 delete ip6ra;
1589 delete l3;
1590
1591 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1592
1593 STRICT_ORDER_OFF();
1594 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001595 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1596 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1597 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001598
1599 TRY_CHECK(OM::remove(paulo));
1600}
1601
1602BOOST_AUTO_TEST_CASE(test_interface_span) {
1603 VppInit vi;
1604 const std::string elif = "ElifShafak";
1605 rc_t rc = rc_t::OK;
1606
1607 /*
1608 * Interface 1 to be mirrored
1609 */
1610 std::string itf1_name = "port-from";
1611 interface itf1(itf1_name,
1612 interface::type_t::AFPACKET,
1613 interface::admin_state_t::UP);
1614 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1615 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001616 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1617 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001618 TRY_CHECK_RC(OM::write(elif, itf1));
1619
1620 /*
1621 * Interface 2 where traffic is mirrored
1622 */
1623 std::string itf2_name = "port-to";
1624 interface itf2(itf2_name,
1625 interface::type_t::AFPACKET,
1626 interface::admin_state_t::UP);
1627
1628 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1629 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1630
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001631 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1632 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001633 TRY_CHECK_RC(OM::write(elif, itf2));
1634
1635 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1636 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1637 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001638 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 -07001639 TRY_CHECK_RC(OM::write(elif, *itf_span));
1640
1641 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1642 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1643
1644 delete itf_span;
1645 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001646 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1647 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1648 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1649 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1650 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001651
1652 TRY_CHECK(OM::remove(elif));
1653}
1654
1655BOOST_AUTO_TEST_CASE(test_routing) {
1656 VppInit vi;
1657 const std::string ian = "IanFleming";
1658 rc_t rc = rc_t::OK;
1659
1660 /*
1661 * non-default route domain
1662 */
1663 route_domain rd4(1);
1664 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1665 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1666 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1667 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1668 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1669 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1670 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1671 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001672 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1673 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001674 TRY_CHECK_RC(OM::write(ian, rd4));
1675
1676 /*
1677 * a couple of interfaces
1678 */
1679 std::string itf1_name = "af1";
1680 interface itf1(itf1_name,
1681 interface::type_t::AFPACKET,
1682 interface::admin_state_t::UP);
1683 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1684 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1685 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001686 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1687 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001688 TRY_CHECK_RC(OM::write(ian, itf1));
1689
1690 std::string itf2_name = "af2";
1691 interface *itf2 = new interface(itf2_name,
1692 interface::type_t::AFPACKET,
1693 interface::admin_state_t::UP,
1694 rd4);
1695
1696 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1697 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1698 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001699 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1700 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1701 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1702 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001703 TRY_CHECK_RC(OM::write(ian, *itf2));
1704
1705 /*
1706 * prefix on each interface
1707 */
1708 route::prefix_t pfx_10("10.10.10.10", 24);
1709 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1710 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1711 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001712 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001713 TRY_CHECK_RC(OM::write(ian, *l3_10));
1714 route::prefix_t pfx_11("11.11.11.11", 24);
1715 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1716 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1717 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001718 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001719 TRY_CHECK_RC(OM::write(ian, *l3_11));
1720
1721 /*
1722 * A route via interface 1 in the default table
1723 */
1724 route::prefix_t pfx_5("5.5.5.5", 32);
1725 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1726 route::path *path_10 = new route::path(nh_10, itf1);
1727 route::ip_route *route_5 = new route::ip_route(pfx_5);
1728 route_5->add(*path_10);
1729 HW::item<bool> hw_route_5(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001730 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
Neale Ranns812ed392017-10-16 04:20:13 -07001731 TRY_CHECK_RC(OM::write(ian, *route_5));
1732
1733 /*
1734 * A route via interface 2 in the non-default table
1735 */
1736 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1737 route::path *path_11 = new route::path(nh_11, *itf2);
1738 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1739 route_5_2->add(*path_11);
1740 HW::item<bool> hw_route_5_2(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001741 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
Neale Ranns812ed392017-10-16 04:20:13 -07001742 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1743
1744 /*
1745 * An ARP entry for the neighbour on itf1
1746 */
1747 HW::item<bool> hw_neighbour(true, rc_t::OK);
1748 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001749 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001750 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001751 TRY_CHECK_RC(OM::write(ian, *ne));
1752
1753 /*
1754 * A DVR route
1755 */
1756 route::prefix_t pfx_6("6.6.6.6", 32);
1757 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1758 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1759 route_dvr->add(*path_l2);
1760 HW::item<bool> hw_route_dvr(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001761 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
Neale Ranns812ed392017-10-16 04:20:13 -07001762 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1763
1764 STRICT_ORDER_OFF();
1765 // delete the stack objects that hold references to others
1766 // so the OM::remove is the call that removes the last reference
1767 delete l3_11;
1768 delete l3_10;
1769 delete itf2;
1770 delete route_5;
1771 delete path_10;
1772 delete route_5_2;
1773 delete path_11;
1774 delete route_dvr;
1775 delete path_l2;
1776 delete ne;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001777 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1778 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1779 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1780 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1781 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1782 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1783 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1784 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1785 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1786 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1787 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1788 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1789 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1790 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001791
1792 TRY_CHECK(OM::remove(ian));
1793}
1794
1795BOOST_AUTO_TEST_CASE(test_nat) {
1796 VppInit vi;
1797 const std::string gs = "GeorgeSimenon";
1798 rc_t rc = rc_t::OK;
1799
1800 /*
1801 * Inside Interface
1802 */
1803 std::string itf_in_name = "inside";
1804 interface itf_in(itf_in_name,
1805 interface::type_t::AFPACKET,
1806 interface::admin_state_t::UP);
1807 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1808 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1809 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001810 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1811 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001812 TRY_CHECK_RC(OM::write(gs, itf_in));
1813
1814 /*
1815 * outside
1816 */
1817 std::string itf_out_name = "port-to";
1818 interface itf_out(itf_out_name,
1819 interface::type_t::AFPACKET,
1820 interface::admin_state_t::UP);
1821
1822 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1823 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1824 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1825
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001826 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1827 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001828 TRY_CHECK_RC(OM::write(gs, itf_out));
1829
1830 /*
1831 * A NAT static mapping
1832 */
1833 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1834 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1835
1836 nat_static ns(in_addr, out_addr);
1837 HW::item<bool> hw_ns(true, rc_t::OK);
1838
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001839 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001840 TRY_CHECK_RC(OM::write(gs, ns));
1841
1842 /*
1843 * bind nat inside and out
1844 */
1845 nat_binding *nb_in = new nat_binding(itf_in,
1846 direction_t::INPUT,
1847 l3_proto_t::IPV4,
1848 nat_binding::zone_t::INSIDE);
1849 HW::item<bool> hw_nb_in(true, rc_t::OK);
1850
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001851 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1852 hw_ifh.data().value(),
1853 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001854 TRY_CHECK_RC(OM::write(gs, *nb_in));
1855
1856 nat_binding *nb_out = new nat_binding(itf_out,
1857 direction_t::INPUT,
1858 l3_proto_t::IPV4,
1859 nat_binding::zone_t::OUTSIDE);
1860 HW::item<bool> hw_nb_out(true, rc_t::OK);
1861
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001862 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1863 hw_ifh2.data().value(),
1864 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001865 TRY_CHECK_RC(OM::write(gs, *nb_out));
1866
1867
1868 STRICT_ORDER_OFF();
1869 delete nb_in;
1870 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001871 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1872 hw_ifh.data().value(),
1873 nat_binding::zone_t::INSIDE));
1874 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1875 hw_ifh2.data().value(),
1876 nat_binding::zone_t::OUTSIDE));
1877 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1879 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1880 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1881 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001882
1883 TRY_CHECK(OM::remove(gs));
1884}
1885
1886BOOST_AUTO_TEST_CASE(test_interface_events) {
1887 VppInit vi;
1888 MockListener ml;
1889
1890 HW::item<bool> hw_want(true, rc_t::OK);
1891
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001892 ADD_EXPECT(interface_cmds::events_cmd(ml));
1893 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07001894
1895 HW::enqueue(itf);
1896 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07001897}
1898
Neale Ranns352ea0c2017-11-14 11:04:28 -08001899BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1900 VppInit vi;
1901 const std::string rene = "ReneGoscinny";
1902 rc_t rc = rc_t::OK;
1903
1904 /*
1905 * Create an interface with two IP addresses
1906 */
1907 std::string itf1_name = "host1";
1908 interface itf1(itf1_name,
1909 interface::type_t::AFPACKET,
1910 interface::admin_state_t::UP);
1911 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1912 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1913 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1914 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1915 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1916 TRY_CHECK_RC(OM::write(rene, itf1));
1917
1918 route::prefix_t pfx_10("10.10.10.10", 24);
1919 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1920 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1921 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1922 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1923 TRY_CHECK_RC(OM::write(rene, *l3_1));
1924
1925 route::prefix_t pfx_11("10.10.11.11", 24);
1926 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1927 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1928 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1929 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1930 TRY_CHECK_RC(OM::write(rene, *l3_2));
1931
1932 route_domain rd(1);
1933 HW::item<bool> hw_rd_create(true, rc_t::OK);
1934 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1935 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1936 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1937 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1938 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1939 TRY_CHECK_RC(OM::write(rene, rd));
1940
1941 /*
1942 * update the interface to change to a new route-domain
1943 * expect that the l3-bindings are removed and readded.
1944 */
1945 interface *itf2 = new interface(itf1_name,
1946 interface::type_t::AFPACKET,
1947 interface::admin_state_t::UP,
1948 rd);
1949 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1950 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1951 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1952 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1953 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1954 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1955 TRY_CHECK_RC(OM::write(rene, *itf2));
1956
1957 /*
1958 * mve the interface back to the default route-domain
1959 */
1960 interface itf3(itf1_name,
1961 interface::type_t::AFPACKET,
1962 interface::admin_state_t::UP);
1963 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1964 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1965 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1966 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1967 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1968 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1969 TRY_CHECK_RC(OM::write(rene, itf3));
1970
1971 delete l3_1;
1972 delete l3_2;
1973 delete itf2;
1974
1975 STRICT_ORDER_OFF();
1976 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1977 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1978 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1979 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1980 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1981 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1982
1983 TRY_CHECK(OM::remove(rene));
1984}
1985
Neale Rannsd3464b52017-12-07 08:48:02 -08001986BOOST_AUTO_TEST_CASE(test_prefixes) {
1987 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1988
1989 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1990
1991 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1992
1993 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1994 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1995
1996 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1997 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1998 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1999
2000 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2001
2002 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2003
2004 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2005
2006 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2007 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2008 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2009
2010 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2011
2012 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2013 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2014 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2015
2016 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2017
2018 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2019 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2020 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2021
2022}
2023
Neale Ranns208c29a2018-04-11 08:08:30 -07002024BOOST_AUTO_TEST_CASE(test_pipes) {
2025 VppInit vi;
2026 const std::string gk = "GKChesterton";
2027
2028 const std::string pipe_name_1 = "pipe1";
2029 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2030 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2031 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2032
2033 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2034 rc_t::OK);
2035 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2036 rc_t::OK);
2037 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2038 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2039 TRY_CHECK_RC(OM::write(gk, pipe1));
2040
2041 pipe1.set_ends(hw_hdl_pair.data());
2042
2043 // put each end of the pipe in a BD
2044 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2045 bridge_domain::arp_term_mode_t::OFF,
2046 bridge_domain::flood_mode_t::OFF,
2047 bridge_domain::mac_age_mode_t::ON);
2048
2049 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2050 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2051 bridge_domain::learning_mode_t::OFF,
2052 bridge_domain::arp_term_mode_t::OFF,
2053 bridge_domain::flood_mode_t::OFF,
2054 bridge_domain::mac_age_mode_t::ON));
2055
2056 TRY_CHECK_RC(OM::write(gk, bd1));
2057
2058 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2059 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2060
2061 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2062 pipe1.east()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002063 hw_bd.data(),
2064 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002065 TRY_CHECK_RC(OM::write(gk, *l2_1));
2066
2067 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2068 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2069
2070 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2071 pipe1.west()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002072 hw_bd.data(),
2073 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002074 TRY_CHECK_RC(OM::write(gk, *l2_2));
2075
2076 STRICT_ORDER_OFF();
2077
2078 delete l2_1;
2079 delete l2_2;
2080 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2081 pipe1.east()->handle(),
2082 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002083 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002084 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2085 pipe1.west()->handle(),
2086 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002087 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002088 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2089 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2090 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2091 TRY_CHECK(OM::remove(gk));
2092}
2093
Neale Ranns812ed392017-10-16 04:20:13 -07002094BOOST_AUTO_TEST_SUITE_END()