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"
71 using namespace boost;
75 * An expectation exception
80 ExpException(unsigned int number)
82 // a neat place to add a break point
83 std::cout << " ExpException here: " << number << std::endl;
87 class MockListener : public interface::event_listener,
88 public interface::stat_listener
90 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
93 void handle_interface_event(interface_cmds::events_cmd *cmd)
98 class MockCmdQ : public HW::cmd_q
110 m_exp_queue.push_back(f);
114 m_act_queue.push_back(f);
116 void enqueue(std::queue<cmd*> &cmds)
120 m_act_queue.push_back(cmds.front());
124 void enqueue(std::shared_ptr<cmd> f)
126 m_act_queue.push_back(f.get());
133 void dequeue(std::shared_ptr<cmd> cmd)
137 void strict_order(bool on)
144 return ((0 == m_exp_queue.size()) &&
145 (0 == m_act_queue.size()));
153 while (m_act_queue.size())
155 bool matched = false;
156 auto it_exp = m_exp_queue.begin();
157 auto it_act = m_act_queue.begin();
161 std::cout << " Act: " << f_act->to_string() << std::endl;
162 while (it_exp != m_exp_queue.end())
167 std::cout << " Exp: " << f_exp->to_string() << std::endl;
169 if (typeid(*f_exp) != typeid(*f_act))
171 throw ExpException(1);
174 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
176 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
178 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
180 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
182 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
184 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
186 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
188 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
190 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
192 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
194 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
196 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
198 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
200 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
202 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
204 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
206 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
208 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
210 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
212 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
214 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
216 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
218 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
220 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
222 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
224 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
226 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
228 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
230 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
232 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
234 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
236 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
238 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
240 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
242 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
244 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
246 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
248 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
250 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
252 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
254 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
256 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
258 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
260 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
262 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
264 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
266 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
268 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
270 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
272 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
274 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
276 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
278 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
280 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
282 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
284 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
286 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
288 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
290 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
292 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
294 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
296 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
298 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
300 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
302 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
304 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
306 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
308 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
310 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
312 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
314 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
316 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
318 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
320 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
322 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
324 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
326 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
328 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
330 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
332 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
334 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
336 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
338 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
340 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
342 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
344 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
346 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
348 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
350 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
352 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
354 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
356 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
358 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
360 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
362 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
364 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
366 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
368 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
370 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
372 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
374 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
376 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
378 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
380 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
382 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
384 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
386 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
388 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
390 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
392 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
394 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
396 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
398 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
400 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
402 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
404 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
406 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
408 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
410 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
412 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
414 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
416 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
418 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
420 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
422 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
424 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
426 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
428 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
432 throw ExpException(2);
435 // if we get here then we found the match.
436 m_exp_queue.erase(it_exp);
437 m_act_queue.erase(it_act);
441 // return any injected failures to the agent
442 if (rc_t::OK != rc && rc_t::NOOP != rc)
450 catch (ExpException &e)
452 // The expected and actual do not match
455 // in strict ordering mode this is fatal, so rethrow
460 // move the iterator onto the next in the expected list and
468 throw ExpException(3);
475 template <typename T>
476 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
481 i_exp = dynamic_cast<const T*>(f_exp);
482 i_act = dynamic_cast<T*>(f_act);
483 if (!(*i_exp == *i_act))
485 throw ExpException(4);
487 // pass the data and return code to the agent
488 i_act->item() = i_exp->item();
490 return (i_act->item().rc());
493 // The Q to push the expectations on
494 std::deque<cmd*> m_exp_queue;
496 // the queue to push the actual events on
497 std::deque<cmd*> m_act_queue;
499 // control whether the expected queue is strictly ordered.
514 logger().set(log_level_t::DEBUG);
522 BOOST_AUTO_TEST_SUITE(vom)
524 #define TRY_CHECK_RC(stmt) \
527 BOOST_CHECK(rc_t::OK == stmt); \
529 catch (ExpException &e) \
531 BOOST_CHECK(false); \
533 BOOST_CHECK(vi.f->is_empty()); \
536 #define TRY_CHECK(stmt) \
541 catch (ExpException &e) \
543 BOOST_CHECK(false); \
545 BOOST_CHECK(vi.f->is_empty()); \
548 #define ADD_EXPECT(stmt) \
549 vi.f->expect(new stmt)
551 #define STRICT_ORDER_OFF() \
552 vi.f->strict_order(false)
554 BOOST_AUTO_TEST_CASE(test_interface) {
556 const std::string go = "GeorgeOrwell";
557 const std::string js = "JohnSteinbeck";
561 * George creates and deletes the interface
563 std::string itf1_name = "afpacket1";
564 interface itf1(itf1_name,
565 interface::type_t::AFPACKET,
566 interface::admin_state_t::UP);
569 * set the expectation for a afpacket interface create.
570 * 2 is the interface handle VPP [mock] assigns
572 HW::item<handle_t> hw_ifh(2, rc_t::OK);
573 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
575 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
576 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
578 TRY_CHECK_RC(OM::write(go, itf1));
580 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
581 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
582 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
584 TRY_CHECK(OM::remove(go));
587 * George creates the interface, then John brings it down.
588 * George's remove is a no-op, sice John also owns the interface
590 interface itf1b(itf1_name,
591 interface::type_t::AFPACKET,
592 interface::admin_state_t::DOWN);
594 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
595 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
596 TRY_CHECK_RC(OM::write(go, itf1));
598 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
599 TRY_CHECK_RC(OM::write(js, itf1b));
601 TRY_CHECK(OM::remove(go));
603 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
604 TRY_CHECK(OM::remove(js));
607 * George adds an interface, then we flush all of Geroge's state
609 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
610 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
611 TRY_CHECK_RC(OM::write(go, itf1));
613 TRY_CHECK(OM::mark(go));
615 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
616 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
617 TRY_CHECK(OM::sweep(go));
620 * George adds an interface. mark stale. update the same interface. sweep
621 * and expect no delete
623 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
624 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
625 TRY_CHECK_RC(OM::write(go, itf1b));
627 TRY_CHECK(OM::mark(go));
629 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
630 TRY_CHECK_RC(OM::write(go, itf1));
632 TRY_CHECK(OM::sweep(go));
634 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
635 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
636 TRY_CHECK(OM::remove(go));
639 * George adds an insterface, then we mark that state. Add a second interface
640 * an flush the first that is now stale.
642 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
643 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
644 TRY_CHECK_RC(OM::write(go, itf1));
646 TRY_CHECK(OM::mark(go));
648 std::string itf2_name = "afpacket2";
649 std::string itf2_tag = "uuid-of-afpacket2-interface";
650 interface itf2(itf2_name,
651 interface::type_t::AFPACKET,
652 interface::admin_state_t::UP,
654 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
656 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
657 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
658 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
659 TRY_CHECK_RC(OM::write(go, itf2));
661 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
662 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
663 TRY_CHECK(OM::sweep(go));
665 TRY_CHECK(OM::mark(go));
667 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
668 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
669 TRY_CHECK(OM::sweep(go));
672 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
673 std::string itf3_tag = "uuid-of-vhost_user1-interface";
674 interface itf3(itf3_name,
675 interface::type_t::VHOST,
676 interface::admin_state_t::UP,
678 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
680 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
681 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
682 TRY_CHECK_RC(OM::write(go, itf3));
684 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
685 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
686 TRY_CHECK(OM::remove(go));
689 BOOST_AUTO_TEST_CASE(test_bvi) {
691 const std::string ernest = "ErnestHemmingway";
692 const std::string graham = "GrahamGreene";
696 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
698 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
702 * Enrest creates a BVI with address 10.10.10.10/24
704 route::prefix_t pfx_10("10.10.10.10", 24);
706 const std::string bvi_name = "bvi1";
707 interface itf(bvi_name,
708 interface::type_t::BVI,
709 interface::admin_state_t::UP);
710 HW::item<handle_t> hw_ifh(4, rc_t::OK);
711 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
713 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
714 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
715 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
716 TRY_CHECK_RC(OM::write(ernest, itf));
718 l3 = new l3_binding(itf, pfx_10);
719 HW::item<bool> hw_l3_bind(true, rc_t::OK);
720 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
721 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
722 TRY_CHECK_RC(OM::write(ernest, *l3));
724 // change the MAC address on the BVI
725 interface itf_new_mac(bvi_name,
726 interface::type_t::BVI,
727 interface::admin_state_t::UP);
728 l2_address_t l2_addr({0,1,2,3,4,5});
729 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
730 itf_new_mac.set(l2_addr);
731 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
732 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
734 // create/write the interface to the OM again but with an unset MAC
735 // this should not generate a MAC address update
736 TRY_CHECK_RC(OM::write(ernest, itf));
738 // change the MAC address on the BVI - again
739 interface itf_new_mac2(bvi_name,
740 interface::type_t::BVI,
741 interface::admin_state_t::UP);
742 l2_address_t l2_addr2({0,1,2,3,4,6});
743 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
744 itf_new_mac2.set(l2_addr2);
745 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
746 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
749 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
750 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
751 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
752 TRY_CHECK(OM::remove(ernest));
755 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
758 HW::item<bool> hw_rd4_create(true, rc_t::OK);
759 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
760 HW::item<bool> hw_rd6_create(true, rc_t::OK);
761 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
762 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
763 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
764 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
765 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
766 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
767 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
768 TRY_CHECK_RC(OM::write(graham, rd));
770 const std::string bvi2_name = "bvi2";
771 interface *itf2 = new interface(bvi2_name,
772 interface::type_t::BVI,
773 interface::admin_state_t::UP,
775 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
777 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
778 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
779 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
780 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
781 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
783 TRY_CHECK_RC(OM::write(graham, *itf2));
785 l3 = new l3_binding(*itf2, pfx_10);
786 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
787 TRY_CHECK_RC(OM::write(graham, *l3));
792 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
793 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
794 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
795 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
796 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
797 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
798 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
799 TRY_CHECK(OM::remove(graham));
802 BOOST_AUTO_TEST_CASE(test_bond) {
804 const std::string cb = "CarolBerg";
808 * creates the interfaces
810 std::string itf1_name = "afpacket1";
811 interface itf1(itf1_name,
812 interface::type_t::AFPACKET,
813 interface::admin_state_t::UP);
815 HW::item<handle_t> hw_ifh(2, rc_t::OK);
816 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
818 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
819 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
821 TRY_CHECK_RC(OM::write(cb, itf1));
823 std::string itf2_name = "afpacket2";
824 interface itf2(itf2_name,
825 interface::type_t::AFPACKET,
826 interface::admin_state_t::UP);
829 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
830 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
831 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
833 TRY_CHECK_RC(OM::write(cb, itf2));
835 std::string bond_name = "bond";
836 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
837 bond_interface::mode_t::LACP);
839 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
840 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
841 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
842 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
844 TRY_CHECK_RC(OM::write(cb, bond_itf));
846 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
847 bond_member::rate_t::SLOW);
848 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
849 bond_member::rate_t::SLOW);
850 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
852 HW::item<bool> bond_hw_bind(true, rc_t::OK);
853 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
854 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
856 TRY_CHECK_RC(OM::write(cb, *bgb));
863 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
864 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
865 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
866 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
867 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
868 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
869 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
870 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
871 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
873 TRY_CHECK(OM::remove(cb));
876 BOOST_AUTO_TEST_CASE(test_bridge) {
878 const std::string franz = "FranzKafka";
879 const std::string dante = "Dante";
880 const std::string jkr = "jkrowling";
884 * Franz creates an interface, Bridge-domain, then binds the two
888 std::string itf1_name = "afpacket1";
889 interface itf1(itf1_name,
890 interface::type_t::AFPACKET,
891 interface::admin_state_t::UP);
893 HW::item<handle_t> hw_ifh(3, rc_t::OK);
894 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
896 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
897 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
899 TRY_CHECK_RC(OM::write(franz, itf1));
901 // bridge-domain create
902 bridge_domain bd1(33);
904 HW::item<uint32_t> hw_bd(33, rc_t::OK);
905 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
906 bridge_domain::learning_mode_t::ON,
907 bridge_domain::arp_term_mode_t::ON,
908 bridge_domain::flood_mode_t::ON,
909 bridge_domain::mac_age_mode_t::OFF));
911 TRY_CHECK_RC(OM::write(franz, bd1));
913 // L2-interface create and bind
914 // this needs to be delete'd before the flush below, since it too maintains
915 // references to the BD and Interface
916 l2_binding *l2itf = new l2_binding(itf1, bd1);
917 HW::item<bool> hw_l2_bind(true, rc_t::OK);
919 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
920 TRY_CHECK_RC(OM::write(franz, *l2itf));
923 * Dante adds an interface to the same BD
925 std::string itf2_name = "afpacket2";
926 interface itf2(itf2_name,
927 interface::type_t::AFPACKET,
928 interface::admin_state_t::UP);
930 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
931 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
932 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
933 TRY_CHECK_RC(OM::write(dante, itf2));
935 // BD add is a no-op since it exists
936 TRY_CHECK_RC(OM::write(dante, bd1));
938 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
939 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
940 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
942 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
943 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
944 TRY_CHECK_RC(OM::write(dante, *l2itf2));
946 // Add some static entries to the bridge-domain
947 HW::item<bool> hw_be1(true, rc_t::OK);
948 mac_address_t mac1({0,1,2,3,4,5});
949 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
950 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
952 TRY_CHECK_RC(OM::write(dante, *be1));
954 // Add some entries to the bridge-domain ARP termination table
955 HW::item<bool> hw_bea1(true, rc_t::OK);
956 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
958 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
959 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
960 TRY_CHECK_RC(OM::write(dante, *bea1));
962 // flush Franz's state
964 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
966 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
967 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
968 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
969 TRY_CHECK(OM::remove(franz));
971 // flush Dante's state - the order the interface and BD are deleted
972 // is an uncontrollable artifact of the C++ object destruction.
977 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
978 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
979 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
981 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
982 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
983 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
984 TRY_CHECK(OM::remove(dante));
986 // test the BVI entry in l2fib
987 bridge_domain bd2(99);
989 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
990 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
991 bridge_domain::learning_mode_t::ON,
992 bridge_domain::arp_term_mode_t::ON,
993 bridge_domain::flood_mode_t::ON,
994 bridge_domain::mac_age_mode_t::OFF));
996 TRY_CHECK_RC(OM::write(jkr, bd2));
998 std::string itf3_name = "bvi";
999 interface itf3(itf3_name,
1000 interface::type_t::BVI,
1001 interface::admin_state_t::UP);
1003 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1004 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1005 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1006 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1007 TRY_CHECK_RC(OM::write(jkr, itf3));
1009 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1010 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1011 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1013 HW::item<bool> hw_be2(true, rc_t::OK);
1014 mac_address_t mac2({0,1,2,3,4,5});
1015 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1016 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1017 TRY_CHECK_RC(OM::write(jkr, *be2));
1022 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1023 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1024 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1025 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1026 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1027 TRY_CHECK(OM::remove(jkr));
1030 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1032 const std::string nicholas = "NicholasAbercrombie";
1038 std::string itf1_name = "host1";
1039 interface itf1(itf1_name,
1040 interface::type_t::AFPACKET,
1041 interface::admin_state_t::UP);
1042 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1043 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1044 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1045 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1046 TRY_CHECK_RC(OM::write(nicholas, itf1));
1051 std::string itf2_name = "host2";
1052 interface itf2(itf2_name,
1053 interface::type_t::AFPACKET,
1054 interface::admin_state_t::UP);
1056 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1057 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1058 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1059 TRY_CHECK_RC(OM::write(nicholas, itf2));
1061 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1062 HW::item<bool> xconnect_east(true, rc_t::OK);
1063 HW::item<bool> xconnect_west(true, rc_t::OK);
1064 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1065 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1066 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1067 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1068 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1072 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1074 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1075 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1076 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1077 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1078 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1079 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1081 TRY_CHECK(OM::remove(nicholas));
1084 BOOST_AUTO_TEST_CASE(test_vxlan) {
1086 const std::string franz = "FranzKafka";
1090 * Franz creates an interface, Bridge-domain, then binds the two
1094 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1095 boost::asio::ip::address::from_string("10.10.10.11"),
1098 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1100 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1101 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
1103 TRY_CHECK_RC(OM::write(franz, vxt));
1105 // bridge-domain create
1106 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1107 bridge_domain::arp_term_mode_t::OFF,
1108 bridge_domain::flood_mode_t::OFF,
1109 bridge_domain::mac_age_mode_t::ON);
1111 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1112 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1113 bridge_domain::learning_mode_t::OFF,
1114 bridge_domain::arp_term_mode_t::OFF,
1115 bridge_domain::flood_mode_t::OFF,
1116 bridge_domain::mac_age_mode_t::ON));
1118 TRY_CHECK_RC(OM::write(franz, bd1));
1120 // L2-interface create and bind
1121 // this needs to be delete'd before the flush below, since it too maintains
1122 // references to the BD and Interface
1123 l2_binding *l2itf = new l2_binding(vxt, bd1);
1124 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1126 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1127 TRY_CHECK_RC(OM::write(franz, *l2itf));
1129 // flush Franz's state
1131 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1133 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1134 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1135 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1136 TRY_CHECK(OM::remove(franz));
1139 BOOST_AUTO_TEST_CASE(test_vlan) {
1141 const std::string noam = "NoamChomsky";
1144 std::string itf1_name = "host1";
1145 interface itf1(itf1_name,
1146 interface::type_t::AFPACKET,
1147 interface::admin_state_t::UP);
1149 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1150 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1152 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1153 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1155 TRY_CHECK_RC(OM::write(noam, itf1));
1157 sub_interface *vl33 = new sub_interface(itf1,
1158 interface::admin_state_t::UP,
1161 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1162 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1163 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1165 TRY_CHECK_RC(OM::write(noam, *vl33));
1168 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1169 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1170 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1171 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1172 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1173 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1175 TRY_CHECK(OM::remove(noam));
1178 BOOST_AUTO_TEST_CASE(test_acl) {
1180 const std::string fyodor = "FyodorDostoyevsky";
1181 const std::string leo = "LeoTolstoy";
1185 * Fyodor adds an ACL in the input direction
1187 std::string itf1_name = "host1";
1188 interface itf1(itf1_name,
1189 interface::type_t::AFPACKET,
1190 interface::admin_state_t::UP);
1191 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1192 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1193 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1194 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1195 TRY_CHECK_RC(OM::write(fyodor, itf1));
1197 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1198 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1199 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1200 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1201 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1202 HW::item<bool> ae_binding(true, rc_t::OK);
1203 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1204 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1206 route::prefix_t src("10.10.10.10", 32);
1207 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1208 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1210 std::string acl_name = "acl1";
1211 ACL::l3_list acl1(acl_name);
1214 ACL::l3_list::rules_t rules = {r1, r2};
1216 HW::item<handle_t> hw_acl(2, rc_t::OK);
1217 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1218 TRY_CHECK_RC(OM::write(fyodor, acl1));
1220 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1221 ACL::l3_list acl2(acl_name);
1223 ACL::l3_list::rules_t rules2 = {r3};
1224 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1225 TRY_CHECK_RC(OM::write(fyodor, acl2));
1227 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1228 HW::item<bool> hw_binding(true, rc_t::OK);
1229 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1230 hw_ifh.data(), hw_acl.data()));
1231 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1234 * Leo adds an L2 ACL in the output direction
1236 TRY_CHECK_RC(OM::write(leo, itf1));
1238 std::string l2_acl_name = "l2_acl1";
1239 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1240 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1241 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1242 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1244 ACL::l2_list l2_acl(l2_acl_name);
1245 l2_acl.insert(l2_r2);
1246 l2_acl.insert(l2_r1);
1248 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1250 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1251 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1252 TRY_CHECK_RC(OM::write(leo, l2_acl));
1254 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1255 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1256 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1257 hw_ifh.data(), l2_hw_acl.data()));
1258 TRY_CHECK_RC(OM::write(leo, *l2b));
1261 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1262 hw_ifh.data(), l2_hw_acl.data()));
1263 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1264 TRY_CHECK(OM::remove(leo));
1268 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1271 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1272 hw_ifh.data(), hw_acl.data()));
1273 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1274 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1275 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1276 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1278 TRY_CHECK(OM::remove(fyodor));
1281 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1283 const std::string kurt = "KurtVonnegut";
1286 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1287 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1289 arp_proxy_config ap(low, high);
1290 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1291 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1292 TRY_CHECK_RC(OM::write(kurt, ap));
1294 std::string itf3_name = "host3";
1295 interface itf3(itf3_name,
1296 interface::type_t::AFPACKET,
1297 interface::admin_state_t::UP);
1298 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1299 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1300 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1301 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1302 TRY_CHECK_RC(OM::write(kurt, itf3));
1304 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1305 HW::item<bool> hw_binding(true, rc_t::OK);
1306 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1307 TRY_CHECK_RC(OM::write(kurt, *apb));
1311 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1314 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1315 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1316 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1317 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1319 TRY_CHECK(OM::remove(kurt));
1322 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1324 const std::string eric = "EricAmbler";
1328 * Interface 1 has the L3 address
1330 std::string itf1_name = "host1";
1331 interface itf1(itf1_name,
1332 interface::type_t::AFPACKET,
1333 interface::admin_state_t::UP);
1334 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1335 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1336 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1337 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1338 TRY_CHECK_RC(OM::write(eric, itf1));
1340 route::prefix_t pfx_10("10.10.10.10", 24);
1341 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1342 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1343 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1344 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1345 TRY_CHECK_RC(OM::write(eric, *l3));
1348 * Interface 2 is unnumbered
1350 std::string itf2_name = "host2";
1351 interface itf2(itf2_name,
1352 interface::type_t::AFPACKET,
1353 interface::admin_state_t::UP);
1355 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1356 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1357 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1358 TRY_CHECK_RC(OM::write(eric, itf2));
1360 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1361 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1362 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1363 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1364 TRY_CHECK_RC(OM::write(eric, *ipun));
1369 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1371 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1372 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1373 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1374 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1375 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1376 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1378 TRY_CHECK(OM::remove(eric));
1381 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1383 const std::string paulo = "PauloCoelho";
1389 std::string itf_name = "host_ip6nd";
1390 interface itf(itf_name,
1391 interface::type_t::AFPACKET,
1392 interface::admin_state_t::UP);
1393 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1394 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1395 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1396 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1397 TRY_CHECK_RC(OM::write(paulo, itf));
1399 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1400 l3_binding *l3 = new l3_binding(itf, pfx_10);
1401 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1402 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1403 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1404 TRY_CHECK_RC(OM::write(paulo, *l3));
1406 ra_config ra(0, 1, 0, 4);
1407 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1408 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1409 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1410 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1411 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1416 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1417 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1418 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1419 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1420 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1421 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1425 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1430 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1433 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1434 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1435 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1436 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1438 TRY_CHECK(OM::remove(paulo));
1441 BOOST_AUTO_TEST_CASE(test_interface_span) {
1443 const std::string elif = "ElifShafak";
1447 * Interface 1 to be mirrored
1449 std::string itf1_name = "port-from";
1450 interface itf1(itf1_name,
1451 interface::type_t::AFPACKET,
1452 interface::admin_state_t::UP);
1453 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1454 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1455 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1456 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1457 TRY_CHECK_RC(OM::write(elif, itf1));
1460 * Interface 2 where traffic is mirrored
1462 std::string itf2_name = "port-to";
1463 interface itf2(itf2_name,
1464 interface::type_t::AFPACKET,
1465 interface::admin_state_t::UP);
1467 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1468 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1470 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1471 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1472 TRY_CHECK_RC(OM::write(elif, itf2));
1474 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1475 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1476 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1477 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1478 TRY_CHECK_RC(OM::write(elif, *itf_span));
1480 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1481 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1485 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1486 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1487 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1488 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1489 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1491 TRY_CHECK(OM::remove(elif));
1494 BOOST_AUTO_TEST_CASE(test_routing) {
1496 const std::string ian = "IanFleming";
1500 * non-default route domain
1502 route_domain rd4(1);
1503 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1504 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1505 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1506 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1507 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1508 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1509 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1510 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1511 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1512 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1513 TRY_CHECK_RC(OM::write(ian, rd4));
1516 * a couple of interfaces
1518 std::string itf1_name = "af1";
1519 interface itf1(itf1_name,
1520 interface::type_t::AFPACKET,
1521 interface::admin_state_t::UP);
1522 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1523 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1524 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1525 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1526 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1527 TRY_CHECK_RC(OM::write(ian, itf1));
1529 std::string itf2_name = "af2";
1530 interface *itf2 = new interface(itf2_name,
1531 interface::type_t::AFPACKET,
1532 interface::admin_state_t::UP,
1535 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1536 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1537 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1538 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1539 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1540 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1541 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1542 TRY_CHECK_RC(OM::write(ian, *itf2));
1545 * prefix on each interface
1547 route::prefix_t pfx_10("10.10.10.10", 24);
1548 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1549 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1550 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1551 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1552 TRY_CHECK_RC(OM::write(ian, *l3_10));
1553 route::prefix_t pfx_11("11.11.11.11", 24);
1554 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1555 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1556 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1557 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1558 TRY_CHECK_RC(OM::write(ian, *l3_11));
1561 * A route via interface 1 in the default table
1563 route::prefix_t pfx_5("5.5.5.5", 32);
1564 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1565 route::path *path_10 = new route::path(nh_10, itf1);
1566 route::ip_route *route_5 = new route::ip_route(pfx_5);
1567 route_5->add(*path_10);
1568 HW::item<bool> hw_route_5(true, rc_t::OK);
1569 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
1570 TRY_CHECK_RC(OM::write(ian, *route_5));
1573 * A route via interface 2 in the non-default table
1575 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1576 route::path *path_11 = new route::path(nh_11, *itf2);
1577 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1578 route_5_2->add(*path_11);
1579 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1580 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
1581 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1584 * An ARP entry for the neighbour on itf1
1586 HW::item<bool> hw_neighbour(true, rc_t::OK);
1587 mac_address_t mac_n({0,1,2,4,5,6});
1588 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1589 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1590 TRY_CHECK_RC(OM::write(ian, *ne));
1595 route::prefix_t pfx_6("6.6.6.6", 32);
1596 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1597 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1598 route_dvr->add(*path_l2);
1599 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1600 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
1601 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1604 // delete the stack objects that hold references to others
1605 // so the OM::remove is the call that removes the last reference
1616 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1617 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1618 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1619 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1620 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1621 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1622 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1623 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1624 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1625 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1626 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1627 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1628 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1629 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1631 TRY_CHECK(OM::remove(ian));
1634 BOOST_AUTO_TEST_CASE(test_nat) {
1636 const std::string gs = "GeorgeSimenon";
1642 std::string itf_in_name = "inside";
1643 interface itf_in(itf_in_name,
1644 interface::type_t::AFPACKET,
1645 interface::admin_state_t::UP);
1646 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1647 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1648 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1649 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1650 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1651 TRY_CHECK_RC(OM::write(gs, itf_in));
1656 std::string itf_out_name = "port-to";
1657 interface itf_out(itf_out_name,
1658 interface::type_t::AFPACKET,
1659 interface::admin_state_t::UP);
1661 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1662 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1663 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1665 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1666 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1667 TRY_CHECK_RC(OM::write(gs, itf_out));
1670 * A NAT static mapping
1672 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1673 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1675 nat_static ns(in_addr, out_addr);
1676 HW::item<bool> hw_ns(true, rc_t::OK);
1678 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1679 TRY_CHECK_RC(OM::write(gs, ns));
1682 * bind nat inside and out
1684 nat_binding *nb_in = new nat_binding(itf_in,
1687 nat_binding::zone_t::INSIDE);
1688 HW::item<bool> hw_nb_in(true, rc_t::OK);
1690 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1691 hw_ifh.data().value(),
1692 nat_binding::zone_t::INSIDE));
1693 TRY_CHECK_RC(OM::write(gs, *nb_in));
1695 nat_binding *nb_out = new nat_binding(itf_out,
1698 nat_binding::zone_t::OUTSIDE);
1699 HW::item<bool> hw_nb_out(true, rc_t::OK);
1701 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1702 hw_ifh2.data().value(),
1703 nat_binding::zone_t::OUTSIDE));
1704 TRY_CHECK_RC(OM::write(gs, *nb_out));
1710 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1711 hw_ifh.data().value(),
1712 nat_binding::zone_t::INSIDE));
1713 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1714 hw_ifh2.data().value(),
1715 nat_binding::zone_t::OUTSIDE));
1716 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1717 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1718 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1719 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1720 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1722 TRY_CHECK(OM::remove(gs));
1725 BOOST_AUTO_TEST_CASE(test_interface_events) {
1729 HW::item<bool> hw_want(true, rc_t::OK);
1731 ADD_EXPECT(interface_cmds::events_cmd(ml));
1732 cmd* itf = new interface_cmds::events_cmd(ml);
1738 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1740 const std::string rene = "ReneGoscinny";
1744 * Create an interface with two IP addresses
1746 std::string itf1_name = "host1";
1747 interface itf1(itf1_name,
1748 interface::type_t::AFPACKET,
1749 interface::admin_state_t::UP);
1750 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1751 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1752 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1753 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1754 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1755 TRY_CHECK_RC(OM::write(rene, itf1));
1757 route::prefix_t pfx_10("10.10.10.10", 24);
1758 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1759 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1760 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1761 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1762 TRY_CHECK_RC(OM::write(rene, *l3_1));
1764 route::prefix_t pfx_11("10.10.11.11", 24);
1765 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1766 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1767 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1768 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1769 TRY_CHECK_RC(OM::write(rene, *l3_2));
1772 HW::item<bool> hw_rd_create(true, rc_t::OK);
1773 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1774 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1775 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1776 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1777 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1778 TRY_CHECK_RC(OM::write(rene, rd));
1781 * update the interface to change to a new route-domain
1782 * expect that the l3-bindings are removed and readded.
1784 interface *itf2 = new interface(itf1_name,
1785 interface::type_t::AFPACKET,
1786 interface::admin_state_t::UP,
1788 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1789 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1790 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1791 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1792 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1793 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1794 TRY_CHECK_RC(OM::write(rene, *itf2));
1797 * mve the interface back to the default route-domain
1799 interface itf3(itf1_name,
1800 interface::type_t::AFPACKET,
1801 interface::admin_state_t::UP);
1802 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1803 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1804 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1805 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1806 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1807 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1808 TRY_CHECK_RC(OM::write(rene, itf3));
1815 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1816 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1817 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1818 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1819 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1820 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1822 TRY_CHECK(OM::remove(rene));
1825 BOOST_AUTO_TEST_CASE(test_prefixes) {
1826 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1828 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1830 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1832 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1833 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1835 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1836 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1837 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1839 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1841 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1843 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1845 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1846 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1847 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1849 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1851 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1852 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1853 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1855 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1857 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1858 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1859 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1863 BOOST_AUTO_TEST_SUITE_END()