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,
942 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
943 TRY_CHECK_RC(OM::write(franz, *l2itf));
946 * Dante adds an interface to the same BD
948 std::string itf2_name = "afpacket2";
949 interface itf2(itf2_name,
950 interface::type_t::AFPACKET,
951 interface::admin_state_t::UP);
953 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
954 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
955 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
956 TRY_CHECK_RC(OM::write(dante, itf2));
958 // BD add is a no-op since it exists
959 TRY_CHECK_RC(OM::write(dante, bd1));
961 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
962 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
963 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
965 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
968 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
969 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
970 TRY_CHECK_RC(OM::write(dante, *l2itf2));
972 // Add some static entries to the bridge-domain
973 HW::item<bool> hw_be1(true, rc_t::OK);
974 mac_address_t mac1({0,1,2,3,4,5});
975 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
976 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
978 TRY_CHECK_RC(OM::write(dante, *be1));
980 // Add some entries to the bridge-domain ARP termination table
981 HW::item<bool> hw_bea1(true, rc_t::OK);
982 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
984 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
985 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
986 TRY_CHECK_RC(OM::write(dante, *bea1));
988 // flush Franz's state
990 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
992 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
995 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
996 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
997 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
998 TRY_CHECK(OM::remove(franz));
1000 // flush Dante's state - the order the interface and BD are deleted
1001 // is an uncontrollable artifact of the C++ object destruction.
1006 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1007 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
1008 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1011 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1013 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1014 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1015 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1016 TRY_CHECK(OM::remove(dante));
1018 // test the BVI entry in l2fib
1019 bridge_domain bd2(99);
1021 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1022 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1023 bridge_domain::learning_mode_t::ON,
1024 bridge_domain::arp_term_mode_t::ON,
1025 bridge_domain::flood_mode_t::ON,
1026 bridge_domain::mac_age_mode_t::OFF));
1028 TRY_CHECK_RC(OM::write(jkr, bd2));
1030 std::string itf3_name = "bvi";
1031 interface itf3(itf3_name,
1032 interface::type_t::BVI,
1033 interface::admin_state_t::UP);
1035 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1036 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1037 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1038 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1039 TRY_CHECK_RC(OM::write(jkr, itf3));
1041 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1042 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1045 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1046 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1048 HW::item<bool> hw_be2(true, rc_t::OK);
1049 mac_address_t mac2({0,1,2,3,4,5});
1050 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1051 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1052 TRY_CHECK_RC(OM::write(jkr, *be2));
1057 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1060 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1061 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1062 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1063 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1064 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1065 TRY_CHECK(OM::remove(jkr));
1068 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1070 const std::string nicholas = "NicholasAbercrombie";
1076 std::string itf1_name = "host1";
1077 interface itf1(itf1_name,
1078 interface::type_t::AFPACKET,
1079 interface::admin_state_t::UP);
1080 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1081 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1082 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1083 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1084 TRY_CHECK_RC(OM::write(nicholas, itf1));
1089 std::string itf2_name = "host2";
1090 interface itf2(itf2_name,
1091 interface::type_t::AFPACKET,
1092 interface::admin_state_t::UP);
1094 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1095 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1096 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1097 TRY_CHECK_RC(OM::write(nicholas, itf2));
1099 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1100 HW::item<bool> xconnect_east(true, rc_t::OK);
1101 HW::item<bool> xconnect_west(true, rc_t::OK);
1102 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1103 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1104 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1105 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1106 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1110 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1112 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1113 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1114 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1115 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1116 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1117 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1119 TRY_CHECK(OM::remove(nicholas));
1122 BOOST_AUTO_TEST_CASE(test_vxlan) {
1124 const std::string franz = "FranzKafka";
1128 * Franz creates an interface, Bridge-domain, then binds the two
1132 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1133 boost::asio::ip::address::from_string("10.10.10.11"),
1136 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1138 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1139 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
1141 TRY_CHECK_RC(OM::write(franz, vxt));
1143 // bridge-domain create
1144 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1145 bridge_domain::arp_term_mode_t::OFF,
1146 bridge_domain::flood_mode_t::OFF,
1147 bridge_domain::mac_age_mode_t::ON);
1149 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1150 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1151 bridge_domain::learning_mode_t::OFF,
1152 bridge_domain::arp_term_mode_t::OFF,
1153 bridge_domain::flood_mode_t::OFF,
1154 bridge_domain::mac_age_mode_t::ON));
1156 TRY_CHECK_RC(OM::write(franz, bd1));
1158 // L2-interface create and bind
1159 // this needs to be delete'd before the flush below, since it too maintains
1160 // references to the BD and Interface
1161 l2_binding *l2itf = new l2_binding(vxt, bd1);
1162 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1164 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1167 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1168 TRY_CHECK_RC(OM::write(franz, *l2itf));
1170 // flush Franz's state
1172 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1174 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1177 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1178 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1179 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1180 TRY_CHECK(OM::remove(franz));
1183 BOOST_AUTO_TEST_CASE(test_vlan) {
1185 const std::string noam = "NoamChomsky";
1188 std::string itf1_name = "host1";
1189 interface itf1(itf1_name,
1190 interface::type_t::AFPACKET,
1191 interface::admin_state_t::UP);
1193 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1194 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1196 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1197 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1199 TRY_CHECK_RC(OM::write(noam, itf1));
1201 sub_interface *vl33 = new sub_interface(itf1,
1202 interface::admin_state_t::UP,
1205 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1206 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1207 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1209 TRY_CHECK_RC(OM::write(noam, *vl33));
1212 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1213 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1214 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1215 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1216 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1217 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1219 TRY_CHECK(OM::remove(noam));
1222 BOOST_AUTO_TEST_CASE(test_acl) {
1224 const std::string fyodor = "FyodorDostoyevsky";
1225 const std::string leo = "LeoTolstoy";
1229 * Fyodor adds an ACL in the input direction
1231 std::string itf1_name = "host1";
1232 interface itf1(itf1_name,
1233 interface::type_t::AFPACKET,
1234 interface::admin_state_t::UP);
1235 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1236 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1237 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1238 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1239 TRY_CHECK_RC(OM::write(fyodor, itf1));
1241 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1242 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1243 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1244 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1245 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1246 HW::item<bool> ae_binding(true, rc_t::OK);
1247 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1248 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1250 route::prefix_t src("10.10.10.10", 32);
1251 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1252 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1254 std::string acl_name = "acl1";
1255 ACL::l3_list acl1(acl_name);
1258 ACL::l3_list::rules_t rules = {r1, r2};
1260 HW::item<handle_t> hw_acl(2, rc_t::OK);
1261 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1262 TRY_CHECK_RC(OM::write(fyodor, acl1));
1264 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1265 ACL::l3_list acl2(acl_name);
1267 ACL::l3_list::rules_t rules2 = {r3};
1268 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1269 TRY_CHECK_RC(OM::write(fyodor, acl2));
1271 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1272 HW::item<bool> hw_binding(true, rc_t::OK);
1273 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1274 hw_ifh.data(), hw_acl.data()));
1275 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1278 * Leo adds an L2 ACL in the output direction
1280 TRY_CHECK_RC(OM::write(leo, itf1));
1282 std::string l2_acl_name = "l2_acl1";
1283 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1284 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1285 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1286 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1288 ACL::l2_list l2_acl(l2_acl_name);
1289 l2_acl.insert(l2_r2);
1290 l2_acl.insert(l2_r1);
1292 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1294 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1295 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1296 TRY_CHECK_RC(OM::write(leo, l2_acl));
1298 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1299 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1300 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1301 hw_ifh.data(), l2_hw_acl.data()));
1302 TRY_CHECK_RC(OM::write(leo, *l2b));
1305 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1306 hw_ifh.data(), l2_hw_acl.data()));
1307 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1308 TRY_CHECK(OM::remove(leo));
1312 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1315 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1316 hw_ifh.data(), hw_acl.data()));
1317 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1318 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1319 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1320 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1322 TRY_CHECK(OM::remove(fyodor));
1325 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1327 const std::string kurt = "KurtVonnegut";
1330 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1331 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1333 arp_proxy_config ap(low, high);
1334 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1335 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1336 TRY_CHECK_RC(OM::write(kurt, ap));
1338 std::string itf3_name = "host3";
1339 interface itf3(itf3_name,
1340 interface::type_t::AFPACKET,
1341 interface::admin_state_t::UP);
1342 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1343 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1344 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1345 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1346 TRY_CHECK_RC(OM::write(kurt, itf3));
1348 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1349 HW::item<bool> hw_binding(true, rc_t::OK);
1350 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1351 TRY_CHECK_RC(OM::write(kurt, *apb));
1355 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1358 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1359 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1360 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1361 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1363 TRY_CHECK(OM::remove(kurt));
1366 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1368 const std::string eliot = "EliotReed";
1372 * Interface 1 is the tx interface
1374 std::string itf1_name = "tx-itf";
1375 interface itf1(itf1_name,
1376 interface::type_t::AFPACKET,
1377 interface::admin_state_t::UP);
1378 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1379 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1380 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1381 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1382 TRY_CHECK_RC(OM::write(eliot, itf1));
1384 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1387 * Interface 2 is the rx interface
1389 std::string itf2_name = "rx-itf";
1390 interface itf2(itf2_name,
1391 interface::type_t::AFPACKET,
1392 interface::admin_state_t::UP);
1394 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1395 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1396 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1397 TRY_CHECK_RC(OM::write(eliot, itf2));
1399 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1400 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1401 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1402 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1403 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1407 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1409 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1410 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1411 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1412 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1413 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1415 TRY_CHECK(OM::remove(eliot));
1418 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1420 const std::string eric = "EricAmbler";
1424 * Interface 1 has the L3 address
1426 std::string itf1_name = "host1";
1427 interface itf1(itf1_name,
1428 interface::type_t::AFPACKET,
1429 interface::admin_state_t::UP);
1430 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1431 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1432 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1433 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1434 TRY_CHECK_RC(OM::write(eric, itf1));
1436 route::prefix_t pfx_10("10.10.10.10", 24);
1437 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1438 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1439 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1440 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1441 TRY_CHECK_RC(OM::write(eric, *l3));
1444 * Interface 2 is unnumbered
1446 std::string itf2_name = "host2";
1447 interface itf2(itf2_name,
1448 interface::type_t::AFPACKET,
1449 interface::admin_state_t::UP);
1451 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1452 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1453 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1454 TRY_CHECK_RC(OM::write(eric, itf2));
1456 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1457 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1458 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1459 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1460 TRY_CHECK_RC(OM::write(eric, *ipun));
1465 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1467 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1468 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1469 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1470 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1471 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1472 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1474 TRY_CHECK(OM::remove(eric));
1477 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1479 const std::string paulo = "PauloCoelho";
1485 std::string itf_name = "host_ip6nd";
1486 interface itf(itf_name,
1487 interface::type_t::AFPACKET,
1488 interface::admin_state_t::UP);
1489 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1490 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1491 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1492 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1493 TRY_CHECK_RC(OM::write(paulo, itf));
1495 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1496 l3_binding *l3 = new l3_binding(itf, pfx_10);
1497 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1498 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1499 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1500 TRY_CHECK_RC(OM::write(paulo, *l3));
1502 ra_config ra(0, 1, 0, 4);
1503 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1504 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1505 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1506 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1507 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1512 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1513 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1514 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1515 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1516 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1517 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1521 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1526 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1529 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1530 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1531 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1532 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1534 TRY_CHECK(OM::remove(paulo));
1537 BOOST_AUTO_TEST_CASE(test_interface_span) {
1539 const std::string elif = "ElifShafak";
1543 * Interface 1 to be mirrored
1545 std::string itf1_name = "port-from";
1546 interface itf1(itf1_name,
1547 interface::type_t::AFPACKET,
1548 interface::admin_state_t::UP);
1549 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1550 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1551 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1552 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1553 TRY_CHECK_RC(OM::write(elif, itf1));
1556 * Interface 2 where traffic is mirrored
1558 std::string itf2_name = "port-to";
1559 interface itf2(itf2_name,
1560 interface::type_t::AFPACKET,
1561 interface::admin_state_t::UP);
1563 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1564 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1566 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1567 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1568 TRY_CHECK_RC(OM::write(elif, itf2));
1570 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1571 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1572 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1573 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1574 TRY_CHECK_RC(OM::write(elif, *itf_span));
1576 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1577 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1581 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1582 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1583 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1584 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1585 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1587 TRY_CHECK(OM::remove(elif));
1590 BOOST_AUTO_TEST_CASE(test_routing) {
1592 const std::string ian = "IanFleming";
1596 * non-default route domain
1598 route_domain rd4(1);
1599 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1600 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1601 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1602 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1603 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1604 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1605 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1606 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1607 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1608 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1609 TRY_CHECK_RC(OM::write(ian, rd4));
1612 * a couple of interfaces
1614 std::string itf1_name = "af1";
1615 interface itf1(itf1_name,
1616 interface::type_t::AFPACKET,
1617 interface::admin_state_t::UP);
1618 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1619 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1620 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1621 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1622 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1623 TRY_CHECK_RC(OM::write(ian, itf1));
1625 std::string itf2_name = "af2";
1626 interface *itf2 = new interface(itf2_name,
1627 interface::type_t::AFPACKET,
1628 interface::admin_state_t::UP,
1631 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1632 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1633 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1634 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1635 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1636 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1637 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1638 TRY_CHECK_RC(OM::write(ian, *itf2));
1641 * prefix on each interface
1643 route::prefix_t pfx_10("10.10.10.10", 24);
1644 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1645 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1646 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1647 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1648 TRY_CHECK_RC(OM::write(ian, *l3_10));
1649 route::prefix_t pfx_11("11.11.11.11", 24);
1650 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1651 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1652 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1653 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1654 TRY_CHECK_RC(OM::write(ian, *l3_11));
1657 * A route via interface 1 in the default table
1659 route::prefix_t pfx_5("5.5.5.5", 32);
1660 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1661 route::path *path_10 = new route::path(nh_10, itf1);
1662 route::ip_route *route_5 = new route::ip_route(pfx_5);
1663 route_5->add(*path_10);
1664 HW::item<bool> hw_route_5(true, rc_t::OK);
1665 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
1666 TRY_CHECK_RC(OM::write(ian, *route_5));
1669 * A route via interface 2 in the non-default table
1671 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1672 route::path *path_11 = new route::path(nh_11, *itf2);
1673 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1674 route_5_2->add(*path_11);
1675 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1676 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
1677 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1680 * An ARP entry for the neighbour on itf1
1682 HW::item<bool> hw_neighbour(true, rc_t::OK);
1683 mac_address_t mac_n({0,1,2,4,5,6});
1684 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1685 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1686 TRY_CHECK_RC(OM::write(ian, *ne));
1691 route::prefix_t pfx_6("6.6.6.6", 32);
1692 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1693 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1694 route_dvr->add(*path_l2);
1695 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1696 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
1697 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1700 // delete the stack objects that hold references to others
1701 // so the OM::remove is the call that removes the last reference
1712 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1713 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1714 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1715 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1716 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1717 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1718 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1719 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1720 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1721 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1722 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1723 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1724 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1725 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1727 TRY_CHECK(OM::remove(ian));
1730 BOOST_AUTO_TEST_CASE(test_nat) {
1732 const std::string gs = "GeorgeSimenon";
1738 std::string itf_in_name = "inside";
1739 interface itf_in(itf_in_name,
1740 interface::type_t::AFPACKET,
1741 interface::admin_state_t::UP);
1742 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1743 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1744 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1745 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1746 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1747 TRY_CHECK_RC(OM::write(gs, itf_in));
1752 std::string itf_out_name = "port-to";
1753 interface itf_out(itf_out_name,
1754 interface::type_t::AFPACKET,
1755 interface::admin_state_t::UP);
1757 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1758 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1759 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1761 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1762 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1763 TRY_CHECK_RC(OM::write(gs, itf_out));
1766 * A NAT static mapping
1768 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1769 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1771 nat_static ns(in_addr, out_addr);
1772 HW::item<bool> hw_ns(true, rc_t::OK);
1774 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1775 TRY_CHECK_RC(OM::write(gs, ns));
1778 * bind nat inside and out
1780 nat_binding *nb_in = new nat_binding(itf_in,
1783 nat_binding::zone_t::INSIDE);
1784 HW::item<bool> hw_nb_in(true, rc_t::OK);
1786 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1787 hw_ifh.data().value(),
1788 nat_binding::zone_t::INSIDE));
1789 TRY_CHECK_RC(OM::write(gs, *nb_in));
1791 nat_binding *nb_out = new nat_binding(itf_out,
1794 nat_binding::zone_t::OUTSIDE);
1795 HW::item<bool> hw_nb_out(true, rc_t::OK);
1797 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1798 hw_ifh2.data().value(),
1799 nat_binding::zone_t::OUTSIDE));
1800 TRY_CHECK_RC(OM::write(gs, *nb_out));
1806 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1807 hw_ifh.data().value(),
1808 nat_binding::zone_t::INSIDE));
1809 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1810 hw_ifh2.data().value(),
1811 nat_binding::zone_t::OUTSIDE));
1812 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1813 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1814 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1815 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1816 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1818 TRY_CHECK(OM::remove(gs));
1821 BOOST_AUTO_TEST_CASE(test_interface_events) {
1825 HW::item<bool> hw_want(true, rc_t::OK);
1827 ADD_EXPECT(interface_cmds::events_cmd(ml));
1828 cmd* itf = new interface_cmds::events_cmd(ml);
1834 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1836 const std::string rene = "ReneGoscinny";
1840 * Create an interface with two IP addresses
1842 std::string itf1_name = "host1";
1843 interface itf1(itf1_name,
1844 interface::type_t::AFPACKET,
1845 interface::admin_state_t::UP);
1846 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1847 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1848 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1849 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1850 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1851 TRY_CHECK_RC(OM::write(rene, itf1));
1853 route::prefix_t pfx_10("10.10.10.10", 24);
1854 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1855 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1856 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1857 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1858 TRY_CHECK_RC(OM::write(rene, *l3_1));
1860 route::prefix_t pfx_11("10.10.11.11", 24);
1861 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1862 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1863 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1864 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1865 TRY_CHECK_RC(OM::write(rene, *l3_2));
1868 HW::item<bool> hw_rd_create(true, rc_t::OK);
1869 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1870 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1871 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1872 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1873 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1874 TRY_CHECK_RC(OM::write(rene, rd));
1877 * update the interface to change to a new route-domain
1878 * expect that the l3-bindings are removed and readded.
1880 interface *itf2 = new interface(itf1_name,
1881 interface::type_t::AFPACKET,
1882 interface::admin_state_t::UP,
1884 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1885 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1886 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1887 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1888 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1889 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1890 TRY_CHECK_RC(OM::write(rene, *itf2));
1893 * mve the interface back to the default route-domain
1895 interface itf3(itf1_name,
1896 interface::type_t::AFPACKET,
1897 interface::admin_state_t::UP);
1898 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1899 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1900 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1901 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1902 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1903 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1904 TRY_CHECK_RC(OM::write(rene, itf3));
1911 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1912 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1913 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1914 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1915 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1916 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1918 TRY_CHECK(OM::remove(rene));
1921 BOOST_AUTO_TEST_CASE(test_prefixes) {
1922 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1924 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1926 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1928 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1929 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1931 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1932 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1933 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1935 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1937 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1939 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1941 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1942 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1943 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1945 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1947 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1948 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1949 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1951 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1953 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1954 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1955 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1959 BOOST_AUTO_TEST_CASE(test_pipes) {
1961 const std::string gk = "GKChesterton";
1963 const std::string pipe_name_1 = "pipe1";
1964 VOM::pipe pipe1(1, interface::admin_state_t::UP);
1965 HW::item<handle_t> hw_hdl(4, rc_t::OK);
1966 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
1968 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
1970 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1972 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
1973 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
1974 TRY_CHECK_RC(OM::write(gk, pipe1));
1976 pipe1.set_ends(hw_hdl_pair.data());
1978 // put each end of the pipe in a BD
1979 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1980 bridge_domain::arp_term_mode_t::OFF,
1981 bridge_domain::flood_mode_t::OFF,
1982 bridge_domain::mac_age_mode_t::ON);
1984 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1985 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1986 bridge_domain::learning_mode_t::OFF,
1987 bridge_domain::arp_term_mode_t::OFF,
1988 bridge_domain::flood_mode_t::OFF,
1989 bridge_domain::mac_age_mode_t::ON));
1991 TRY_CHECK_RC(OM::write(gk, bd1));
1993 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
1994 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
1996 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
1997 pipe1.east()->handle(),
1999 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2000 TRY_CHECK_RC(OM::write(gk, *l2_1));
2002 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2003 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2005 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2006 pipe1.west()->handle(),
2008 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2009 TRY_CHECK_RC(OM::write(gk, *l2_2));
2015 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2016 pipe1.east()->handle(),
2018 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2019 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2020 pipe1.west()->handle(),
2022 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2023 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2024 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2025 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2026 TRY_CHECK(OM::remove(gk));
2029 BOOST_AUTO_TEST_SUITE_END()