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_vtr_cmds.hpp"
29 #include "vom/l2_xconnect.hpp"
30 #include "vom/l2_xconnect_cmds.hpp"
31 #include "vom/l3_binding.hpp"
32 #include "vom/l3_binding_cmds.hpp"
33 #include "vom/bridge_domain.hpp"
34 #include "vom/bridge_domain_entry.hpp"
35 #include "vom/bridge_domain_arp_entry.hpp"
36 #include "vom/bridge_domain_cmds.hpp"
37 #include "vom/bridge_domain_entry_cmds.hpp"
38 #include "vom/bridge_domain_arp_entry_cmds.hpp"
39 #include "vom/prefix.hpp"
40 #include "vom/route.hpp"
41 #include "vom/route_cmds.hpp"
42 #include "vom/mroute_cmds.hpp"
43 #include "vom/route_domain.hpp"
44 #include "vom/route_domain_cmds.hpp"
45 #include "vom/vxlan_tunnel.hpp"
46 #include "vom/vxlan_tunnel_cmds.hpp"
47 #include "vom/sub_interface.hpp"
48 #include "vom/sub_interface_cmds.hpp"
49 #include "vom/acl_ethertype.hpp"
50 #include "vom/acl_ethertype_cmds.hpp"
51 #include "vom/acl_list.hpp"
52 #include "vom/acl_binding.hpp"
53 #include "vom/acl_list_cmds.hpp"
54 #include "vom/acl_binding_cmds.hpp"
55 #include "vom/acl_l3_rule.hpp"
56 #include "vom/acl_l2_rule.hpp"
57 #include "vom/arp_proxy_config.hpp"
58 #include "vom/arp_proxy_binding.hpp"
59 #include "vom/arp_proxy_config_cmds.hpp"
60 #include "vom/arp_proxy_binding_cmds.hpp"
61 #include "vom/igmp_binding.hpp"
62 #include "vom/igmp_binding_cmds.hpp"
63 #include "vom/igmp_listen.hpp"
64 #include "vom/igmp_listen_cmds.hpp"
65 #include "vom/ip_punt_redirect.hpp"
66 #include "vom/ip_punt_redirect_cmds.hpp"
67 #include "vom/ip_unnumbered.hpp"
68 #include "vom/ip_unnumbered_cmds.hpp"
69 #include "vom/interface_ip6_nd.hpp"
70 #include "vom/interface_span.hpp"
71 #include "vom/interface_span_cmds.hpp"
72 #include "vom/neighbour.hpp"
73 #include "vom/neighbour_cmds.hpp"
74 #include "vom/nat_static.hpp"
75 #include "vom/nat_static_cmds.hpp"
76 #include "vom/nat_binding.hpp"
77 #include "vom/nat_binding_cmds.hpp"
78 #include "vom/pipe.hpp"
79 #include "vom/pipe_cmds.hpp"
81 using namespace boost;
85 * An expectation exception
90 ExpException(unsigned int number)
92 // a neat place to add a break point
93 std::cout << " ExpException here: " << number << std::endl;
97 class MockListener : public interface::event_listener,
98 public interface::stat_listener
100 void handle_interface_stat(const interface& itf)
103 void handle_interface_event(std::vector<VOM::interface::event> events)
108 class MockCmdQ : public HW::cmd_q
120 m_exp_queue.push_back(f);
124 m_act_queue.push_back(f);
126 void enqueue(std::queue<cmd*> &cmds)
130 m_act_queue.push_back(cmds.front());
134 void enqueue(std::shared_ptr<cmd> f)
136 m_act_queue.push_back(f.get());
143 void dequeue(std::shared_ptr<cmd> cmd)
147 void strict_order(bool on)
154 return ((0 == m_exp_queue.size()) &&
155 (0 == m_act_queue.size()));
163 while (m_act_queue.size())
165 bool matched = false;
166 auto it_exp = m_exp_queue.begin();
167 auto it_act = m_act_queue.begin();
171 std::cout << " Act: " << f_act->to_string() << std::endl;
172 while (it_exp != m_exp_queue.end())
177 std::cout << " Exp: " << f_exp->to_string() << std::endl;
179 if (typeid(*f_exp) != typeid(*f_act))
181 throw ExpException(1);
184 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
186 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
188 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
190 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
192 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
194 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
196 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
198 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
200 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
202 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
204 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
206 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
208 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
210 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
212 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
214 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
216 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
218 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
220 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
222 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
224 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
226 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
228 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
230 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
232 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
234 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
236 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
238 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
240 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
242 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
244 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
246 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
248 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
250 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
252 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
254 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
256 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
258 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
260 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
262 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
264 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
266 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
268 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
270 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
272 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
274 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
276 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
278 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
280 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
282 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
284 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
286 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
288 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
290 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
292 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
294 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
296 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
298 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
300 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
302 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
304 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
306 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
308 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
310 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
312 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
314 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
316 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
318 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
320 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
322 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
324 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
326 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
328 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
330 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
332 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
334 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
336 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
338 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
340 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
342 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
344 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
346 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
348 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
350 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
352 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
354 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
356 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
358 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
360 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
362 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
364 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
366 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
368 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
370 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
372 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
374 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
376 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
378 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
380 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
382 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
384 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
386 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
388 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
390 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
392 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
394 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
396 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
398 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
400 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
402 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
404 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
406 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
408 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
410 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
412 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
414 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
416 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
418 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
420 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
422 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
424 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
426 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
428 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
430 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
432 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
434 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
436 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
438 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
440 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
442 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
444 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
446 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
448 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
450 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
452 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
454 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
456 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
458 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
460 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
462 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
464 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
466 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
468 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
470 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
472 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
474 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
476 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
478 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
482 throw ExpException(2);
485 // if we get here then we found the match.
486 m_exp_queue.erase(it_exp);
487 m_act_queue.erase(it_act);
491 // return any injected failures to the agent
492 if (rc_t::OK != rc && rc_t::NOOP != rc)
500 catch (ExpException &e)
502 // The expected and actual do not match
505 // in strict ordering mode this is fatal, so rethrow
510 // move the iterator onto the next in the expected list and
518 throw ExpException(3);
525 template <typename T>
526 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
531 i_exp = dynamic_cast<const T*>(f_exp);
532 i_act = dynamic_cast<T*>(f_act);
533 if (!(*i_exp == *i_act))
535 throw ExpException(4);
537 // pass the data and return code to the agent
538 i_act->item() = i_exp->item();
540 return (i_act->item().rc());
543 // The Q to push the expectations on
544 std::deque<cmd*> m_exp_queue;
546 // the queue to push the actual events on
547 std::deque<cmd*> m_act_queue;
549 // control whether the expected queue is strictly ordered.
564 logger().set(log_level_t::DEBUG);
572 BOOST_AUTO_TEST_SUITE(vom)
574 #define TRY_CHECK_RC(stmt) \
577 BOOST_CHECK(rc_t::OK == stmt); \
579 catch (ExpException &e) \
581 BOOST_CHECK(false); \
583 BOOST_CHECK(vi.f->is_empty()); \
586 #define TRY_CHECK(stmt) \
591 catch (ExpException &e) \
593 BOOST_CHECK(false); \
595 BOOST_CHECK(vi.f->is_empty()); \
598 #define ADD_EXPECT(stmt) \
599 vi.f->expect(new stmt)
601 #define STRICT_ORDER_OFF() \
602 vi.f->strict_order(false)
604 BOOST_AUTO_TEST_CASE(test_interface) {
606 const std::string go = "GeorgeOrwell";
607 const std::string js = "JohnSteinbeck";
611 * George creates and deletes the interface
613 std::string itf1_name = "afpacket1";
614 interface itf1(itf1_name,
615 interface::type_t::AFPACKET,
616 interface::admin_state_t::UP);
619 * set the expectation for a afpacket interface create.
620 * 2 is the interface handle VPP [mock] assigns
622 HW::item<handle_t> hw_ifh(2, rc_t::OK);
623 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
625 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
626 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
628 TRY_CHECK_RC(OM::write(go, itf1));
630 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
631 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
632 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
634 TRY_CHECK(OM::remove(go));
637 * George creates the interface, then John brings it down.
638 * George's remove is a no-op, sice John also owns the interface
640 interface itf1b(itf1_name,
641 interface::type_t::AFPACKET,
642 interface::admin_state_t::DOWN);
644 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
645 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
646 TRY_CHECK_RC(OM::write(go, itf1));
648 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
649 TRY_CHECK_RC(OM::write(js, itf1b));
651 TRY_CHECK(OM::remove(go));
653 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
654 TRY_CHECK(OM::remove(js));
657 * George adds an interface, then we flush all of Geroge's state
659 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
660 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
661 TRY_CHECK_RC(OM::write(go, itf1));
663 TRY_CHECK(OM::mark(go));
665 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
666 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
667 TRY_CHECK(OM::sweep(go));
670 * George adds an interface. mark stale. update the same interface. sweep
671 * and expect no delete
673 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
674 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
675 TRY_CHECK_RC(OM::write(go, itf1b));
677 TRY_CHECK(OM::mark(go));
679 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
680 TRY_CHECK_RC(OM::write(go, itf1));
682 TRY_CHECK(OM::sweep(go));
684 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
685 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
686 TRY_CHECK(OM::remove(go));
689 * George adds an insterface, then we mark that state. Add a second interface
690 * an flush the first that is now stale.
692 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
693 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
694 TRY_CHECK_RC(OM::write(go, itf1));
696 TRY_CHECK(OM::mark(go));
698 std::string itf2_name = "afpacket2";
699 std::string itf2_tag = "uuid-of-afpacket2-interface";
700 interface itf2(itf2_name,
701 interface::type_t::AFPACKET,
702 interface::admin_state_t::UP,
704 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
706 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
707 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
708 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
709 TRY_CHECK_RC(OM::write(go, itf2));
711 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
712 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
713 TRY_CHECK(OM::sweep(go));
715 TRY_CHECK(OM::mark(go));
717 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
718 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
719 TRY_CHECK(OM::sweep(go));
722 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
723 std::string itf3_tag = "uuid-of-vhost_user1-interface";
724 interface itf3(itf3_name,
725 interface::type_t::VHOST,
726 interface::admin_state_t::UP,
728 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
730 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
731 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
732 TRY_CHECK_RC(OM::write(go, itf3));
734 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
735 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
736 TRY_CHECK(OM::remove(go));
739 BOOST_AUTO_TEST_CASE(test_bvi) {
741 const std::string ernest = "ErnestHemmingway";
742 const std::string graham = "GrahamGreene";
746 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
748 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
752 * Enrest creates a BVI with address 10.10.10.10/24
754 route::prefix_t pfx_10("10.10.10.10", 24);
756 const std::string bvi_name = "bvi1";
757 interface itf(bvi_name,
758 interface::type_t::BVI,
759 interface::admin_state_t::UP);
760 HW::item<handle_t> hw_ifh(4, rc_t::OK);
761 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
763 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
764 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
765 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
766 TRY_CHECK_RC(OM::write(ernest, itf));
768 l3 = new l3_binding(itf, pfx_10);
769 HW::item<bool> hw_l3_bind(true, rc_t::OK);
770 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
771 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
772 TRY_CHECK_RC(OM::write(ernest, *l3));
774 // change the MAC address on the BVI
775 interface itf_new_mac(bvi_name,
776 interface::type_t::BVI,
777 interface::admin_state_t::UP);
778 l2_address_t l2_addr({0,1,2,3,4,5});
779 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
780 itf_new_mac.set(l2_addr);
781 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
782 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
784 // create/write the interface to the OM again but with an unset MAC
785 // this should not generate a MAC address update
786 TRY_CHECK_RC(OM::write(ernest, itf));
788 // change the MAC address on the BVI - again
789 interface itf_new_mac2(bvi_name,
790 interface::type_t::BVI,
791 interface::admin_state_t::UP);
792 l2_address_t l2_addr2({0,1,2,3,4,6});
793 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
794 itf_new_mac2.set(l2_addr2);
795 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
796 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
799 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
800 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
801 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
802 TRY_CHECK(OM::remove(ernest));
805 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
808 HW::item<bool> hw_rd4_create(true, rc_t::OK);
809 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
810 HW::item<bool> hw_rd6_create(true, rc_t::OK);
811 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
812 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
813 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
814 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
815 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
816 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
817 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
818 TRY_CHECK_RC(OM::write(graham, rd));
820 const std::string bvi2_name = "bvi2";
821 interface *itf2 = new interface(bvi2_name,
822 interface::type_t::BVI,
823 interface::admin_state_t::UP,
825 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
827 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
828 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
829 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
830 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
831 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
833 TRY_CHECK_RC(OM::write(graham, *itf2));
835 l3 = new l3_binding(*itf2, pfx_10);
836 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
837 TRY_CHECK_RC(OM::write(graham, *l3));
842 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
843 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
844 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
845 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
846 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
847 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
848 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
849 TRY_CHECK(OM::remove(graham));
852 BOOST_AUTO_TEST_CASE(test_bond) {
854 const std::string cb = "CarolBerg";
858 * creates the interfaces
860 std::string itf1_name = "afpacket1";
861 interface itf1(itf1_name,
862 interface::type_t::AFPACKET,
863 interface::admin_state_t::UP);
865 HW::item<handle_t> hw_ifh(2, rc_t::OK);
866 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
868 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
869 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
871 TRY_CHECK_RC(OM::write(cb, itf1));
873 std::string itf2_name = "afpacket2";
874 interface itf2(itf2_name,
875 interface::type_t::AFPACKET,
876 interface::admin_state_t::UP);
879 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
880 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
881 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
883 TRY_CHECK_RC(OM::write(cb, itf2));
885 std::string bond_name = "bond";
886 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
887 bond_interface::mode_t::LACP);
889 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
890 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
891 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
892 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
894 TRY_CHECK_RC(OM::write(cb, bond_itf));
896 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
897 bond_member::rate_t::SLOW);
898 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
899 bond_member::rate_t::SLOW);
900 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
902 HW::item<bool> bond_hw_bind(true, rc_t::OK);
903 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
904 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
906 TRY_CHECK_RC(OM::write(cb, *bgb));
913 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
914 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
915 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
916 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
917 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
918 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
919 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
920 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
921 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
923 TRY_CHECK(OM::remove(cb));
926 BOOST_AUTO_TEST_CASE(test_bridge) {
928 const std::string franz = "FranzKafka";
929 const std::string dante = "Dante";
930 const std::string jkr = "jkrowling";
934 * Franz creates an interface, Bridge-domain, then binds the two
938 std::string itf1_name = "afpacket1";
939 interface itf1(itf1_name,
940 interface::type_t::AFPACKET,
941 interface::admin_state_t::UP);
943 HW::item<handle_t> hw_ifh(3, rc_t::OK);
944 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
946 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
947 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
949 TRY_CHECK_RC(OM::write(franz, itf1));
951 // bridge-domain create
952 bridge_domain bd1(33);
954 HW::item<uint32_t> hw_bd(33, rc_t::OK);
955 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
956 bridge_domain::learning_mode_t::ON,
957 bridge_domain::arp_term_mode_t::ON,
958 bridge_domain::flood_mode_t::ON,
959 bridge_domain::mac_age_mode_t::OFF));
961 TRY_CHECK_RC(OM::write(franz, bd1));
963 // L2-interface create and bind
964 // this needs to be delete'd before the flush below, since it too maintains
965 // references to the BD and Interface
966 l2_binding *l2itf = new l2_binding(itf1, bd1);
967 HW::item<bool> hw_l2_bind(true, rc_t::OK);
969 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
972 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
973 TRY_CHECK_RC(OM::write(franz, *l2itf));
976 * Dante adds an interface to the same BD
978 std::string itf2_name = "afpacket2";
979 interface itf2(itf2_name,
980 interface::type_t::AFPACKET,
981 interface::admin_state_t::UP);
983 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
984 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
985 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
986 TRY_CHECK_RC(OM::write(dante, itf2));
988 // BD add is a no-op since it exists
989 TRY_CHECK_RC(OM::write(dante, bd1));
991 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
992 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
993 l2itf2->set(l2_vtr::option_t::POP_1, 68);
995 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
998 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
999 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
1000 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1002 // Add some static entries to the bridge-domain
1003 HW::item<bool> hw_be1(true, rc_t::OK);
1004 mac_address_t mac1({0,1,2,3,4,5});
1005 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
1006 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1008 TRY_CHECK_RC(OM::write(dante, *be1));
1010 // Add some entries to the bridge-domain ARP termination table
1011 HW::item<bool> hw_bea1(true, rc_t::OK);
1012 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1014 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
1015 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
1016 TRY_CHECK_RC(OM::write(dante, *bea1));
1018 // flush Franz's state
1020 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1022 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1025 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1026 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1027 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1028 TRY_CHECK(OM::remove(franz));
1030 // flush Dante's state - the order the interface and BD are deleted
1031 // is an uncontrollable artifact of the C++ object destruction.
1036 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1037 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
1038 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1041 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1043 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1044 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1045 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1046 TRY_CHECK(OM::remove(dante));
1048 // test the BVI entry in l2fib
1049 bridge_domain bd2(99);
1051 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1052 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1053 bridge_domain::learning_mode_t::ON,
1054 bridge_domain::arp_term_mode_t::ON,
1055 bridge_domain::flood_mode_t::ON,
1056 bridge_domain::mac_age_mode_t::OFF));
1058 TRY_CHECK_RC(OM::write(jkr, bd2));
1060 std::string itf3_name = "bvi";
1061 interface itf3(itf3_name,
1062 interface::type_t::BVI,
1063 interface::admin_state_t::UP);
1065 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1066 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1067 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1068 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1069 TRY_CHECK_RC(OM::write(jkr, itf3));
1071 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1072 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1075 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1076 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1078 HW::item<bool> hw_be2(true, rc_t::OK);
1079 mac_address_t mac2({0,1,2,3,4,5});
1080 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1081 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1082 TRY_CHECK_RC(OM::write(jkr, *be2));
1087 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1090 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1091 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1092 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1093 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1094 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1095 TRY_CHECK(OM::remove(jkr));
1098 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1100 const std::string nicholas = "NicholasAbercrombie";
1106 std::string itf1_name = "host1";
1107 interface itf1(itf1_name,
1108 interface::type_t::AFPACKET,
1109 interface::admin_state_t::UP);
1110 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1111 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1112 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1113 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1114 TRY_CHECK_RC(OM::write(nicholas, itf1));
1119 std::string itf2_name = "host2";
1120 interface itf2(itf2_name,
1121 interface::type_t::AFPACKET,
1122 interface::admin_state_t::UP);
1124 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1125 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1126 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1127 TRY_CHECK_RC(OM::write(nicholas, itf2));
1129 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1130 HW::item<bool> xconnect_east(true, rc_t::OK);
1131 HW::item<bool> xconnect_west(true, rc_t::OK);
1132 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1133 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1134 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1135 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1136 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1140 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1142 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1143 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1144 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1145 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1146 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1147 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1149 TRY_CHECK(OM::remove(nicholas));
1152 BOOST_AUTO_TEST_CASE(test_vxlan) {
1154 const std::string franz = "FranzKafka";
1158 * Franz creates an interface, Bridge-domain, then binds the two
1162 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1163 boost::asio::ip::address::from_string("10.10.10.11"),
1166 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1168 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1169 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1170 handle_t::INVALID));
1172 TRY_CHECK_RC(OM::write(franz, vxt));
1174 // bridge-domain create
1175 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1176 bridge_domain::arp_term_mode_t::OFF,
1177 bridge_domain::flood_mode_t::OFF,
1178 bridge_domain::mac_age_mode_t::ON);
1180 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1181 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1182 bridge_domain::learning_mode_t::OFF,
1183 bridge_domain::arp_term_mode_t::OFF,
1184 bridge_domain::flood_mode_t::OFF,
1185 bridge_domain::mac_age_mode_t::ON));
1187 TRY_CHECK_RC(OM::write(franz, bd1));
1189 // L2-interface create and bind
1190 // this needs to be delete'd before the flush below, since it too maintains
1191 // references to the BD and Interface
1192 l2_binding *l2itf = new l2_binding(vxt, bd1);
1193 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1195 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1198 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1199 TRY_CHECK_RC(OM::write(franz, *l2itf));
1201 // flush Franz's state
1203 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1205 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1208 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1209 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1210 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1211 TRY_CHECK(OM::remove(franz));
1214 BOOST_AUTO_TEST_CASE(test_vlan) {
1216 const std::string noam = "NoamChomsky";
1219 std::string itf1_name = "host1";
1220 interface itf1(itf1_name,
1221 interface::type_t::AFPACKET,
1222 interface::admin_state_t::UP);
1224 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1225 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1227 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1228 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1230 TRY_CHECK_RC(OM::write(noam, itf1));
1232 sub_interface *vl33 = new sub_interface(itf1,
1233 interface::admin_state_t::UP,
1236 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1237 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1238 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1240 TRY_CHECK_RC(OM::write(noam, *vl33));
1243 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1244 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1245 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1246 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1247 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1248 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1250 TRY_CHECK(OM::remove(noam));
1253 BOOST_AUTO_TEST_CASE(test_acl) {
1255 const std::string fyodor = "FyodorDostoyevsky";
1256 const std::string leo = "LeoTolstoy";
1260 * Fyodor adds an ACL in the input direction
1262 std::string itf1_name = "host1";
1263 interface itf1(itf1_name,
1264 interface::type_t::AFPACKET,
1265 interface::admin_state_t::UP);
1266 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1267 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1268 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1269 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1270 TRY_CHECK_RC(OM::write(fyodor, itf1));
1272 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1273 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1274 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1275 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1276 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1277 HW::item<bool> ae_binding(true, rc_t::OK);
1278 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1279 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1281 route::prefix_t src("10.10.10.10", 32);
1282 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1283 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1285 std::string acl_name = "acl1";
1286 ACL::l3_list acl1(acl_name);
1289 ACL::l3_list::rules_t rules = {r1, r2};
1291 HW::item<handle_t> hw_acl(2, rc_t::OK);
1292 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1293 TRY_CHECK_RC(OM::write(fyodor, acl1));
1295 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1296 ACL::l3_list acl2(acl_name);
1298 ACL::l3_list::rules_t rules2 = {r3};
1299 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1300 TRY_CHECK_RC(OM::write(fyodor, acl2));
1302 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1303 HW::item<bool> hw_binding(true, rc_t::OK);
1304 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1305 hw_ifh.data(), hw_acl.data()));
1306 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1309 * Leo adds an L2 ACL in the output direction
1311 TRY_CHECK_RC(OM::write(leo, itf1));
1313 std::string l2_acl_name = "l2_acl1";
1314 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1315 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1316 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1317 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1319 ACL::l2_list l2_acl(l2_acl_name);
1320 l2_acl.insert(l2_r2);
1321 l2_acl.insert(l2_r1);
1323 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1325 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1326 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1327 TRY_CHECK_RC(OM::write(leo, l2_acl));
1329 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1330 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1331 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1332 hw_ifh.data(), l2_hw_acl.data()));
1333 TRY_CHECK_RC(OM::write(leo, *l2b));
1336 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1337 hw_ifh.data(), l2_hw_acl.data()));
1338 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1339 TRY_CHECK(OM::remove(leo));
1343 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1346 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1347 hw_ifh.data(), hw_acl.data()));
1348 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1349 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1350 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1351 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1353 TRY_CHECK(OM::remove(fyodor));
1356 BOOST_AUTO_TEST_CASE(test_igmp) {
1358 const std::string Isaiah = "IsaiahBerlin";
1361 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1362 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1363 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
1365 std::string itf3_name = "host3";
1366 interface itf3(itf3_name,
1367 interface::type_t::AFPACKET,
1368 interface::admin_state_t::UP);
1369 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1370 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1371 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1372 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1373 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1375 igmp_binding *ib = new igmp_binding(itf3);
1376 HW::item<bool> hw_binding(true, rc_t::OK);
1377 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1378 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1380 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1382 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1383 HW::item<bool> hw_as_listen(true, rc_t::OK);
1384 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1385 TRY_CHECK_RC(OM::write(Isaiah, *il));
1390 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1393 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1394 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1395 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1396 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1398 TRY_CHECK(OM::remove(Isaiah));
1401 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1403 const std::string kurt = "KurtVonnegut";
1406 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1407 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1409 arp_proxy_config ap(low, high);
1410 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1411 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1412 TRY_CHECK_RC(OM::write(kurt, ap));
1414 std::string itf3_name = "host3";
1415 interface itf3(itf3_name,
1416 interface::type_t::AFPACKET,
1417 interface::admin_state_t::UP);
1418 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1419 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1420 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1421 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1422 TRY_CHECK_RC(OM::write(kurt, itf3));
1424 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1425 HW::item<bool> hw_binding(true, rc_t::OK);
1426 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1427 TRY_CHECK_RC(OM::write(kurt, *apb));
1431 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1434 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1435 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1436 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1437 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1439 TRY_CHECK(OM::remove(kurt));
1442 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1444 const std::string eliot = "EliotReed";
1448 * Interface 1 is the tx interface
1450 std::string itf1_name = "tx-itf";
1451 interface itf1(itf1_name,
1452 interface::type_t::AFPACKET,
1453 interface::admin_state_t::UP);
1454 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1455 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1456 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1457 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1458 TRY_CHECK_RC(OM::write(eliot, itf1));
1460 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1463 * Interface 2 is the rx interface
1465 std::string itf2_name = "rx-itf";
1466 interface itf2(itf2_name,
1467 interface::type_t::AFPACKET,
1468 interface::admin_state_t::UP);
1470 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1471 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1472 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1473 TRY_CHECK_RC(OM::write(eliot, itf2));
1475 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1476 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1477 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1478 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1479 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1483 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1485 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1486 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1487 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1488 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1489 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1491 TRY_CHECK(OM::remove(eliot));
1494 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1496 const std::string eric = "EricAmbler";
1500 * Interface 1 has the L3 address
1502 std::string itf1_name = "host1";
1503 interface itf1(itf1_name,
1504 interface::type_t::AFPACKET,
1505 interface::admin_state_t::UP);
1506 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1507 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1508 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1509 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1510 TRY_CHECK_RC(OM::write(eric, itf1));
1512 route::prefix_t pfx_10("10.10.10.10", 24);
1513 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1514 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1515 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1516 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1517 TRY_CHECK_RC(OM::write(eric, *l3));
1520 * Interface 2 is unnumbered
1522 std::string itf2_name = "host2";
1523 interface itf2(itf2_name,
1524 interface::type_t::AFPACKET,
1525 interface::admin_state_t::UP);
1527 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1528 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1529 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1530 TRY_CHECK_RC(OM::write(eric, itf2));
1532 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1533 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1534 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1535 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1536 TRY_CHECK_RC(OM::write(eric, *ipun));
1541 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1543 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1544 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1545 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1546 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1547 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1548 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1550 TRY_CHECK(OM::remove(eric));
1553 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1555 const std::string paulo = "PauloCoelho";
1561 std::string itf_name = "host_ip6nd";
1562 interface itf(itf_name,
1563 interface::type_t::AFPACKET,
1564 interface::admin_state_t::UP);
1565 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1566 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1567 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1568 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1569 TRY_CHECK_RC(OM::write(paulo, itf));
1571 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1572 l3_binding *l3 = new l3_binding(itf, pfx_10);
1573 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1574 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1575 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1576 TRY_CHECK_RC(OM::write(paulo, *l3));
1578 ra_config ra(0, 1, 0, 4);
1579 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1580 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1581 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1582 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1583 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1588 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1589 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1590 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1591 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1592 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1593 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1597 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1602 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1605 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1606 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1607 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1608 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1610 TRY_CHECK(OM::remove(paulo));
1613 BOOST_AUTO_TEST_CASE(test_interface_span) {
1615 const std::string elif = "ElifShafak";
1619 * Interface 1 to be mirrored
1621 std::string itf1_name = "port-from";
1622 interface itf1(itf1_name,
1623 interface::type_t::AFPACKET,
1624 interface::admin_state_t::UP);
1625 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1626 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1627 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1628 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1629 TRY_CHECK_RC(OM::write(elif, itf1));
1632 * Interface 2 where traffic is mirrored
1634 std::string itf2_name = "port-to";
1635 interface itf2(itf2_name,
1636 interface::type_t::AFPACKET,
1637 interface::admin_state_t::UP);
1639 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1640 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1642 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1643 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1644 TRY_CHECK_RC(OM::write(elif, itf2));
1646 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1647 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1648 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1649 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1650 TRY_CHECK_RC(OM::write(elif, *itf_span));
1652 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1653 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1657 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1658 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1659 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1660 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1661 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1663 TRY_CHECK(OM::remove(elif));
1666 BOOST_AUTO_TEST_CASE(test_routing) {
1668 const std::string ian = "IanFleming";
1672 * non-default route domain
1674 route_domain rd4(1);
1675 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1676 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1677 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1678 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1679 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1680 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1681 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1682 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1683 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1684 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1685 TRY_CHECK_RC(OM::write(ian, rd4));
1688 * a couple of interfaces
1690 std::string itf1_name = "af1";
1691 interface itf1(itf1_name,
1692 interface::type_t::AFPACKET,
1693 interface::admin_state_t::UP);
1694 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1695 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1696 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1697 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1698 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1699 TRY_CHECK_RC(OM::write(ian, itf1));
1701 std::string itf2_name = "af2";
1702 interface *itf2 = new interface(itf2_name,
1703 interface::type_t::AFPACKET,
1704 interface::admin_state_t::UP,
1707 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1708 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1709 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1710 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1711 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1712 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1713 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1714 TRY_CHECK_RC(OM::write(ian, *itf2));
1717 * prefix on each interface
1719 route::prefix_t pfx_10("10.10.10.10", 24);
1720 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1721 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1722 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1723 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1724 TRY_CHECK_RC(OM::write(ian, *l3_10));
1725 route::prefix_t pfx_11("11.11.11.11", 24);
1726 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1727 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1728 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1729 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1730 TRY_CHECK_RC(OM::write(ian, *l3_11));
1733 * A route via interface 1 in the default table
1735 route::prefix_t pfx_5("5.5.5.5", 32);
1736 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1737 route::path *path_9 = new route::path(nh_9, itf1);
1738 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1739 route::path *path_10 = new route::path(nh_10, itf1);
1740 route::ip_route *route_5 = new route::ip_route(pfx_5);
1741 route_5->add(*path_10);
1742 route_5->add(*path_9);
1743 HW::item<bool> hw_route_5(true, rc_t::OK);
1744 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_9));
1745 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_10));
1746 TRY_CHECK_RC(OM::write(ian, *route_5));
1748 route_5->remove(*path_9);
1749 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_9));
1750 TRY_CHECK_RC(OM::write(ian, *route_5));
1755 * A route via interface 2 in the non-default table
1757 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1758 route::path *path_11 = new route::path(nh_11, *itf2);
1759 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1760 route::path *path_12 = new route::path(nh_12, *itf2);
1761 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1762 route_5_2->add(*path_11);
1763 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1764 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1765 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1767 route_5_2->add(*path_12);
1768 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1769 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1772 * An ARP entry for the neighbour on itf1
1774 HW::item<bool> hw_neighbour(true, rc_t::OK);
1775 mac_address_t mac_n({0,1,2,4,5,6});
1776 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1777 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1779 neighbour::flags_t::STATIC));
1780 TRY_CHECK_RC(OM::write(ian, *ne));
1785 route::prefix_t pfx_6("6.6.6.6", 32);
1786 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1787 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1788 route_dvr->add(*path_l2);
1789 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1790 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1791 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1796 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1797 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1799 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1800 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1801 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1802 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1803 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1804 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1805 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1806 *mp1, route::itf_flags_t::FORWARD));
1807 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1808 *mp2, route::itf_flags_t::FORWARD));
1809 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1810 *mp1, route::itf_flags_t::ACCEPT));
1811 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1814 // delete the stack objects that hold references to others
1815 // so the OM::remove is the call that removes the last reference
1825 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1826 *mp1, route::itf_flags_t::FORWARD));
1827 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1828 *mp2, route::itf_flags_t::FORWARD));
1829 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1830 *mp1, route::itf_flags_t::ACCEPT));
1835 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1837 neighbour::flags_t::STATIC));
1838 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1839 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1840 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1841 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_10));
1848 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1849 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1850 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1851 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1852 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1853 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1854 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1855 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1856 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1857 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1859 TRY_CHECK(OM::remove(ian));
1862 BOOST_AUTO_TEST_CASE(test_nat) {
1864 const std::string gs = "GeorgeSimenon";
1870 std::string itf_in_name = "inside";
1871 interface itf_in(itf_in_name,
1872 interface::type_t::AFPACKET,
1873 interface::admin_state_t::UP);
1874 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1875 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1876 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1877 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1879 TRY_CHECK_RC(OM::write(gs, itf_in));
1884 std::string itf_out_name = "port-to";
1885 interface itf_out(itf_out_name,
1886 interface::type_t::AFPACKET,
1887 interface::admin_state_t::UP);
1889 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1890 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1891 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1893 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1894 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1895 TRY_CHECK_RC(OM::write(gs, itf_out));
1898 * A NAT static mapping
1900 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1901 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1903 nat_static ns(in_addr, out_addr);
1904 HW::item<bool> hw_ns(true, rc_t::OK);
1906 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1907 TRY_CHECK_RC(OM::write(gs, ns));
1910 * bind nat inside and out
1912 nat_binding *nb_in = new nat_binding(itf_in,
1915 nat_binding::zone_t::INSIDE);
1916 HW::item<bool> hw_nb_in(true, rc_t::OK);
1918 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1919 hw_ifh.data().value(),
1920 nat_binding::zone_t::INSIDE));
1921 TRY_CHECK_RC(OM::write(gs, *nb_in));
1923 nat_binding *nb_out = new nat_binding(itf_out,
1926 nat_binding::zone_t::OUTSIDE);
1927 HW::item<bool> hw_nb_out(true, rc_t::OK);
1929 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1930 hw_ifh2.data().value(),
1931 nat_binding::zone_t::OUTSIDE));
1932 TRY_CHECK_RC(OM::write(gs, *nb_out));
1938 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1939 hw_ifh.data().value(),
1940 nat_binding::zone_t::INSIDE));
1941 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1942 hw_ifh2.data().value(),
1943 nat_binding::zone_t::OUTSIDE));
1944 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1945 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1946 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1947 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1948 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1950 TRY_CHECK(OM::remove(gs));
1953 BOOST_AUTO_TEST_CASE(test_interface_events) {
1957 HW::item<bool> hw_want(true, rc_t::OK);
1959 ADD_EXPECT(interface_cmds::events_cmd(ml));
1960 cmd* itf = new interface_cmds::events_cmd(ml);
1966 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1968 const std::string rene = "ReneGoscinny";
1972 * Create an interface with two IP addresses
1974 std::string itf1_name = "host1";
1975 interface itf1(itf1_name,
1976 interface::type_t::AFPACKET,
1977 interface::admin_state_t::UP);
1978 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1979 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1980 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1981 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1982 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1983 TRY_CHECK_RC(OM::write(rene, itf1));
1985 route::prefix_t pfx_10("10.10.10.10", 24);
1986 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1987 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1988 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1989 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1990 TRY_CHECK_RC(OM::write(rene, *l3_1));
1992 route::prefix_t pfx_11("10.10.11.11", 24);
1993 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1994 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1995 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1996 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1997 TRY_CHECK_RC(OM::write(rene, *l3_2));
2000 HW::item<bool> hw_rd_create(true, rc_t::OK);
2001 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2002 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2003 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2004 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2005 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2006 TRY_CHECK_RC(OM::write(rene, rd));
2009 * update the interface to change to a new route-domain
2010 * expect that the l3-bindings are removed and readded.
2012 interface *itf2 = new interface(itf1_name,
2013 interface::type_t::AFPACKET,
2014 interface::admin_state_t::UP,
2016 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2017 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2018 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2019 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2020 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2021 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2022 TRY_CHECK_RC(OM::write(rene, *itf2));
2025 * mve the interface back to the default route-domain
2027 interface itf3(itf1_name,
2028 interface::type_t::AFPACKET,
2029 interface::admin_state_t::UP);
2030 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2031 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2032 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2033 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2034 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2035 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2036 TRY_CHECK_RC(OM::write(rene, itf3));
2043 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2044 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2045 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2046 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2047 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2048 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2050 TRY_CHECK(OM::remove(rene));
2053 BOOST_AUTO_TEST_CASE(test_prefixes) {
2054 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2056 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2058 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2060 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2061 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2063 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2064 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2065 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2067 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2069 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2071 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2073 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2074 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2075 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2077 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2079 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2080 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2081 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2083 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2085 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2086 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2087 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2091 BOOST_AUTO_TEST_CASE(test_pipes) {
2093 const std::string gk = "GKChesterton";
2095 const std::string pipe_name_1 = "pipe1";
2096 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2097 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2098 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2100 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2102 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2104 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2105 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2106 TRY_CHECK_RC(OM::write(gk, pipe1));
2108 pipe1.set_ends(hw_hdl_pair.data());
2110 // put each end of the pipe in a BD
2111 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2112 bridge_domain::arp_term_mode_t::OFF,
2113 bridge_domain::flood_mode_t::OFF,
2114 bridge_domain::mac_age_mode_t::ON);
2116 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2117 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2118 bridge_domain::learning_mode_t::OFF,
2119 bridge_domain::arp_term_mode_t::OFF,
2120 bridge_domain::flood_mode_t::OFF,
2121 bridge_domain::mac_age_mode_t::ON));
2123 TRY_CHECK_RC(OM::write(gk, bd1));
2125 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2126 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2128 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2129 pipe1.east()->handle(),
2131 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2132 TRY_CHECK_RC(OM::write(gk, *l2_1));
2134 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2135 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2137 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2138 pipe1.west()->handle(),
2140 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2141 TRY_CHECK_RC(OM::write(gk, *l2_2));
2147 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2148 pipe1.east()->handle(),
2150 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2151 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2152 pipe1.west()->handle(),
2154 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2155 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2156 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2157 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2158 TRY_CHECK(OM::remove(gk));
2161 BOOST_AUTO_TEST_SUITE_END()