blob: 6aacea9803baa097f91b2693b153d5fe09859628 [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{
Mohsin Kazmi51edc3a2018-11-21 19:00:46 +010098 void handle_interface_stat(const interface& itf)
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 Rannscf3ecb12018-12-11 08:40:20 -08001159 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1160 handle_t::INVALID));
Neale Ranns812ed392017-10-16 04:20:13 -07001161
1162 TRY_CHECK_RC(OM::write(franz, vxt));
1163
1164 // bridge-domain create
Neale Ranns25b04942018-04-04 09:34:50 -07001165 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1166 bridge_domain::arp_term_mode_t::OFF,
1167 bridge_domain::flood_mode_t::OFF,
1168 bridge_domain::mac_age_mode_t::ON);
Neale Ranns812ed392017-10-16 04:20:13 -07001169
1170 HW::item<uint32_t> hw_bd(33, rc_t::OK);
Neale Ranns25b04942018-04-04 09:34:50 -07001171 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1172 bridge_domain::learning_mode_t::OFF,
1173 bridge_domain::arp_term_mode_t::OFF,
1174 bridge_domain::flood_mode_t::OFF,
1175 bridge_domain::mac_age_mode_t::ON));
Neale Ranns812ed392017-10-16 04:20:13 -07001176
1177 TRY_CHECK_RC(OM::write(franz, bd1));
1178
1179 // L2-interface create and bind
1180 // this needs to be delete'd before the flush below, since it too maintains
1181 // references to the BD and Interface
1182 l2_binding *l2itf = new l2_binding(vxt, bd1);
1183 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1184
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001185 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1186 hw_vxt.data(),
1187 hw_bd.data(),
1188 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns812ed392017-10-16 04:20:13 -07001189 TRY_CHECK_RC(OM::write(franz, *l2itf));
1190
1191 // flush Franz's state
1192 delete l2itf;
1193 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1194 STRICT_ORDER_OFF();
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001195 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1196 hw_vxt.data(),
1197 hw_bd.data(),
1198 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001199 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1200 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
Neale Ranns812ed392017-10-16 04:20:13 -07001201 TRY_CHECK(OM::remove(franz));
1202}
1203
1204BOOST_AUTO_TEST_CASE(test_vlan) {
1205 VppInit vi;
1206 const std::string noam = "NoamChomsky";
1207 rc_t rc = rc_t::OK;
1208
1209 std::string itf1_name = "host1";
1210 interface itf1(itf1_name,
1211 interface::type_t::AFPACKET,
1212 interface::admin_state_t::UP);
1213
1214 HW::item<handle_t> hw_ifh(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001215 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001216
1217 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001218 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001219
1220 TRY_CHECK_RC(OM::write(noam, itf1));
1221
1222 sub_interface *vl33 = new sub_interface(itf1,
1223 interface::admin_state_t::UP,
1224 33);
1225
1226 HW::item<handle_t> hw_vl33(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001227 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1228 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
Neale Ranns812ed392017-10-16 04:20:13 -07001229
1230 TRY_CHECK_RC(OM::write(noam, *vl33));
1231
1232 delete vl33;
1233 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1234 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001235 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1236 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1237 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1238 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001239
1240 TRY_CHECK(OM::remove(noam));
1241}
1242
1243BOOST_AUTO_TEST_CASE(test_acl) {
1244 VppInit vi;
1245 const std::string fyodor = "FyodorDostoyevsky";
1246 const std::string leo = "LeoTolstoy";
1247 rc_t rc = rc_t::OK;
1248
1249 /*
1250 * Fyodor adds an ACL in the input direction
1251 */
1252 std::string itf1_name = "host1";
1253 interface itf1(itf1_name,
1254 interface::type_t::AFPACKET,
1255 interface::admin_state_t::UP);
1256 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1257 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001258 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1259 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001260 TRY_CHECK_RC(OM::write(fyodor, itf1));
1261
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001262 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1263 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1264 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1265 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1266 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1267 HW::item<bool> ae_binding(true, rc_t::OK);
1268 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1269 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1270
Neale Ranns812ed392017-10-16 04:20:13 -07001271 route::prefix_t src("10.10.10.10", 32);
1272 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1273 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1274
1275 std::string acl_name = "acl1";
1276 ACL::l3_list acl1(acl_name);
1277 acl1.insert(r2);
1278 acl1.insert(r1);
1279 ACL::l3_list::rules_t rules = {r1, r2};
1280
1281 HW::item<handle_t> hw_acl(2, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001282 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001283 TRY_CHECK_RC(OM::write(fyodor, acl1));
1284
Mohsin Kazmid91d1402018-02-14 15:47:19 +01001285 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1286 ACL::l3_list acl2(acl_name);
1287 acl2.insert(r3);
1288 ACL::l3_list::rules_t rules2 = {r3};
1289 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1290 TRY_CHECK_RC(OM::write(fyodor, acl2));
1291
Neale Ranns812ed392017-10-16 04:20:13 -07001292 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1293 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001294 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1295 hw_ifh.data(), hw_acl.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001296 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1297
1298 /**
1299 * Leo adds an L2 ACL in the output direction
1300 */
1301 TRY_CHECK_RC(OM::write(leo, itf1));
1302
1303 std::string l2_acl_name = "l2_acl1";
1304 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1305 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1306 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1307 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1308
1309 ACL::l2_list l2_acl(l2_acl_name);
1310 l2_acl.insert(l2_r2);
1311 l2_acl.insert(l2_r1);
1312
1313 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1314
1315 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001316 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
Neale Ranns812ed392017-10-16 04:20:13 -07001317 TRY_CHECK_RC(OM::write(leo, l2_acl));
1318
1319 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1320 HW::item<bool> l2_hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001321 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001322 hw_ifh.data(), l2_hw_acl.data()));
1323 TRY_CHECK_RC(OM::write(leo, *l2b));
1324
1325 delete l2b;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001326 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1327 hw_ifh.data(), l2_hw_acl.data()));
1328 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
Neale Ranns812ed392017-10-16 04:20:13 -07001329 TRY_CHECK(OM::remove(leo));
1330
1331 delete l3b;
Mohsin Kazmi49c7f0c2018-02-07 20:20:36 +01001332 delete a_e;
Neale Ranns812ed392017-10-16 04:20:13 -07001333 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1334 rc_t::OK);
1335 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001336 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
Neale Ranns812ed392017-10-16 04:20:13 -07001337 hw_ifh.data(), hw_acl.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001338 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
Mohsin Kazmi04def742018-03-07 19:53:51 +01001339 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001340 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1341 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001342
1343 TRY_CHECK(OM::remove(fyodor));
1344}
1345
Mohsin Kazmi12fe8782018-10-30 19:24:34 +01001346BOOST_AUTO_TEST_CASE(test_igmp) {
1347 VppInit vi;
1348 const std::string Isaiah = "IsaiahBerlin";
1349 rc_t rc = rc_t::OK;
1350
1351 boost::asio::ip::address gaddr = boost::asio::ip::address::from_string("232.0.0.1");
1352 boost::asio::ip::address saddr1 = boost::asio::ip::address::from_string("192.168.0.20");
1353 boost::asio::ip::address saddr2 = boost::asio::ip::address::from_string("192.168.0.30");
1354
1355 std::string itf3_name = "host3";
1356 interface itf3(itf3_name,
1357 interface::type_t::AFPACKET,
1358 interface::admin_state_t::UP);
1359 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1360 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1361 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1362 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1363 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1364
1365 igmp_binding *ib = new igmp_binding(itf3);
1366 HW::item<bool> hw_binding(true, rc_t::OK);
1367 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1368 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1369
1370 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1371
1372 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1373 HW::item<bool> hw_as_listen(true, rc_t::OK);
1374 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1375 TRY_CHECK_RC(OM::write(Isaiah, *il));
1376
1377 delete il;
1378 delete ib;
1379
1380 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1381 rc_t::OK);
1382 STRICT_ORDER_OFF();
1383 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1384 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1385 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1386 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1387
1388 TRY_CHECK(OM::remove(Isaiah));
1389}
1390
Neale Ranns812ed392017-10-16 04:20:13 -07001391BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1392 VppInit vi;
1393 const std::string kurt = "KurtVonnegut";
1394 rc_t rc = rc_t::OK;
1395
1396 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1397 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1398
1399 arp_proxy_config ap(low, high);
1400 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001401 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001402 TRY_CHECK_RC(OM::write(kurt, ap));
1403
1404 std::string itf3_name = "host3";
1405 interface itf3(itf3_name,
1406 interface::type_t::AFPACKET,
1407 interface::admin_state_t::UP);
1408 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1409 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001410 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1411 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001412 TRY_CHECK_RC(OM::write(kurt, itf3));
1413
Neale Ranns0053de62018-05-22 08:40:52 -07001414 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
Neale Ranns812ed392017-10-16 04:20:13 -07001415 HW::item<bool> hw_binding(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001416 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001417 TRY_CHECK_RC(OM::write(kurt, *apb));
1418
1419 delete apb;
1420
1421 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1422 rc_t::OK);
1423 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001424 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1425 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1426 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1427 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
Neale Ranns812ed392017-10-16 04:20:13 -07001428
1429 TRY_CHECK(OM::remove(kurt));
1430}
1431
Mohsin Kazmie23edac2018-09-25 18:26:52 +02001432BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1433 VppInit vi;
1434 const std::string eliot = "EliotReed";
1435 rc_t rc = rc_t::OK;
1436
1437 /*
1438 * Interface 1 is the tx interface
1439 */
1440 std::string itf1_name = "tx-itf";
1441 interface itf1(itf1_name,
1442 interface::type_t::AFPACKET,
1443 interface::admin_state_t::UP);
1444 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1445 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1446 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1447 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1448 TRY_CHECK_RC(OM::write(eliot, itf1));
1449
1450 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1451
1452 /*
1453 * Interface 2 is the rx interface
1454 */
1455 std::string itf2_name = "rx-itf";
1456 interface itf2(itf2_name,
1457 interface::type_t::AFPACKET,
1458 interface::admin_state_t::UP);
1459
1460 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1461 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1462 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1463 TRY_CHECK_RC(OM::write(eliot, itf2));
1464
1465 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1466 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1467 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1468 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1469 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1470
1471 delete ip_punt;
1472
1473 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1474 STRICT_ORDER_OFF();
1475 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1476 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1477 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1478 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1479 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1480
1481 TRY_CHECK(OM::remove(eliot));
1482}
1483
Neale Ranns812ed392017-10-16 04:20:13 -07001484BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1485 VppInit vi;
1486 const std::string eric = "EricAmbler";
1487 rc_t rc = rc_t::OK;
1488
1489 /*
1490 * Interface 1 has the L3 address
1491 */
1492 std::string itf1_name = "host1";
1493 interface itf1(itf1_name,
1494 interface::type_t::AFPACKET,
1495 interface::admin_state_t::UP);
1496 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1497 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001498 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1499 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001500 TRY_CHECK_RC(OM::write(eric, itf1));
1501
1502 route::prefix_t pfx_10("10.10.10.10", 24);
1503 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1504 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1505 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001506 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001507 TRY_CHECK_RC(OM::write(eric, *l3));
1508
1509 /*
1510 * Interface 2 is unnumbered
1511 */
1512 std::string itf2_name = "host2";
1513 interface itf2(itf2_name,
1514 interface::type_t::AFPACKET,
1515 interface::admin_state_t::UP);
1516
1517 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001518 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1519 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001520 TRY_CHECK_RC(OM::write(eric, itf2));
1521
1522 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1523 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1524 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001525 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
Neale Ranns812ed392017-10-16 04:20:13 -07001526 TRY_CHECK_RC(OM::write(eric, *ipun));
1527
1528 delete l3;
1529 delete ipun;
1530
1531 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1532 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001533 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1534 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1535 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1536 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1537 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1538 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001539
1540 TRY_CHECK(OM::remove(eric));
1541}
1542
1543BOOST_AUTO_TEST_CASE(test_ip6nd) {
1544 VppInit vi;
1545 const std::string paulo = "PauloCoelho";
1546 rc_t rc = rc_t::OK;
1547
1548 /*
1549 * ra config
1550 */
1551 std::string itf_name = "host_ip6nd";
1552 interface itf(itf_name,
1553 interface::type_t::AFPACKET,
1554 interface::admin_state_t::UP);
1555 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1556 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001557 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1558 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001559 TRY_CHECK_RC(OM::write(paulo, itf));
1560
1561 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1562 l3_binding *l3 = new l3_binding(itf, pfx_10);
1563 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1564 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001565 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001566 TRY_CHECK_RC(OM::write(paulo, *l3));
1567
1568 ra_config ra(0, 1, 0, 4);
1569 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1570 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1571 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1572 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1573 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1574
1575 /*
1576 * ra prefix
1577 */
1578 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1579 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1580 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1581 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1582 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1583 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1584
1585 delete ip6pfx;
1586
1587 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1588
1589 delete ip6ra;
1590 delete l3;
1591
1592 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1593
1594 STRICT_ORDER_OFF();
1595 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001596 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1597 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1598 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001599
1600 TRY_CHECK(OM::remove(paulo));
1601}
1602
1603BOOST_AUTO_TEST_CASE(test_interface_span) {
1604 VppInit vi;
1605 const std::string elif = "ElifShafak";
1606 rc_t rc = rc_t::OK;
1607
1608 /*
1609 * Interface 1 to be mirrored
1610 */
1611 std::string itf1_name = "port-from";
1612 interface itf1(itf1_name,
1613 interface::type_t::AFPACKET,
1614 interface::admin_state_t::UP);
1615 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1616 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001617 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1618 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001619 TRY_CHECK_RC(OM::write(elif, itf1));
1620
1621 /*
1622 * Interface 2 where traffic is mirrored
1623 */
1624 std::string itf2_name = "port-to";
1625 interface itf2(itf2_name,
1626 interface::type_t::AFPACKET,
1627 interface::admin_state_t::UP);
1628
1629 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1630 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1631
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001632 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1633 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001634 TRY_CHECK_RC(OM::write(elif, itf2));
1635
1636 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1637 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1638 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001639 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 -07001640 TRY_CHECK_RC(OM::write(elif, *itf_span));
1641
1642 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1643 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1644
1645 delete itf_span;
1646 STRICT_ORDER_OFF();
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001647 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1648 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1649 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1650 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1651 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001652
1653 TRY_CHECK(OM::remove(elif));
1654}
1655
1656BOOST_AUTO_TEST_CASE(test_routing) {
1657 VppInit vi;
1658 const std::string ian = "IanFleming";
1659 rc_t rc = rc_t::OK;
1660
1661 /*
1662 * non-default route domain
1663 */
1664 route_domain rd4(1);
1665 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1666 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1667 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1668 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1669 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1670 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1671 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1672 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001673 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1674 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001675 TRY_CHECK_RC(OM::write(ian, rd4));
1676
1677 /*
1678 * a couple of interfaces
1679 */
1680 std::string itf1_name = "af1";
1681 interface itf1(itf1_name,
1682 interface::type_t::AFPACKET,
1683 interface::admin_state_t::UP);
1684 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1685 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1686 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001687 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1688 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001689 TRY_CHECK_RC(OM::write(ian, itf1));
1690
1691 std::string itf2_name = "af2";
1692 interface *itf2 = new interface(itf2_name,
1693 interface::type_t::AFPACKET,
1694 interface::admin_state_t::UP,
1695 rd4);
1696
1697 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1698 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1699 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001700 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1701 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1702 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1703 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001704 TRY_CHECK_RC(OM::write(ian, *itf2));
1705
1706 /*
1707 * prefix on each interface
1708 */
1709 route::prefix_t pfx_10("10.10.10.10", 24);
1710 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1711 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1712 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001713 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001714 TRY_CHECK_RC(OM::write(ian, *l3_10));
1715 route::prefix_t pfx_11("11.11.11.11", 24);
1716 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1717 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1718 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001719 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
Neale Ranns812ed392017-10-16 04:20:13 -07001720 TRY_CHECK_RC(OM::write(ian, *l3_11));
1721
1722 /*
1723 * A route via interface 1 in the default table
1724 */
1725 route::prefix_t pfx_5("5.5.5.5", 32);
1726 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1727 route::path *path_10 = new route::path(nh_10, itf1);
1728 route::ip_route *route_5 = new route::ip_route(pfx_5);
1729 route_5->add(*path_10);
1730 HW::item<bool> hw_route_5(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001731 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
Neale Ranns812ed392017-10-16 04:20:13 -07001732 TRY_CHECK_RC(OM::write(ian, *route_5));
1733
1734 /*
1735 * A route via interface 2 in the non-default table
1736 */
1737 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1738 route::path *path_11 = new route::path(nh_11, *itf2);
1739 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1740 route_5_2->add(*path_11);
1741 HW::item<bool> hw_route_5_2(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001742 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
Neale Ranns812ed392017-10-16 04:20:13 -07001743 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1744
1745 /*
1746 * An ARP entry for the neighbour on itf1
1747 */
1748 HW::item<bool> hw_neighbour(true, rc_t::OK);
1749 mac_address_t mac_n({0,1,2,4,5,6});
Neale Rannsfd920602017-11-23 12:15:00 -08001750 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001751 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
Neale Ranns812ed392017-10-16 04:20:13 -07001752 TRY_CHECK_RC(OM::write(ian, *ne));
1753
1754 /*
1755 * A DVR route
1756 */
1757 route::prefix_t pfx_6("6.6.6.6", 32);
1758 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1759 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1760 route_dvr->add(*path_l2);
1761 HW::item<bool> hw_route_dvr(true, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001762 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
Neale Ranns812ed392017-10-16 04:20:13 -07001763 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1764
1765 STRICT_ORDER_OFF();
1766 // delete the stack objects that hold references to others
1767 // so the OM::remove is the call that removes the last reference
1768 delete l3_11;
1769 delete l3_10;
1770 delete itf2;
1771 delete route_5;
1772 delete path_10;
1773 delete route_5_2;
1774 delete path_11;
1775 delete route_dvr;
1776 delete path_l2;
1777 delete ne;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001778 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1779 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1780 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1781 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1782 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1783 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1784 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1785 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1786 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1787 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1788 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1789 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1790 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1791 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
Neale Ranns812ed392017-10-16 04:20:13 -07001792
1793 TRY_CHECK(OM::remove(ian));
1794}
1795
1796BOOST_AUTO_TEST_CASE(test_nat) {
1797 VppInit vi;
1798 const std::string gs = "GeorgeSimenon";
1799 rc_t rc = rc_t::OK;
1800
1801 /*
1802 * Inside Interface
1803 */
1804 std::string itf_in_name = "inside";
1805 interface itf_in(itf_in_name,
1806 interface::type_t::AFPACKET,
1807 interface::admin_state_t::UP);
1808 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1809 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1810 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001811 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1812 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
Neale Ranns812ed392017-10-16 04:20:13 -07001813 TRY_CHECK_RC(OM::write(gs, itf_in));
1814
1815 /*
1816 * outside
1817 */
1818 std::string itf_out_name = "port-to";
1819 interface itf_out(itf_out_name,
1820 interface::type_t::AFPACKET,
1821 interface::admin_state_t::UP);
1822
1823 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1824 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1825 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1826
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001827 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1828 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
Neale Ranns812ed392017-10-16 04:20:13 -07001829 TRY_CHECK_RC(OM::write(gs, itf_out));
1830
1831 /*
1832 * A NAT static mapping
1833 */
1834 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1835 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1836
1837 nat_static ns(in_addr, out_addr);
1838 HW::item<bool> hw_ns(true, rc_t::OK);
1839
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001840 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
Neale Ranns812ed392017-10-16 04:20:13 -07001841 TRY_CHECK_RC(OM::write(gs, ns));
1842
1843 /*
1844 * bind nat inside and out
1845 */
1846 nat_binding *nb_in = new nat_binding(itf_in,
1847 direction_t::INPUT,
1848 l3_proto_t::IPV4,
1849 nat_binding::zone_t::INSIDE);
1850 HW::item<bool> hw_nb_in(true, rc_t::OK);
1851
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001852 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1853 hw_ifh.data().value(),
1854 nat_binding::zone_t::INSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001855 TRY_CHECK_RC(OM::write(gs, *nb_in));
1856
1857 nat_binding *nb_out = new nat_binding(itf_out,
1858 direction_t::INPUT,
1859 l3_proto_t::IPV4,
1860 nat_binding::zone_t::OUTSIDE);
1861 HW::item<bool> hw_nb_out(true, rc_t::OK);
1862
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001863 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1864 hw_ifh2.data().value(),
1865 nat_binding::zone_t::OUTSIDE));
Neale Ranns812ed392017-10-16 04:20:13 -07001866 TRY_CHECK_RC(OM::write(gs, *nb_out));
1867
1868
1869 STRICT_ORDER_OFF();
1870 delete nb_in;
1871 delete nb_out;
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001872 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1873 hw_ifh.data().value(),
1874 nat_binding::zone_t::INSIDE));
1875 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1876 hw_ifh2.data().value(),
1877 nat_binding::zone_t::OUTSIDE));
1878 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1879 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1880 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1881 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1882 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
Neale Ranns812ed392017-10-16 04:20:13 -07001883
1884 TRY_CHECK(OM::remove(gs));
1885}
1886
1887BOOST_AUTO_TEST_CASE(test_interface_events) {
1888 VppInit vi;
1889 MockListener ml;
1890
1891 HW::item<bool> hw_want(true, rc_t::OK);
1892
Neale Ranns9ef1c0a2017-11-03 04:39:05 -07001893 ADD_EXPECT(interface_cmds::events_cmd(ml));
1894 cmd* itf = new interface_cmds::events_cmd(ml);
Neale Ranns812ed392017-10-16 04:20:13 -07001895
1896 HW::enqueue(itf);
1897 HW::write();
Neale Ranns812ed392017-10-16 04:20:13 -07001898}
1899
Neale Ranns352ea0c2017-11-14 11:04:28 -08001900BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1901 VppInit vi;
1902 const std::string rene = "ReneGoscinny";
1903 rc_t rc = rc_t::OK;
1904
1905 /*
1906 * Create an interface with two IP addresses
1907 */
1908 std::string itf1_name = "host1";
1909 interface itf1(itf1_name,
1910 interface::type_t::AFPACKET,
1911 interface::admin_state_t::UP);
1912 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1913 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1914 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1915 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1916 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1917 TRY_CHECK_RC(OM::write(rene, itf1));
1918
1919 route::prefix_t pfx_10("10.10.10.10", 24);
1920 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1921 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1922 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1923 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1924 TRY_CHECK_RC(OM::write(rene, *l3_1));
1925
1926 route::prefix_t pfx_11("10.10.11.11", 24);
1927 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1928 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1929 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1930 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1931 TRY_CHECK_RC(OM::write(rene, *l3_2));
1932
1933 route_domain rd(1);
1934 HW::item<bool> hw_rd_create(true, rc_t::OK);
1935 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1936 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1937 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1938 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1939 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1940 TRY_CHECK_RC(OM::write(rene, rd));
1941
1942 /*
1943 * update the interface to change to a new route-domain
1944 * expect that the l3-bindings are removed and readded.
1945 */
1946 interface *itf2 = new interface(itf1_name,
1947 interface::type_t::AFPACKET,
1948 interface::admin_state_t::UP,
1949 rd);
1950 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1951 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1952 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1953 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1954 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1955 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1956 TRY_CHECK_RC(OM::write(rene, *itf2));
1957
1958 /*
1959 * mve the interface back to the default route-domain
1960 */
1961 interface itf3(itf1_name,
1962 interface::type_t::AFPACKET,
1963 interface::admin_state_t::UP);
1964 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1965 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1966 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1967 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1968 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1969 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1970 TRY_CHECK_RC(OM::write(rene, itf3));
1971
1972 delete l3_1;
1973 delete l3_2;
1974 delete itf2;
1975
1976 STRICT_ORDER_OFF();
1977 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1978 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1979 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1980 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1981 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1982 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1983
1984 TRY_CHECK(OM::remove(rene));
1985}
1986
Neale Rannsd3464b52017-12-07 08:48:02 -08001987BOOST_AUTO_TEST_CASE(test_prefixes) {
1988 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1989
1990 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1991
1992 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1993
1994 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1995 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1996
1997 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1998 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1999 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2000
2001 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2002
2003 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2004
2005 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2006
2007 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2008 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2009 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2010
2011 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2012
2013 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2014 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2015 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2016
2017 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2018
2019 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2020 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2021 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2022
2023}
2024
Neale Ranns208c29a2018-04-11 08:08:30 -07002025BOOST_AUTO_TEST_CASE(test_pipes) {
2026 VppInit vi;
2027 const std::string gk = "GKChesterton";
2028
2029 const std::string pipe_name_1 = "pipe1";
2030 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2031 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2032 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2033
2034 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2035 rc_t::OK);
2036 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2037 rc_t::OK);
2038 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2039 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2040 TRY_CHECK_RC(OM::write(gk, pipe1));
2041
2042 pipe1.set_ends(hw_hdl_pair.data());
2043
2044 // put each end of the pipe in a BD
2045 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2046 bridge_domain::arp_term_mode_t::OFF,
2047 bridge_domain::flood_mode_t::OFF,
2048 bridge_domain::mac_age_mode_t::ON);
2049
2050 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2051 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2052 bridge_domain::learning_mode_t::OFF,
2053 bridge_domain::arp_term_mode_t::OFF,
2054 bridge_domain::flood_mode_t::OFF,
2055 bridge_domain::mac_age_mode_t::ON));
2056
2057 TRY_CHECK_RC(OM::write(gk, bd1));
2058
2059 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2060 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2061
2062 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2063 pipe1.east()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002064 hw_bd.data(),
2065 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002066 TRY_CHECK_RC(OM::write(gk, *l2_1));
2067
2068 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2069 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2070
2071 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2072 pipe1.west()->handle(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002073 hw_bd.data(),
2074 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002075 TRY_CHECK_RC(OM::write(gk, *l2_2));
2076
2077 STRICT_ORDER_OFF();
2078
2079 delete l2_1;
2080 delete l2_2;
2081 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2082 pipe1.east()->handle(),
2083 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002084 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002085 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2086 pipe1.west()->handle(),
2087 hw_bd.data(),
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02002088 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
Neale Ranns208c29a2018-04-11 08:08:30 -07002089 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2090 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2091 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2092 TRY_CHECK(OM::remove(gk));
2093}
2094
Neale Ranns812ed392017-10-16 04:20:13 -07002095BOOST_AUTO_TEST_SUITE_END()