2 * Test suite for class VppOM
4 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
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
10 #define BOOST_TEST_MODULE "VPP OBJECT MODEL"
11 #define BOOST_TEST_DYN_LINK
13 #include <boost/test/unit_test.hpp>
14 #include <boost/assign/list_inserter.hpp>
21 #include "vom/interface.hpp"
22 #include "vom/interface_cmds.hpp"
23 #include "vom/bond_interface_cmds.hpp"
24 #include "vom/bond_group_binding.hpp"
25 #include "vom/bond_group_binding_cmds.hpp"
26 #include "vom/l2_binding.hpp"
27 #include "vom/l2_binding_cmds.hpp"
28 #include "vom/l2_xconnect.hpp"
29 #include "vom/l2_xconnect_cmds.hpp"
30 #include "vom/l3_binding.hpp"
31 #include "vom/l3_binding_cmds.hpp"
32 #include "vom/bridge_domain.hpp"
33 #include "vom/bridge_domain_entry.hpp"
34 #include "vom/bridge_domain_arp_entry.hpp"
35 #include "vom/bridge_domain_cmds.hpp"
36 #include "vom/bridge_domain_entry_cmds.hpp"
37 #include "vom/bridge_domain_arp_entry_cmds.hpp"
38 #include "vom/prefix.hpp"
39 #include "vom/route.hpp"
40 #include "vom/route_cmds.hpp"
41 #include "vom/route_domain.hpp"
42 #include "vom/route_domain_cmds.hpp"
43 #include "vom/vxlan_tunnel.hpp"
44 #include "vom/vxlan_tunnel_cmds.hpp"
45 #include "vom/sub_interface.hpp"
46 #include "vom/sub_interface_cmds.hpp"
47 #include "vom/acl_ethertype.hpp"
48 #include "vom/acl_ethertype_cmds.hpp"
49 #include "vom/acl_list.hpp"
50 #include "vom/acl_binding.hpp"
51 #include "vom/acl_list_cmds.hpp"
52 #include "vom/acl_binding_cmds.hpp"
53 #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"
57 #include "vom/arp_proxy_config_cmds.hpp"
58 #include "vom/arp_proxy_binding_cmds.hpp"
59 #include "vom/ip_unnumbered.hpp"
60 #include "vom/ip_unnumbered_cmds.hpp"
61 #include "vom/interface_ip6_nd.hpp"
62 #include "vom/interface_span.hpp"
63 #include "vom/interface_span_cmds.hpp"
64 #include "vom/neighbour.hpp"
65 #include "vom/neighbour_cmds.hpp"
66 #include "vom/nat_static.hpp"
67 #include "vom/nat_static_cmds.hpp"
68 #include "vom/nat_binding.hpp"
69 #include "vom/nat_binding_cmds.hpp"
70 #include "vom/pipe.hpp"
71 #include "vom/pipe_cmds.hpp"
73 using namespace boost;
77 * An expectation exception
82 ExpException(unsigned int number)
84 // a neat place to add a break point
85 std::cout << " ExpException here: " << number << std::endl;
89 class MockListener : public interface::event_listener,
90 public interface::stat_listener
92 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
95 void handle_interface_event(interface_cmds::events_cmd *cmd)
100 class MockCmdQ : public HW::cmd_q
112 m_exp_queue.push_back(f);
116 m_act_queue.push_back(f);
118 void enqueue(std::queue<cmd*> &cmds)
122 m_act_queue.push_back(cmds.front());
126 void enqueue(std::shared_ptr<cmd> f)
128 m_act_queue.push_back(f.get());
135 void dequeue(std::shared_ptr<cmd> cmd)
139 void strict_order(bool on)
146 return ((0 == m_exp_queue.size()) &&
147 (0 == m_act_queue.size()));
155 while (m_act_queue.size())
157 bool matched = false;
158 auto it_exp = m_exp_queue.begin();
159 auto it_act = m_act_queue.begin();
163 std::cout << " Act: " << f_act->to_string() << std::endl;
164 while (it_exp != m_exp_queue.end())
169 std::cout << " Exp: " << f_exp->to_string() << std::endl;
171 if (typeid(*f_exp) != typeid(*f_act))
173 throw ExpException(1);
176 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
178 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
180 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
182 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
184 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
186 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
188 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
190 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
192 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
194 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
196 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
198 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
200 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
202 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
204 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
206 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
208 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
210 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
212 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
214 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
216 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
218 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
220 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
222 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
224 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
226 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
228 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
230 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
232 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
234 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
236 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
238 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
240 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
242 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
244 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
246 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
248 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
250 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
252 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
254 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
256 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
258 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
260 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
262 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
264 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
266 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
268 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
270 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
272 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
274 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
276 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
278 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
280 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
282 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
284 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
286 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
288 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
290 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
292 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
294 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
296 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
298 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
300 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
302 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
304 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
306 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
308 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
310 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
312 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
314 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
316 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
318 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
320 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
322 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
324 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
326 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
328 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
330 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
332 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
334 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
336 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
338 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
340 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
342 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
344 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
346 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
348 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
350 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
352 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
354 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
356 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
358 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
360 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
362 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
364 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
366 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
368 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
370 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
372 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
374 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
376 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
378 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
380 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
382 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
384 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
386 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
388 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
390 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
392 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
394 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
396 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
398 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
400 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
402 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
404 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
406 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
408 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
410 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
412 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
414 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
416 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
418 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
420 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
422 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
424 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
426 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
428 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
430 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
432 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
434 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
436 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
438 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
442 throw ExpException(2);
445 // if we get here then we found the match.
446 m_exp_queue.erase(it_exp);
447 m_act_queue.erase(it_act);
451 // return any injected failures to the agent
452 if (rc_t::OK != rc && rc_t::NOOP != rc)
460 catch (ExpException &e)
462 // The expected and actual do not match
465 // in strict ordering mode this is fatal, so rethrow
470 // move the iterator onto the next in the expected list and
478 throw ExpException(3);
485 template <typename T>
486 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
491 i_exp = dynamic_cast<const T*>(f_exp);
492 i_act = dynamic_cast<T*>(f_act);
493 if (!(*i_exp == *i_act))
495 throw ExpException(4);
497 // pass the data and return code to the agent
498 i_act->item() = i_exp->item();
500 return (i_act->item().rc());
503 // The Q to push the expectations on
504 std::deque<cmd*> m_exp_queue;
506 // the queue to push the actual events on
507 std::deque<cmd*> m_act_queue;
509 // control whether the expected queue is strictly ordered.
524 logger().set(log_level_t::DEBUG);
532 BOOST_AUTO_TEST_SUITE(vom)
534 #define TRY_CHECK_RC(stmt) \
537 BOOST_CHECK(rc_t::OK == stmt); \
539 catch (ExpException &e) \
541 BOOST_CHECK(false); \
543 BOOST_CHECK(vi.f->is_empty()); \
546 #define TRY_CHECK(stmt) \
551 catch (ExpException &e) \
553 BOOST_CHECK(false); \
555 BOOST_CHECK(vi.f->is_empty()); \
558 #define ADD_EXPECT(stmt) \
559 vi.f->expect(new stmt)
561 #define STRICT_ORDER_OFF() \
562 vi.f->strict_order(false)
564 BOOST_AUTO_TEST_CASE(test_interface) {
566 const std::string go = "GeorgeOrwell";
567 const std::string js = "JohnSteinbeck";
571 * George creates and deletes the interface
573 std::string itf1_name = "afpacket1";
574 interface itf1(itf1_name,
575 interface::type_t::AFPACKET,
576 interface::admin_state_t::UP);
579 * set the expectation for a afpacket interface create.
580 * 2 is the interface handle VPP [mock] assigns
582 HW::item<handle_t> hw_ifh(2, rc_t::OK);
583 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
585 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
586 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
588 TRY_CHECK_RC(OM::write(go, itf1));
590 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
591 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
592 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
594 TRY_CHECK(OM::remove(go));
597 * George creates the interface, then John brings it down.
598 * George's remove is a no-op, sice John also owns the interface
600 interface itf1b(itf1_name,
601 interface::type_t::AFPACKET,
602 interface::admin_state_t::DOWN);
604 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
605 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
606 TRY_CHECK_RC(OM::write(go, itf1));
608 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
609 TRY_CHECK_RC(OM::write(js, itf1b));
611 TRY_CHECK(OM::remove(go));
613 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
614 TRY_CHECK(OM::remove(js));
617 * George adds an interface, then we flush all of Geroge's state
619 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
620 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
621 TRY_CHECK_RC(OM::write(go, itf1));
623 TRY_CHECK(OM::mark(go));
625 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
626 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
627 TRY_CHECK(OM::sweep(go));
630 * George adds an interface. mark stale. update the same interface. sweep
631 * and expect no delete
633 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
634 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
635 TRY_CHECK_RC(OM::write(go, itf1b));
637 TRY_CHECK(OM::mark(go));
639 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
640 TRY_CHECK_RC(OM::write(go, itf1));
642 TRY_CHECK(OM::sweep(go));
644 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
645 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
646 TRY_CHECK(OM::remove(go));
649 * George adds an insterface, then we mark that state. Add a second interface
650 * an flush the first that is now stale.
652 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
653 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
654 TRY_CHECK_RC(OM::write(go, itf1));
656 TRY_CHECK(OM::mark(go));
658 std::string itf2_name = "afpacket2";
659 std::string itf2_tag = "uuid-of-afpacket2-interface";
660 interface itf2(itf2_name,
661 interface::type_t::AFPACKET,
662 interface::admin_state_t::UP,
664 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
666 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
667 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
668 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
669 TRY_CHECK_RC(OM::write(go, itf2));
671 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
672 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
673 TRY_CHECK(OM::sweep(go));
675 TRY_CHECK(OM::mark(go));
677 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
678 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
679 TRY_CHECK(OM::sweep(go));
682 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
683 std::string itf3_tag = "uuid-of-vhost_user1-interface";
684 interface itf3(itf3_name,
685 interface::type_t::VHOST,
686 interface::admin_state_t::UP,
688 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
690 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
691 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
692 TRY_CHECK_RC(OM::write(go, itf3));
694 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
695 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
696 TRY_CHECK(OM::remove(go));
699 BOOST_AUTO_TEST_CASE(test_bvi) {
701 const std::string ernest = "ErnestHemmingway";
702 const std::string graham = "GrahamGreene";
706 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
708 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
712 * Enrest creates a BVI with address 10.10.10.10/24
714 route::prefix_t pfx_10("10.10.10.10", 24);
716 const std::string bvi_name = "bvi1";
717 interface itf(bvi_name,
718 interface::type_t::BVI,
719 interface::admin_state_t::UP);
720 HW::item<handle_t> hw_ifh(4, rc_t::OK);
721 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
723 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
724 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
725 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
726 TRY_CHECK_RC(OM::write(ernest, itf));
728 l3 = new l3_binding(itf, pfx_10);
729 HW::item<bool> hw_l3_bind(true, rc_t::OK);
730 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
731 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
732 TRY_CHECK_RC(OM::write(ernest, *l3));
734 // change the MAC address on the BVI
735 interface itf_new_mac(bvi_name,
736 interface::type_t::BVI,
737 interface::admin_state_t::UP);
738 l2_address_t l2_addr({0,1,2,3,4,5});
739 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
740 itf_new_mac.set(l2_addr);
741 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
742 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
744 // create/write the interface to the OM again but with an unset MAC
745 // this should not generate a MAC address update
746 TRY_CHECK_RC(OM::write(ernest, itf));
748 // change the MAC address on the BVI - again
749 interface itf_new_mac2(bvi_name,
750 interface::type_t::BVI,
751 interface::admin_state_t::UP);
752 l2_address_t l2_addr2({0,1,2,3,4,6});
753 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
754 itf_new_mac2.set(l2_addr2);
755 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
756 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
759 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
760 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
761 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
762 TRY_CHECK(OM::remove(ernest));
765 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
768 HW::item<bool> hw_rd4_create(true, rc_t::OK);
769 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
770 HW::item<bool> hw_rd6_create(true, rc_t::OK);
771 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
772 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
773 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
774 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
775 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
776 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
777 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
778 TRY_CHECK_RC(OM::write(graham, rd));
780 const std::string bvi2_name = "bvi2";
781 interface *itf2 = new interface(bvi2_name,
782 interface::type_t::BVI,
783 interface::admin_state_t::UP,
785 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
787 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
788 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
789 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
790 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
791 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
793 TRY_CHECK_RC(OM::write(graham, *itf2));
795 l3 = new l3_binding(*itf2, pfx_10);
796 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
797 TRY_CHECK_RC(OM::write(graham, *l3));
802 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
803 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
804 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
805 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
806 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
807 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
808 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
809 TRY_CHECK(OM::remove(graham));
812 BOOST_AUTO_TEST_CASE(test_bond) {
814 const std::string cb = "CarolBerg";
818 * creates the interfaces
820 std::string itf1_name = "afpacket1";
821 interface itf1(itf1_name,
822 interface::type_t::AFPACKET,
823 interface::admin_state_t::UP);
825 HW::item<handle_t> hw_ifh(2, rc_t::OK);
826 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
828 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
829 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
831 TRY_CHECK_RC(OM::write(cb, itf1));
833 std::string itf2_name = "afpacket2";
834 interface itf2(itf2_name,
835 interface::type_t::AFPACKET,
836 interface::admin_state_t::UP);
839 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
840 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
841 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
843 TRY_CHECK_RC(OM::write(cb, itf2));
845 std::string bond_name = "bond";
846 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
847 bond_interface::mode_t::LACP);
849 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
850 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
851 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
852 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
854 TRY_CHECK_RC(OM::write(cb, bond_itf));
856 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
857 bond_member::rate_t::SLOW);
858 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
859 bond_member::rate_t::SLOW);
860 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
862 HW::item<bool> bond_hw_bind(true, rc_t::OK);
863 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
864 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
866 TRY_CHECK_RC(OM::write(cb, *bgb));
873 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
874 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
875 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
876 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
877 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
879 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
880 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
881 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
883 TRY_CHECK(OM::remove(cb));
886 BOOST_AUTO_TEST_CASE(test_bridge) {
888 const std::string franz = "FranzKafka";
889 const std::string dante = "Dante";
890 const std::string jkr = "jkrowling";
894 * Franz creates an interface, Bridge-domain, then binds the two
898 std::string itf1_name = "afpacket1";
899 interface itf1(itf1_name,
900 interface::type_t::AFPACKET,
901 interface::admin_state_t::UP);
903 HW::item<handle_t> hw_ifh(3, rc_t::OK);
904 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
906 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
907 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
909 TRY_CHECK_RC(OM::write(franz, itf1));
911 // bridge-domain create
912 bridge_domain bd1(33);
914 HW::item<uint32_t> hw_bd(33, rc_t::OK);
915 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
916 bridge_domain::learning_mode_t::ON,
917 bridge_domain::arp_term_mode_t::ON,
918 bridge_domain::flood_mode_t::ON,
919 bridge_domain::mac_age_mode_t::OFF));
921 TRY_CHECK_RC(OM::write(franz, bd1));
923 // L2-interface create and bind
924 // this needs to be delete'd before the flush below, since it too maintains
925 // references to the BD and Interface
926 l2_binding *l2itf = new l2_binding(itf1, bd1);
927 HW::item<bool> hw_l2_bind(true, rc_t::OK);
929 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
930 TRY_CHECK_RC(OM::write(franz, *l2itf));
933 * Dante adds an interface to the same BD
935 std::string itf2_name = "afpacket2";
936 interface itf2(itf2_name,
937 interface::type_t::AFPACKET,
938 interface::admin_state_t::UP);
940 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
941 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
942 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
943 TRY_CHECK_RC(OM::write(dante, itf2));
945 // BD add is a no-op since it exists
946 TRY_CHECK_RC(OM::write(dante, bd1));
948 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
949 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
950 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
952 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
953 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
954 TRY_CHECK_RC(OM::write(dante, *l2itf2));
956 // Add some static entries to the bridge-domain
957 HW::item<bool> hw_be1(true, rc_t::OK);
958 mac_address_t mac1({0,1,2,3,4,5});
959 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
960 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
962 TRY_CHECK_RC(OM::write(dante, *be1));
964 // Add some entries to the bridge-domain ARP termination table
965 HW::item<bool> hw_bea1(true, rc_t::OK);
966 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
968 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
969 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
970 TRY_CHECK_RC(OM::write(dante, *bea1));
972 // flush Franz's state
974 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
976 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
977 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
978 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
979 TRY_CHECK(OM::remove(franz));
981 // flush Dante's state - the order the interface and BD are deleted
982 // is an uncontrollable artifact of the C++ object destruction.
987 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
988 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
989 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
991 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
992 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
993 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
994 TRY_CHECK(OM::remove(dante));
996 // test the BVI entry in l2fib
997 bridge_domain bd2(99);
999 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1000 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1001 bridge_domain::learning_mode_t::ON,
1002 bridge_domain::arp_term_mode_t::ON,
1003 bridge_domain::flood_mode_t::ON,
1004 bridge_domain::mac_age_mode_t::OFF));
1006 TRY_CHECK_RC(OM::write(jkr, bd2));
1008 std::string itf3_name = "bvi";
1009 interface itf3(itf3_name,
1010 interface::type_t::BVI,
1011 interface::admin_state_t::UP);
1013 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1014 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1015 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1016 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1017 TRY_CHECK_RC(OM::write(jkr, itf3));
1019 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1020 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1021 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1023 HW::item<bool> hw_be2(true, rc_t::OK);
1024 mac_address_t mac2({0,1,2,3,4,5});
1025 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1026 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1027 TRY_CHECK_RC(OM::write(jkr, *be2));
1032 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1033 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1034 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1035 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1036 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1037 TRY_CHECK(OM::remove(jkr));
1040 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1042 const std::string nicholas = "NicholasAbercrombie";
1048 std::string itf1_name = "host1";
1049 interface itf1(itf1_name,
1050 interface::type_t::AFPACKET,
1051 interface::admin_state_t::UP);
1052 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1053 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1054 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1055 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1056 TRY_CHECK_RC(OM::write(nicholas, itf1));
1061 std::string itf2_name = "host2";
1062 interface itf2(itf2_name,
1063 interface::type_t::AFPACKET,
1064 interface::admin_state_t::UP);
1066 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1067 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1068 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1069 TRY_CHECK_RC(OM::write(nicholas, itf2));
1071 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1072 HW::item<bool> xconnect_east(true, rc_t::OK);
1073 HW::item<bool> xconnect_west(true, rc_t::OK);
1074 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1075 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1076 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1077 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1078 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1082 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1084 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1085 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1086 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1087 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1088 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1089 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1091 TRY_CHECK(OM::remove(nicholas));
1094 BOOST_AUTO_TEST_CASE(test_vxlan) {
1096 const std::string franz = "FranzKafka";
1100 * Franz creates an interface, Bridge-domain, then binds the two
1104 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1105 boost::asio::ip::address::from_string("10.10.10.11"),
1108 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1110 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1111 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
1113 TRY_CHECK_RC(OM::write(franz, vxt));
1115 // bridge-domain create
1116 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1117 bridge_domain::arp_term_mode_t::OFF,
1118 bridge_domain::flood_mode_t::OFF,
1119 bridge_domain::mac_age_mode_t::ON);
1121 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1122 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1123 bridge_domain::learning_mode_t::OFF,
1124 bridge_domain::arp_term_mode_t::OFF,
1125 bridge_domain::flood_mode_t::OFF,
1126 bridge_domain::mac_age_mode_t::ON));
1128 TRY_CHECK_RC(OM::write(franz, bd1));
1130 // L2-interface create and bind
1131 // this needs to be delete'd before the flush below, since it too maintains
1132 // references to the BD and Interface
1133 l2_binding *l2itf = new l2_binding(vxt, bd1);
1134 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1136 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1137 TRY_CHECK_RC(OM::write(franz, *l2itf));
1139 // flush Franz's state
1141 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1143 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1144 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1145 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1146 TRY_CHECK(OM::remove(franz));
1149 BOOST_AUTO_TEST_CASE(test_vlan) {
1151 const std::string noam = "NoamChomsky";
1154 std::string itf1_name = "host1";
1155 interface itf1(itf1_name,
1156 interface::type_t::AFPACKET,
1157 interface::admin_state_t::UP);
1159 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1160 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1162 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1163 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1165 TRY_CHECK_RC(OM::write(noam, itf1));
1167 sub_interface *vl33 = new sub_interface(itf1,
1168 interface::admin_state_t::UP,
1171 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1172 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1173 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1175 TRY_CHECK_RC(OM::write(noam, *vl33));
1178 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1179 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1180 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1181 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1182 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1183 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1185 TRY_CHECK(OM::remove(noam));
1188 BOOST_AUTO_TEST_CASE(test_acl) {
1190 const std::string fyodor = "FyodorDostoyevsky";
1191 const std::string leo = "LeoTolstoy";
1195 * Fyodor adds an ACL in the input direction
1197 std::string itf1_name = "host1";
1198 interface itf1(itf1_name,
1199 interface::type_t::AFPACKET,
1200 interface::admin_state_t::UP);
1201 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1202 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1203 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1204 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1205 TRY_CHECK_RC(OM::write(fyodor, itf1));
1207 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1208 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1209 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1210 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1211 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1212 HW::item<bool> ae_binding(true, rc_t::OK);
1213 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1214 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1216 route::prefix_t src("10.10.10.10", 32);
1217 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1218 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1220 std::string acl_name = "acl1";
1221 ACL::l3_list acl1(acl_name);
1224 ACL::l3_list::rules_t rules = {r1, r2};
1226 HW::item<handle_t> hw_acl(2, rc_t::OK);
1227 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1228 TRY_CHECK_RC(OM::write(fyodor, acl1));
1230 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1231 ACL::l3_list acl2(acl_name);
1233 ACL::l3_list::rules_t rules2 = {r3};
1234 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1235 TRY_CHECK_RC(OM::write(fyodor, acl2));
1237 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1238 HW::item<bool> hw_binding(true, rc_t::OK);
1239 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1240 hw_ifh.data(), hw_acl.data()));
1241 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1244 * Leo adds an L2 ACL in the output direction
1246 TRY_CHECK_RC(OM::write(leo, itf1));
1248 std::string l2_acl_name = "l2_acl1";
1249 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1250 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1251 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1252 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1254 ACL::l2_list l2_acl(l2_acl_name);
1255 l2_acl.insert(l2_r2);
1256 l2_acl.insert(l2_r1);
1258 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1260 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1261 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1262 TRY_CHECK_RC(OM::write(leo, l2_acl));
1264 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1265 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1266 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1267 hw_ifh.data(), l2_hw_acl.data()));
1268 TRY_CHECK_RC(OM::write(leo, *l2b));
1271 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1272 hw_ifh.data(), l2_hw_acl.data()));
1273 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1274 TRY_CHECK(OM::remove(leo));
1278 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1281 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1282 hw_ifh.data(), hw_acl.data()));
1283 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1284 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1285 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1286 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1288 TRY_CHECK(OM::remove(fyodor));
1291 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1293 const std::string kurt = "KurtVonnegut";
1296 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1297 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1299 arp_proxy_config ap(low, high);
1300 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1301 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1302 TRY_CHECK_RC(OM::write(kurt, ap));
1304 std::string itf3_name = "host3";
1305 interface itf3(itf3_name,
1306 interface::type_t::AFPACKET,
1307 interface::admin_state_t::UP);
1308 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1309 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1310 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1311 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1312 TRY_CHECK_RC(OM::write(kurt, itf3));
1314 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1315 HW::item<bool> hw_binding(true, rc_t::OK);
1316 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1317 TRY_CHECK_RC(OM::write(kurt, *apb));
1321 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1324 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1325 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1326 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1327 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1329 TRY_CHECK(OM::remove(kurt));
1332 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1334 const std::string eric = "EricAmbler";
1338 * Interface 1 has the L3 address
1340 std::string itf1_name = "host1";
1341 interface itf1(itf1_name,
1342 interface::type_t::AFPACKET,
1343 interface::admin_state_t::UP);
1344 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1345 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1346 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1347 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1348 TRY_CHECK_RC(OM::write(eric, itf1));
1350 route::prefix_t pfx_10("10.10.10.10", 24);
1351 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1352 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1353 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1354 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1355 TRY_CHECK_RC(OM::write(eric, *l3));
1358 * Interface 2 is unnumbered
1360 std::string itf2_name = "host2";
1361 interface itf2(itf2_name,
1362 interface::type_t::AFPACKET,
1363 interface::admin_state_t::UP);
1365 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1366 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1367 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1368 TRY_CHECK_RC(OM::write(eric, itf2));
1370 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1371 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1372 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1373 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1374 TRY_CHECK_RC(OM::write(eric, *ipun));
1379 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1381 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1382 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1383 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1384 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1385 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1386 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1388 TRY_CHECK(OM::remove(eric));
1391 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1393 const std::string paulo = "PauloCoelho";
1399 std::string itf_name = "host_ip6nd";
1400 interface itf(itf_name,
1401 interface::type_t::AFPACKET,
1402 interface::admin_state_t::UP);
1403 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1404 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1405 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1406 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1407 TRY_CHECK_RC(OM::write(paulo, itf));
1409 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1410 l3_binding *l3 = new l3_binding(itf, pfx_10);
1411 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1412 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1413 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1414 TRY_CHECK_RC(OM::write(paulo, *l3));
1416 ra_config ra(0, 1, 0, 4);
1417 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1418 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1419 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1420 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1421 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1426 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1427 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1428 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1429 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1430 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1431 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1435 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1440 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1443 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1444 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1445 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1446 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1448 TRY_CHECK(OM::remove(paulo));
1451 BOOST_AUTO_TEST_CASE(test_interface_span) {
1453 const std::string elif = "ElifShafak";
1457 * Interface 1 to be mirrored
1459 std::string itf1_name = "port-from";
1460 interface itf1(itf1_name,
1461 interface::type_t::AFPACKET,
1462 interface::admin_state_t::UP);
1463 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1464 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1465 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1466 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1467 TRY_CHECK_RC(OM::write(elif, itf1));
1470 * Interface 2 where traffic is mirrored
1472 std::string itf2_name = "port-to";
1473 interface itf2(itf2_name,
1474 interface::type_t::AFPACKET,
1475 interface::admin_state_t::UP);
1477 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1478 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1480 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1481 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1482 TRY_CHECK_RC(OM::write(elif, itf2));
1484 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1485 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1486 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1487 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1488 TRY_CHECK_RC(OM::write(elif, *itf_span));
1490 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1491 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1495 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1496 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1497 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1498 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1499 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1501 TRY_CHECK(OM::remove(elif));
1504 BOOST_AUTO_TEST_CASE(test_routing) {
1506 const std::string ian = "IanFleming";
1510 * non-default route domain
1512 route_domain rd4(1);
1513 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1514 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1515 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1516 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1517 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1518 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1519 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1520 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1521 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1522 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1523 TRY_CHECK_RC(OM::write(ian, rd4));
1526 * a couple of interfaces
1528 std::string itf1_name = "af1";
1529 interface itf1(itf1_name,
1530 interface::type_t::AFPACKET,
1531 interface::admin_state_t::UP);
1532 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1533 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1534 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1535 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1536 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1537 TRY_CHECK_RC(OM::write(ian, itf1));
1539 std::string itf2_name = "af2";
1540 interface *itf2 = new interface(itf2_name,
1541 interface::type_t::AFPACKET,
1542 interface::admin_state_t::UP,
1545 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1546 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1547 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1548 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1549 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1550 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1551 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1552 TRY_CHECK_RC(OM::write(ian, *itf2));
1555 * prefix on each interface
1557 route::prefix_t pfx_10("10.10.10.10", 24);
1558 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1559 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1560 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1561 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1562 TRY_CHECK_RC(OM::write(ian, *l3_10));
1563 route::prefix_t pfx_11("11.11.11.11", 24);
1564 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1565 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1566 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1567 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1568 TRY_CHECK_RC(OM::write(ian, *l3_11));
1571 * A route via interface 1 in the default table
1573 route::prefix_t pfx_5("5.5.5.5", 32);
1574 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1575 route::path *path_10 = new route::path(nh_10, itf1);
1576 route::ip_route *route_5 = new route::ip_route(pfx_5);
1577 route_5->add(*path_10);
1578 HW::item<bool> hw_route_5(true, rc_t::OK);
1579 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
1580 TRY_CHECK_RC(OM::write(ian, *route_5));
1583 * A route via interface 2 in the non-default table
1585 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1586 route::path *path_11 = new route::path(nh_11, *itf2);
1587 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1588 route_5_2->add(*path_11);
1589 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1590 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
1591 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1594 * An ARP entry for the neighbour on itf1
1596 HW::item<bool> hw_neighbour(true, rc_t::OK);
1597 mac_address_t mac_n({0,1,2,4,5,6});
1598 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1599 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1600 TRY_CHECK_RC(OM::write(ian, *ne));
1605 route::prefix_t pfx_6("6.6.6.6", 32);
1606 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1607 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1608 route_dvr->add(*path_l2);
1609 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1610 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
1611 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1614 // delete the stack objects that hold references to others
1615 // so the OM::remove is the call that removes the last reference
1626 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1627 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1628 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1629 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1630 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1631 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1632 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1633 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1634 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1635 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1636 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1637 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1638 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1639 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1641 TRY_CHECK(OM::remove(ian));
1644 BOOST_AUTO_TEST_CASE(test_nat) {
1646 const std::string gs = "GeorgeSimenon";
1652 std::string itf_in_name = "inside";
1653 interface itf_in(itf_in_name,
1654 interface::type_t::AFPACKET,
1655 interface::admin_state_t::UP);
1656 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1657 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1658 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1659 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1660 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1661 TRY_CHECK_RC(OM::write(gs, itf_in));
1666 std::string itf_out_name = "port-to";
1667 interface itf_out(itf_out_name,
1668 interface::type_t::AFPACKET,
1669 interface::admin_state_t::UP);
1671 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1672 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1673 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1675 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1676 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1677 TRY_CHECK_RC(OM::write(gs, itf_out));
1680 * A NAT static mapping
1682 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1683 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1685 nat_static ns(in_addr, out_addr);
1686 HW::item<bool> hw_ns(true, rc_t::OK);
1688 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1689 TRY_CHECK_RC(OM::write(gs, ns));
1692 * bind nat inside and out
1694 nat_binding *nb_in = new nat_binding(itf_in,
1697 nat_binding::zone_t::INSIDE);
1698 HW::item<bool> hw_nb_in(true, rc_t::OK);
1700 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1701 hw_ifh.data().value(),
1702 nat_binding::zone_t::INSIDE));
1703 TRY_CHECK_RC(OM::write(gs, *nb_in));
1705 nat_binding *nb_out = new nat_binding(itf_out,
1708 nat_binding::zone_t::OUTSIDE);
1709 HW::item<bool> hw_nb_out(true, rc_t::OK);
1711 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1712 hw_ifh2.data().value(),
1713 nat_binding::zone_t::OUTSIDE));
1714 TRY_CHECK_RC(OM::write(gs, *nb_out));
1720 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1721 hw_ifh.data().value(),
1722 nat_binding::zone_t::INSIDE));
1723 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1724 hw_ifh2.data().value(),
1725 nat_binding::zone_t::OUTSIDE));
1726 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1727 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1728 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1729 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1730 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1732 TRY_CHECK(OM::remove(gs));
1735 BOOST_AUTO_TEST_CASE(test_interface_events) {
1739 HW::item<bool> hw_want(true, rc_t::OK);
1741 ADD_EXPECT(interface_cmds::events_cmd(ml));
1742 cmd* itf = new interface_cmds::events_cmd(ml);
1748 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1750 const std::string rene = "ReneGoscinny";
1754 * Create an interface with two IP addresses
1756 std::string itf1_name = "host1";
1757 interface itf1(itf1_name,
1758 interface::type_t::AFPACKET,
1759 interface::admin_state_t::UP);
1760 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1761 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1762 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1763 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1764 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1765 TRY_CHECK_RC(OM::write(rene, itf1));
1767 route::prefix_t pfx_10("10.10.10.10", 24);
1768 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1769 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1770 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1771 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1772 TRY_CHECK_RC(OM::write(rene, *l3_1));
1774 route::prefix_t pfx_11("10.10.11.11", 24);
1775 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1776 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1777 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1778 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1779 TRY_CHECK_RC(OM::write(rene, *l3_2));
1782 HW::item<bool> hw_rd_create(true, rc_t::OK);
1783 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1784 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1785 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1786 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1787 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1788 TRY_CHECK_RC(OM::write(rene, rd));
1791 * update the interface to change to a new route-domain
1792 * expect that the l3-bindings are removed and readded.
1794 interface *itf2 = new interface(itf1_name,
1795 interface::type_t::AFPACKET,
1796 interface::admin_state_t::UP,
1798 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1799 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1800 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1801 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1802 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1803 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1804 TRY_CHECK_RC(OM::write(rene, *itf2));
1807 * mve the interface back to the default route-domain
1809 interface itf3(itf1_name,
1810 interface::type_t::AFPACKET,
1811 interface::admin_state_t::UP);
1812 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1813 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1814 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1815 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1816 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1817 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1818 TRY_CHECK_RC(OM::write(rene, itf3));
1825 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1826 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1827 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1828 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1829 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1830 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1832 TRY_CHECK(OM::remove(rene));
1835 BOOST_AUTO_TEST_CASE(test_prefixes) {
1836 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1838 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1840 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1842 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1843 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1845 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1846 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1847 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1849 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1851 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1853 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1855 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1856 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1857 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1859 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1861 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1862 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1863 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1865 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1867 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1868 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1869 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1873 BOOST_AUTO_TEST_CASE(test_pipes) {
1875 const std::string gk = "GKChesterton";
1877 const std::string pipe_name_1 = "pipe1";
1878 VOM::pipe pipe1(1, interface::admin_state_t::UP);
1879 HW::item<handle_t> hw_hdl(4, rc_t::OK);
1880 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
1882 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
1884 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1886 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
1887 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
1888 TRY_CHECK_RC(OM::write(gk, pipe1));
1890 pipe1.set_ends(hw_hdl_pair.data());
1892 // put each end of the pipe in a BD
1893 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1894 bridge_domain::arp_term_mode_t::OFF,
1895 bridge_domain::flood_mode_t::OFF,
1896 bridge_domain::mac_age_mode_t::ON);
1898 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1899 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1900 bridge_domain::learning_mode_t::OFF,
1901 bridge_domain::arp_term_mode_t::OFF,
1902 bridge_domain::flood_mode_t::OFF,
1903 bridge_domain::mac_age_mode_t::ON));
1905 TRY_CHECK_RC(OM::write(gk, bd1));
1907 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
1908 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
1910 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
1911 pipe1.east()->handle(),
1912 hw_bd.data(), false));
1913 TRY_CHECK_RC(OM::write(gk, *l2_1));
1915 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
1916 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
1918 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
1919 pipe1.west()->handle(),
1920 hw_bd.data(), false));
1921 TRY_CHECK_RC(OM::write(gk, *l2_2));
1927 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
1928 pipe1.east()->handle(),
1931 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
1932 pipe1.west()->handle(),
1935 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
1936 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
1937 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1938 TRY_CHECK(OM::remove(gk));
1941 BOOST_AUTO_TEST_SUITE_END()