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_punt_redirect.hpp"
60 #include "vom/ip_punt_redirect_cmds.hpp"
61 #include "vom/ip_unnumbered.hpp"
62 #include "vom/ip_unnumbered_cmds.hpp"
63 #include "vom/interface_ip6_nd.hpp"
64 #include "vom/interface_span.hpp"
65 #include "vom/interface_span_cmds.hpp"
66 #include "vom/neighbour.hpp"
67 #include "vom/neighbour_cmds.hpp"
68 #include "vom/nat_static.hpp"
69 #include "vom/nat_static_cmds.hpp"
70 #include "vom/nat_binding.hpp"
71 #include "vom/nat_binding_cmds.hpp"
72 #include "vom/pipe.hpp"
73 #include "vom/pipe_cmds.hpp"
75 using namespace boost;
79 * An expectation exception
84 ExpException(unsigned int number)
86 // a neat place to add a break point
87 std::cout << " ExpException here: " << number << std::endl;
91 class MockListener : public interface::event_listener,
92 public interface::stat_listener
94 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
97 void handle_interface_event(interface_cmds::events_cmd *cmd)
102 class MockCmdQ : public HW::cmd_q
114 m_exp_queue.push_back(f);
118 m_act_queue.push_back(f);
120 void enqueue(std::queue<cmd*> &cmds)
124 m_act_queue.push_back(cmds.front());
128 void enqueue(std::shared_ptr<cmd> f)
130 m_act_queue.push_back(f.get());
137 void dequeue(std::shared_ptr<cmd> cmd)
141 void strict_order(bool on)
148 return ((0 == m_exp_queue.size()) &&
149 (0 == m_act_queue.size()));
157 while (m_act_queue.size())
159 bool matched = false;
160 auto it_exp = m_exp_queue.begin();
161 auto it_act = m_act_queue.begin();
165 std::cout << " Act: " << f_act->to_string() << std::endl;
166 while (it_exp != m_exp_queue.end())
171 std::cout << " Exp: " << f_exp->to_string() << std::endl;
173 if (typeid(*f_exp) != typeid(*f_act))
175 throw ExpException(1);
178 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
180 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
182 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
184 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
186 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
188 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
190 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
192 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
194 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
196 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
198 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
200 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
202 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
204 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
206 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
208 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
210 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
212 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
214 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
216 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
218 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
220 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
222 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
224 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
226 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
228 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
230 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
232 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
234 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
236 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
238 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
240 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
242 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
244 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
246 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
248 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
250 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
252 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
254 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
256 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
258 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
260 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
262 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
264 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
266 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
268 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
270 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
272 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
274 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
276 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
278 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
280 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
282 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
284 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
286 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
288 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
290 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
292 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
294 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
296 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
298 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
300 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
302 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
304 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
306 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
308 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
310 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
312 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
314 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
316 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
318 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
320 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
322 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
324 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
326 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
328 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
330 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
332 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
334 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
336 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
338 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
340 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
342 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
344 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
346 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
348 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
350 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
352 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
354 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
356 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
358 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
360 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
362 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
364 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
366 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
368 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
370 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
372 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
374 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
376 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
378 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
380 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
382 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
384 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
386 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
388 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
390 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
392 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
394 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
396 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
398 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
400 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
402 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
404 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
406 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
408 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
410 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
412 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
414 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
416 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
418 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
420 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
422 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
424 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
426 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
428 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
430 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
432 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
434 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
436 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
438 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
440 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
442 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
444 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
446 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
448 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
452 throw ExpException(2);
455 // if we get here then we found the match.
456 m_exp_queue.erase(it_exp);
457 m_act_queue.erase(it_act);
461 // return any injected failures to the agent
462 if (rc_t::OK != rc && rc_t::NOOP != rc)
470 catch (ExpException &e)
472 // The expected and actual do not match
475 // in strict ordering mode this is fatal, so rethrow
480 // move the iterator onto the next in the expected list and
488 throw ExpException(3);
495 template <typename T>
496 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
501 i_exp = dynamic_cast<const T*>(f_exp);
502 i_act = dynamic_cast<T*>(f_act);
503 if (!(*i_exp == *i_act))
505 throw ExpException(4);
507 // pass the data and return code to the agent
508 i_act->item() = i_exp->item();
510 return (i_act->item().rc());
513 // The Q to push the expectations on
514 std::deque<cmd*> m_exp_queue;
516 // the queue to push the actual events on
517 std::deque<cmd*> m_act_queue;
519 // control whether the expected queue is strictly ordered.
534 logger().set(log_level_t::DEBUG);
542 BOOST_AUTO_TEST_SUITE(vom)
544 #define TRY_CHECK_RC(stmt) \
547 BOOST_CHECK(rc_t::OK == stmt); \
549 catch (ExpException &e) \
551 BOOST_CHECK(false); \
553 BOOST_CHECK(vi.f->is_empty()); \
556 #define TRY_CHECK(stmt) \
561 catch (ExpException &e) \
563 BOOST_CHECK(false); \
565 BOOST_CHECK(vi.f->is_empty()); \
568 #define ADD_EXPECT(stmt) \
569 vi.f->expect(new stmt)
571 #define STRICT_ORDER_OFF() \
572 vi.f->strict_order(false)
574 BOOST_AUTO_TEST_CASE(test_interface) {
576 const std::string go = "GeorgeOrwell";
577 const std::string js = "JohnSteinbeck";
581 * George creates and deletes the interface
583 std::string itf1_name = "afpacket1";
584 interface itf1(itf1_name,
585 interface::type_t::AFPACKET,
586 interface::admin_state_t::UP);
589 * set the expectation for a afpacket interface create.
590 * 2 is the interface handle VPP [mock] assigns
592 HW::item<handle_t> hw_ifh(2, rc_t::OK);
593 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
595 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
596 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
598 TRY_CHECK_RC(OM::write(go, itf1));
600 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
601 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
602 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
604 TRY_CHECK(OM::remove(go));
607 * George creates the interface, then John brings it down.
608 * George's remove is a no-op, sice John also owns the interface
610 interface itf1b(itf1_name,
611 interface::type_t::AFPACKET,
612 interface::admin_state_t::DOWN);
614 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
615 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
616 TRY_CHECK_RC(OM::write(go, itf1));
618 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
619 TRY_CHECK_RC(OM::write(js, itf1b));
621 TRY_CHECK(OM::remove(go));
623 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
624 TRY_CHECK(OM::remove(js));
627 * George adds an interface, then we flush all of Geroge's state
629 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
630 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
631 TRY_CHECK_RC(OM::write(go, itf1));
633 TRY_CHECK(OM::mark(go));
635 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
636 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
637 TRY_CHECK(OM::sweep(go));
640 * George adds an interface. mark stale. update the same interface. sweep
641 * and expect no delete
643 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
644 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
645 TRY_CHECK_RC(OM::write(go, itf1b));
647 TRY_CHECK(OM::mark(go));
649 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
650 TRY_CHECK_RC(OM::write(go, itf1));
652 TRY_CHECK(OM::sweep(go));
654 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
655 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
656 TRY_CHECK(OM::remove(go));
659 * George adds an insterface, then we mark that state. Add a second interface
660 * an flush the first that is now stale.
662 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
663 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
664 TRY_CHECK_RC(OM::write(go, itf1));
666 TRY_CHECK(OM::mark(go));
668 std::string itf2_name = "afpacket2";
669 std::string itf2_tag = "uuid-of-afpacket2-interface";
670 interface itf2(itf2_name,
671 interface::type_t::AFPACKET,
672 interface::admin_state_t::UP,
674 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
676 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
677 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
678 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
679 TRY_CHECK_RC(OM::write(go, itf2));
681 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
682 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
683 TRY_CHECK(OM::sweep(go));
685 TRY_CHECK(OM::mark(go));
687 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
688 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
689 TRY_CHECK(OM::sweep(go));
692 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
693 std::string itf3_tag = "uuid-of-vhost_user1-interface";
694 interface itf3(itf3_name,
695 interface::type_t::VHOST,
696 interface::admin_state_t::UP,
698 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
700 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
701 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
702 TRY_CHECK_RC(OM::write(go, itf3));
704 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
705 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
706 TRY_CHECK(OM::remove(go));
709 BOOST_AUTO_TEST_CASE(test_bvi) {
711 const std::string ernest = "ErnestHemmingway";
712 const std::string graham = "GrahamGreene";
716 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
718 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
722 * Enrest creates a BVI with address 10.10.10.10/24
724 route::prefix_t pfx_10("10.10.10.10", 24);
726 const std::string bvi_name = "bvi1";
727 interface itf(bvi_name,
728 interface::type_t::BVI,
729 interface::admin_state_t::UP);
730 HW::item<handle_t> hw_ifh(4, rc_t::OK);
731 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
733 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
734 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
735 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
736 TRY_CHECK_RC(OM::write(ernest, itf));
738 l3 = new l3_binding(itf, pfx_10);
739 HW::item<bool> hw_l3_bind(true, rc_t::OK);
740 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
741 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
742 TRY_CHECK_RC(OM::write(ernest, *l3));
744 // change the MAC address on the BVI
745 interface itf_new_mac(bvi_name,
746 interface::type_t::BVI,
747 interface::admin_state_t::UP);
748 l2_address_t l2_addr({0,1,2,3,4,5});
749 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
750 itf_new_mac.set(l2_addr);
751 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
752 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
754 // create/write the interface to the OM again but with an unset MAC
755 // this should not generate a MAC address update
756 TRY_CHECK_RC(OM::write(ernest, itf));
758 // change the MAC address on the BVI - again
759 interface itf_new_mac2(bvi_name,
760 interface::type_t::BVI,
761 interface::admin_state_t::UP);
762 l2_address_t l2_addr2({0,1,2,3,4,6});
763 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
764 itf_new_mac2.set(l2_addr2);
765 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
766 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
769 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
770 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
771 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
772 TRY_CHECK(OM::remove(ernest));
775 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
778 HW::item<bool> hw_rd4_create(true, rc_t::OK);
779 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
780 HW::item<bool> hw_rd6_create(true, rc_t::OK);
781 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
782 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
783 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
784 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
785 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
786 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
787 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
788 TRY_CHECK_RC(OM::write(graham, rd));
790 const std::string bvi2_name = "bvi2";
791 interface *itf2 = new interface(bvi2_name,
792 interface::type_t::BVI,
793 interface::admin_state_t::UP,
795 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
797 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
798 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
799 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
800 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
801 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
803 TRY_CHECK_RC(OM::write(graham, *itf2));
805 l3 = new l3_binding(*itf2, pfx_10);
806 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
807 TRY_CHECK_RC(OM::write(graham, *l3));
812 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
813 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
814 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
815 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
816 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
817 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
818 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
819 TRY_CHECK(OM::remove(graham));
822 BOOST_AUTO_TEST_CASE(test_bond) {
824 const std::string cb = "CarolBerg";
828 * creates the interfaces
830 std::string itf1_name = "afpacket1";
831 interface itf1(itf1_name,
832 interface::type_t::AFPACKET,
833 interface::admin_state_t::UP);
835 HW::item<handle_t> hw_ifh(2, rc_t::OK);
836 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
838 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
839 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
841 TRY_CHECK_RC(OM::write(cb, itf1));
843 std::string itf2_name = "afpacket2";
844 interface itf2(itf2_name,
845 interface::type_t::AFPACKET,
846 interface::admin_state_t::UP);
849 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
850 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
851 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
853 TRY_CHECK_RC(OM::write(cb, itf2));
855 std::string bond_name = "bond";
856 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
857 bond_interface::mode_t::LACP);
859 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
860 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
861 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
862 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
864 TRY_CHECK_RC(OM::write(cb, bond_itf));
866 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
867 bond_member::rate_t::SLOW);
868 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
869 bond_member::rate_t::SLOW);
870 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
872 HW::item<bool> bond_hw_bind(true, rc_t::OK);
873 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
874 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
876 TRY_CHECK_RC(OM::write(cb, *bgb));
883 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
884 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
885 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
886 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
887 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
888 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
889 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
890 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
891 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
893 TRY_CHECK(OM::remove(cb));
896 BOOST_AUTO_TEST_CASE(test_bridge) {
898 const std::string franz = "FranzKafka";
899 const std::string dante = "Dante";
900 const std::string jkr = "jkrowling";
904 * Franz creates an interface, Bridge-domain, then binds the two
908 std::string itf1_name = "afpacket1";
909 interface itf1(itf1_name,
910 interface::type_t::AFPACKET,
911 interface::admin_state_t::UP);
913 HW::item<handle_t> hw_ifh(3, rc_t::OK);
914 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
916 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
917 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
919 TRY_CHECK_RC(OM::write(franz, itf1));
921 // bridge-domain create
922 bridge_domain bd1(33);
924 HW::item<uint32_t> hw_bd(33, rc_t::OK);
925 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
926 bridge_domain::learning_mode_t::ON,
927 bridge_domain::arp_term_mode_t::ON,
928 bridge_domain::flood_mode_t::ON,
929 bridge_domain::mac_age_mode_t::OFF));
931 TRY_CHECK_RC(OM::write(franz, bd1));
933 // L2-interface create and bind
934 // this needs to be delete'd before the flush below, since it too maintains
935 // references to the BD and Interface
936 l2_binding *l2itf = new l2_binding(itf1, bd1);
937 HW::item<bool> hw_l2_bind(true, rc_t::OK);
939 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
940 TRY_CHECK_RC(OM::write(franz, *l2itf));
943 * Dante adds an interface to the same BD
945 std::string itf2_name = "afpacket2";
946 interface itf2(itf2_name,
947 interface::type_t::AFPACKET,
948 interface::admin_state_t::UP);
950 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
951 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
952 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
953 TRY_CHECK_RC(OM::write(dante, itf2));
955 // BD add is a no-op since it exists
956 TRY_CHECK_RC(OM::write(dante, bd1));
958 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
959 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
960 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
962 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
963 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
964 TRY_CHECK_RC(OM::write(dante, *l2itf2));
966 // Add some static entries to the bridge-domain
967 HW::item<bool> hw_be1(true, rc_t::OK);
968 mac_address_t mac1({0,1,2,3,4,5});
969 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
970 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
972 TRY_CHECK_RC(OM::write(dante, *be1));
974 // Add some entries to the bridge-domain ARP termination table
975 HW::item<bool> hw_bea1(true, rc_t::OK);
976 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
978 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
979 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
980 TRY_CHECK_RC(OM::write(dante, *bea1));
982 // flush Franz's state
984 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
986 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
987 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
988 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
989 TRY_CHECK(OM::remove(franz));
991 // flush Dante's state - the order the interface and BD are deleted
992 // is an uncontrollable artifact of the C++ object destruction.
997 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
998 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
999 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
1001 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1002 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1003 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1004 TRY_CHECK(OM::remove(dante));
1006 // test the BVI entry in l2fib
1007 bridge_domain bd2(99);
1009 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1010 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1011 bridge_domain::learning_mode_t::ON,
1012 bridge_domain::arp_term_mode_t::ON,
1013 bridge_domain::flood_mode_t::ON,
1014 bridge_domain::mac_age_mode_t::OFF));
1016 TRY_CHECK_RC(OM::write(jkr, bd2));
1018 std::string itf3_name = "bvi";
1019 interface itf3(itf3_name,
1020 interface::type_t::BVI,
1021 interface::admin_state_t::UP);
1023 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1024 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1025 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1026 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1027 TRY_CHECK_RC(OM::write(jkr, itf3));
1029 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1030 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1031 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1033 HW::item<bool> hw_be2(true, rc_t::OK);
1034 mac_address_t mac2({0,1,2,3,4,5});
1035 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1036 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1037 TRY_CHECK_RC(OM::write(jkr, *be2));
1042 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1043 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1044 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1045 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1046 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1047 TRY_CHECK(OM::remove(jkr));
1050 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1052 const std::string nicholas = "NicholasAbercrombie";
1058 std::string itf1_name = "host1";
1059 interface itf1(itf1_name,
1060 interface::type_t::AFPACKET,
1061 interface::admin_state_t::UP);
1062 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1063 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1064 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1065 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1066 TRY_CHECK_RC(OM::write(nicholas, itf1));
1071 std::string itf2_name = "host2";
1072 interface itf2(itf2_name,
1073 interface::type_t::AFPACKET,
1074 interface::admin_state_t::UP);
1076 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1077 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1078 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1079 TRY_CHECK_RC(OM::write(nicholas, itf2));
1081 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1082 HW::item<bool> xconnect_east(true, rc_t::OK);
1083 HW::item<bool> xconnect_west(true, rc_t::OK);
1084 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1085 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1086 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1087 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1088 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1092 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1094 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1095 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1096 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1097 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1098 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1099 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1101 TRY_CHECK(OM::remove(nicholas));
1104 BOOST_AUTO_TEST_CASE(test_vxlan) {
1106 const std::string franz = "FranzKafka";
1110 * Franz creates an interface, Bridge-domain, then binds the two
1114 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1115 boost::asio::ip::address::from_string("10.10.10.11"),
1118 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1120 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1121 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
1123 TRY_CHECK_RC(OM::write(franz, vxt));
1125 // bridge-domain create
1126 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1127 bridge_domain::arp_term_mode_t::OFF,
1128 bridge_domain::flood_mode_t::OFF,
1129 bridge_domain::mac_age_mode_t::ON);
1131 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1132 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1133 bridge_domain::learning_mode_t::OFF,
1134 bridge_domain::arp_term_mode_t::OFF,
1135 bridge_domain::flood_mode_t::OFF,
1136 bridge_domain::mac_age_mode_t::ON));
1138 TRY_CHECK_RC(OM::write(franz, bd1));
1140 // L2-interface create and bind
1141 // this needs to be delete'd before the flush below, since it too maintains
1142 // references to the BD and Interface
1143 l2_binding *l2itf = new l2_binding(vxt, bd1);
1144 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1146 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1147 TRY_CHECK_RC(OM::write(franz, *l2itf));
1149 // flush Franz's state
1151 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1153 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1154 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1155 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1156 TRY_CHECK(OM::remove(franz));
1159 BOOST_AUTO_TEST_CASE(test_vlan) {
1161 const std::string noam = "NoamChomsky";
1164 std::string itf1_name = "host1";
1165 interface itf1(itf1_name,
1166 interface::type_t::AFPACKET,
1167 interface::admin_state_t::UP);
1169 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1170 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1172 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1173 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1175 TRY_CHECK_RC(OM::write(noam, itf1));
1177 sub_interface *vl33 = new sub_interface(itf1,
1178 interface::admin_state_t::UP,
1181 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1182 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1183 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1185 TRY_CHECK_RC(OM::write(noam, *vl33));
1188 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1189 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1190 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1191 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1192 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1193 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1195 TRY_CHECK(OM::remove(noam));
1198 BOOST_AUTO_TEST_CASE(test_acl) {
1200 const std::string fyodor = "FyodorDostoyevsky";
1201 const std::string leo = "LeoTolstoy";
1205 * Fyodor adds an ACL in the input direction
1207 std::string itf1_name = "host1";
1208 interface itf1(itf1_name,
1209 interface::type_t::AFPACKET,
1210 interface::admin_state_t::UP);
1211 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1212 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1213 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1214 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1215 TRY_CHECK_RC(OM::write(fyodor, itf1));
1217 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1218 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1219 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1220 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1221 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1222 HW::item<bool> ae_binding(true, rc_t::OK);
1223 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1224 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1226 route::prefix_t src("10.10.10.10", 32);
1227 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1228 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1230 std::string acl_name = "acl1";
1231 ACL::l3_list acl1(acl_name);
1234 ACL::l3_list::rules_t rules = {r1, r2};
1236 HW::item<handle_t> hw_acl(2, rc_t::OK);
1237 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1238 TRY_CHECK_RC(OM::write(fyodor, acl1));
1240 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1241 ACL::l3_list acl2(acl_name);
1243 ACL::l3_list::rules_t rules2 = {r3};
1244 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1245 TRY_CHECK_RC(OM::write(fyodor, acl2));
1247 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1248 HW::item<bool> hw_binding(true, rc_t::OK);
1249 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1250 hw_ifh.data(), hw_acl.data()));
1251 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1254 * Leo adds an L2 ACL in the output direction
1256 TRY_CHECK_RC(OM::write(leo, itf1));
1258 std::string l2_acl_name = "l2_acl1";
1259 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1260 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1261 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1262 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1264 ACL::l2_list l2_acl(l2_acl_name);
1265 l2_acl.insert(l2_r2);
1266 l2_acl.insert(l2_r1);
1268 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1270 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1271 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1272 TRY_CHECK_RC(OM::write(leo, l2_acl));
1274 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1275 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1276 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1277 hw_ifh.data(), l2_hw_acl.data()));
1278 TRY_CHECK_RC(OM::write(leo, *l2b));
1281 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1282 hw_ifh.data(), l2_hw_acl.data()));
1283 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1284 TRY_CHECK(OM::remove(leo));
1288 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1291 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1292 hw_ifh.data(), hw_acl.data()));
1293 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1294 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1295 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1296 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1298 TRY_CHECK(OM::remove(fyodor));
1301 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1303 const std::string kurt = "KurtVonnegut";
1306 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1307 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1309 arp_proxy_config ap(low, high);
1310 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1311 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1312 TRY_CHECK_RC(OM::write(kurt, ap));
1314 std::string itf3_name = "host3";
1315 interface itf3(itf3_name,
1316 interface::type_t::AFPACKET,
1317 interface::admin_state_t::UP);
1318 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1319 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1320 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1321 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1322 TRY_CHECK_RC(OM::write(kurt, itf3));
1324 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1325 HW::item<bool> hw_binding(true, rc_t::OK);
1326 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1327 TRY_CHECK_RC(OM::write(kurt, *apb));
1331 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1334 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1335 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1336 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1337 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1339 TRY_CHECK(OM::remove(kurt));
1342 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1344 const std::string eliot = "EliotReed";
1348 * Interface 1 is the tx interface
1350 std::string itf1_name = "tx-itf";
1351 interface itf1(itf1_name,
1352 interface::type_t::AFPACKET,
1353 interface::admin_state_t::UP);
1354 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1355 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1356 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1357 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1358 TRY_CHECK_RC(OM::write(eliot, itf1));
1360 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1363 * Interface 2 is the rx interface
1365 std::string itf2_name = "rx-itf";
1366 interface itf2(itf2_name,
1367 interface::type_t::AFPACKET,
1368 interface::admin_state_t::UP);
1370 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1371 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1372 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1373 TRY_CHECK_RC(OM::write(eliot, itf2));
1375 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1376 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1377 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1378 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1379 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1383 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1385 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1386 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1387 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1388 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1389 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1391 TRY_CHECK(OM::remove(eliot));
1394 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1396 const std::string eric = "EricAmbler";
1400 * Interface 1 has the L3 address
1402 std::string itf1_name = "host1";
1403 interface itf1(itf1_name,
1404 interface::type_t::AFPACKET,
1405 interface::admin_state_t::UP);
1406 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1407 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1408 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1409 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1410 TRY_CHECK_RC(OM::write(eric, itf1));
1412 route::prefix_t pfx_10("10.10.10.10", 24);
1413 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1414 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1415 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1416 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1417 TRY_CHECK_RC(OM::write(eric, *l3));
1420 * Interface 2 is unnumbered
1422 std::string itf2_name = "host2";
1423 interface itf2(itf2_name,
1424 interface::type_t::AFPACKET,
1425 interface::admin_state_t::UP);
1427 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1428 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1429 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1430 TRY_CHECK_RC(OM::write(eric, itf2));
1432 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1433 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1434 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1435 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1436 TRY_CHECK_RC(OM::write(eric, *ipun));
1441 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1443 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
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_ifh2));
1446 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1447 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1448 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1450 TRY_CHECK(OM::remove(eric));
1453 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1455 const std::string paulo = "PauloCoelho";
1461 std::string itf_name = "host_ip6nd";
1462 interface itf(itf_name,
1463 interface::type_t::AFPACKET,
1464 interface::admin_state_t::UP);
1465 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1466 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1467 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1468 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1469 TRY_CHECK_RC(OM::write(paulo, itf));
1471 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1472 l3_binding *l3 = new l3_binding(itf, pfx_10);
1473 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1474 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1475 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1476 TRY_CHECK_RC(OM::write(paulo, *l3));
1478 ra_config ra(0, 1, 0, 4);
1479 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1480 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1481 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1482 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1483 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1488 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1489 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1490 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1491 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1492 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1493 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1497 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1502 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1505 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1506 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1507 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1508 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1510 TRY_CHECK(OM::remove(paulo));
1513 BOOST_AUTO_TEST_CASE(test_interface_span) {
1515 const std::string elif = "ElifShafak";
1519 * Interface 1 to be mirrored
1521 std::string itf1_name = "port-from";
1522 interface itf1(itf1_name,
1523 interface::type_t::AFPACKET,
1524 interface::admin_state_t::UP);
1525 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1526 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1527 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1528 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1529 TRY_CHECK_RC(OM::write(elif, itf1));
1532 * Interface 2 where traffic is mirrored
1534 std::string itf2_name = "port-to";
1535 interface itf2(itf2_name,
1536 interface::type_t::AFPACKET,
1537 interface::admin_state_t::UP);
1539 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1540 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1542 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1543 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1544 TRY_CHECK_RC(OM::write(elif, itf2));
1546 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1547 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1548 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1549 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1550 TRY_CHECK_RC(OM::write(elif, *itf_span));
1552 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1553 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1557 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1558 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1559 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1560 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1561 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1563 TRY_CHECK(OM::remove(elif));
1566 BOOST_AUTO_TEST_CASE(test_routing) {
1568 const std::string ian = "IanFleming";
1572 * non-default route domain
1574 route_domain rd4(1);
1575 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1576 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1577 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1578 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1579 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1580 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1581 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1582 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1583 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1584 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1585 TRY_CHECK_RC(OM::write(ian, rd4));
1588 * a couple of interfaces
1590 std::string itf1_name = "af1";
1591 interface itf1(itf1_name,
1592 interface::type_t::AFPACKET,
1593 interface::admin_state_t::UP);
1594 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1595 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1596 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1597 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1598 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1599 TRY_CHECK_RC(OM::write(ian, itf1));
1601 std::string itf2_name = "af2";
1602 interface *itf2 = new interface(itf2_name,
1603 interface::type_t::AFPACKET,
1604 interface::admin_state_t::UP,
1607 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1608 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1609 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1610 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1611 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1612 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1613 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1614 TRY_CHECK_RC(OM::write(ian, *itf2));
1617 * prefix on each interface
1619 route::prefix_t pfx_10("10.10.10.10", 24);
1620 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1621 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1622 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1623 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1624 TRY_CHECK_RC(OM::write(ian, *l3_10));
1625 route::prefix_t pfx_11("11.11.11.11", 24);
1626 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1627 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1628 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1629 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1630 TRY_CHECK_RC(OM::write(ian, *l3_11));
1633 * A route via interface 1 in the default table
1635 route::prefix_t pfx_5("5.5.5.5", 32);
1636 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1637 route::path *path_10 = new route::path(nh_10, itf1);
1638 route::ip_route *route_5 = new route::ip_route(pfx_5);
1639 route_5->add(*path_10);
1640 HW::item<bool> hw_route_5(true, rc_t::OK);
1641 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
1642 TRY_CHECK_RC(OM::write(ian, *route_5));
1645 * A route via interface 2 in the non-default table
1647 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1648 route::path *path_11 = new route::path(nh_11, *itf2);
1649 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1650 route_5_2->add(*path_11);
1651 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1652 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
1653 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1656 * An ARP entry for the neighbour on itf1
1658 HW::item<bool> hw_neighbour(true, rc_t::OK);
1659 mac_address_t mac_n({0,1,2,4,5,6});
1660 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1661 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1662 TRY_CHECK_RC(OM::write(ian, *ne));
1667 route::prefix_t pfx_6("6.6.6.6", 32);
1668 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1669 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1670 route_dvr->add(*path_l2);
1671 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1672 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
1673 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1676 // delete the stack objects that hold references to others
1677 // so the OM::remove is the call that removes the last reference
1688 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1689 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1690 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1691 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1692 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1693 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1694 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1695 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1696 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1697 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1698 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1699 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1700 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1701 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1703 TRY_CHECK(OM::remove(ian));
1706 BOOST_AUTO_TEST_CASE(test_nat) {
1708 const std::string gs = "GeorgeSimenon";
1714 std::string itf_in_name = "inside";
1715 interface itf_in(itf_in_name,
1716 interface::type_t::AFPACKET,
1717 interface::admin_state_t::UP);
1718 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1719 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1720 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1721 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1722 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1723 TRY_CHECK_RC(OM::write(gs, itf_in));
1728 std::string itf_out_name = "port-to";
1729 interface itf_out(itf_out_name,
1730 interface::type_t::AFPACKET,
1731 interface::admin_state_t::UP);
1733 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1734 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1735 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1737 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1738 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1739 TRY_CHECK_RC(OM::write(gs, itf_out));
1742 * A NAT static mapping
1744 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1745 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1747 nat_static ns(in_addr, out_addr);
1748 HW::item<bool> hw_ns(true, rc_t::OK);
1750 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1751 TRY_CHECK_RC(OM::write(gs, ns));
1754 * bind nat inside and out
1756 nat_binding *nb_in = new nat_binding(itf_in,
1759 nat_binding::zone_t::INSIDE);
1760 HW::item<bool> hw_nb_in(true, rc_t::OK);
1762 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1763 hw_ifh.data().value(),
1764 nat_binding::zone_t::INSIDE));
1765 TRY_CHECK_RC(OM::write(gs, *nb_in));
1767 nat_binding *nb_out = new nat_binding(itf_out,
1770 nat_binding::zone_t::OUTSIDE);
1771 HW::item<bool> hw_nb_out(true, rc_t::OK);
1773 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1774 hw_ifh2.data().value(),
1775 nat_binding::zone_t::OUTSIDE));
1776 TRY_CHECK_RC(OM::write(gs, *nb_out));
1782 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1783 hw_ifh.data().value(),
1784 nat_binding::zone_t::INSIDE));
1785 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1786 hw_ifh2.data().value(),
1787 nat_binding::zone_t::OUTSIDE));
1788 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1789 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1790 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1791 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1792 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1794 TRY_CHECK(OM::remove(gs));
1797 BOOST_AUTO_TEST_CASE(test_interface_events) {
1801 HW::item<bool> hw_want(true, rc_t::OK);
1803 ADD_EXPECT(interface_cmds::events_cmd(ml));
1804 cmd* itf = new interface_cmds::events_cmd(ml);
1810 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1812 const std::string rene = "ReneGoscinny";
1816 * Create an interface with two IP addresses
1818 std::string itf1_name = "host1";
1819 interface itf1(itf1_name,
1820 interface::type_t::AFPACKET,
1821 interface::admin_state_t::UP);
1822 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1823 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1824 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1825 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1826 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1827 TRY_CHECK_RC(OM::write(rene, itf1));
1829 route::prefix_t pfx_10("10.10.10.10", 24);
1830 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1831 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1832 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1833 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1834 TRY_CHECK_RC(OM::write(rene, *l3_1));
1836 route::prefix_t pfx_11("10.10.11.11", 24);
1837 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1838 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1839 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1840 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1841 TRY_CHECK_RC(OM::write(rene, *l3_2));
1844 HW::item<bool> hw_rd_create(true, rc_t::OK);
1845 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1846 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1847 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1848 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1849 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1850 TRY_CHECK_RC(OM::write(rene, rd));
1853 * update the interface to change to a new route-domain
1854 * expect that the l3-bindings are removed and readded.
1856 interface *itf2 = new interface(itf1_name,
1857 interface::type_t::AFPACKET,
1858 interface::admin_state_t::UP,
1860 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1861 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1862 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1863 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1864 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1865 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1866 TRY_CHECK_RC(OM::write(rene, *itf2));
1869 * mve the interface back to the default route-domain
1871 interface itf3(itf1_name,
1872 interface::type_t::AFPACKET,
1873 interface::admin_state_t::UP);
1874 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1875 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1876 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1877 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1878 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1879 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1880 TRY_CHECK_RC(OM::write(rene, itf3));
1887 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1888 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1889 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1890 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1891 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1892 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1894 TRY_CHECK(OM::remove(rene));
1897 BOOST_AUTO_TEST_CASE(test_prefixes) {
1898 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1900 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1902 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1904 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1905 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1907 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1908 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1909 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1911 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1913 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1915 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1917 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1918 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1919 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1921 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1923 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1924 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1925 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1927 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1929 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1930 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1931 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1935 BOOST_AUTO_TEST_CASE(test_pipes) {
1937 const std::string gk = "GKChesterton";
1939 const std::string pipe_name_1 = "pipe1";
1940 VOM::pipe pipe1(1, interface::admin_state_t::UP);
1941 HW::item<handle_t> hw_hdl(4, rc_t::OK);
1942 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
1944 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
1946 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1948 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
1949 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
1950 TRY_CHECK_RC(OM::write(gk, pipe1));
1952 pipe1.set_ends(hw_hdl_pair.data());
1954 // put each end of the pipe in a BD
1955 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1956 bridge_domain::arp_term_mode_t::OFF,
1957 bridge_domain::flood_mode_t::OFF,
1958 bridge_domain::mac_age_mode_t::ON);
1960 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1961 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1962 bridge_domain::learning_mode_t::OFF,
1963 bridge_domain::arp_term_mode_t::OFF,
1964 bridge_domain::flood_mode_t::OFF,
1965 bridge_domain::mac_age_mode_t::ON));
1967 TRY_CHECK_RC(OM::write(gk, bd1));
1969 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
1970 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
1972 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
1973 pipe1.east()->handle(),
1974 hw_bd.data(), false));
1975 TRY_CHECK_RC(OM::write(gk, *l2_1));
1977 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
1978 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
1980 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
1981 pipe1.west()->handle(),
1982 hw_bd.data(), false));
1983 TRY_CHECK_RC(OM::write(gk, *l2_2));
1989 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
1990 pipe1.east()->handle(),
1993 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
1994 pipe1.west()->handle(),
1997 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
1998 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
1999 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2000 TRY_CHECK(OM::remove(gk));
2003 BOOST_AUTO_TEST_SUITE_END()