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_l2_list.hpp"
52 #include "vom/acl_l3_list.hpp"
53 #include "vom/acl_binding.hpp"
54 #include "vom/acl_list_cmds.hpp"
55 #include "vom/acl_binding_cmds.hpp"
56 #include "vom/acl_l3_rule.hpp"
57 #include "vom/acl_l2_rule.hpp"
58 #include "vom/arp_proxy_config.hpp"
59 #include "vom/arp_proxy_binding.hpp"
60 #include "vom/arp_proxy_config_cmds.hpp"
61 #include "vom/arp_proxy_binding_cmds.hpp"
62 #include "vom/igmp_binding.hpp"
63 #include "vom/igmp_binding_cmds.hpp"
64 #include "vom/igmp_listen.hpp"
65 #include "vom/igmp_listen_cmds.hpp"
66 #include "vom/ip_punt_redirect.hpp"
67 #include "vom/ip_punt_redirect_cmds.hpp"
68 #include "vom/ip_unnumbered.hpp"
69 #include "vom/ip_unnumbered_cmds.hpp"
70 #include "vom/interface_ip6_nd.hpp"
71 #include "vom/interface_span.hpp"
72 #include "vom/interface_span_cmds.hpp"
73 #include "vom/neighbour.hpp"
74 #include "vom/neighbour_cmds.hpp"
75 #include "vom/nat_static.hpp"
76 #include "vom/nat_static_cmds.hpp"
77 #include "vom/nat_binding.hpp"
78 #include "vom/nat_binding_cmds.hpp"
79 #include "vom/pipe.hpp"
80 #include "vom/pipe_cmds.hpp"
82 using namespace boost;
86 * An expectation exception
91 ExpException(unsigned int number)
93 // a neat place to add a break point
94 std::cout << " ExpException here: " << number << std::endl;
98 class MockListener : public interface::event_listener,
99 public interface::stat_listener
101 void handle_interface_stat(const interface& itf)
104 void handle_interface_event(std::vector<VOM::interface::event> events)
109 class MockCmdQ : public HW::cmd_q
121 m_exp_queue.push_back(f);
125 m_act_queue.push_back(f);
127 void enqueue(std::queue<cmd*> &cmds)
131 m_act_queue.push_back(cmds.front());
135 void enqueue(std::shared_ptr<cmd> f)
137 m_act_queue.push_back(f.get());
144 void dequeue(std::shared_ptr<cmd> cmd)
148 void strict_order(bool on)
155 return ((0 == m_exp_queue.size()) &&
156 (0 == m_act_queue.size()));
164 while (m_act_queue.size())
166 bool matched = false;
167 auto it_exp = m_exp_queue.begin();
168 auto it_act = m_act_queue.begin();
172 std::cout << " Act: " << f_act->to_string() << std::endl;
173 while (it_exp != m_exp_queue.end())
178 std::cout << " Exp: " << f_exp->to_string() << std::endl;
180 if (typeid(*f_exp) != typeid(*f_act))
182 throw ExpException(1);
185 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
187 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
189 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
191 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
193 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
195 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
197 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
199 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
201 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
203 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
205 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
207 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
209 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
211 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
213 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
215 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
217 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
219 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
221 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
223 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
225 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
227 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
229 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
231 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
233 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
235 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
237 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
239 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
241 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
243 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
245 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
247 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
249 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
251 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
253 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
255 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
257 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
259 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
261 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
263 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
265 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
267 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
269 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
271 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
273 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
275 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
277 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
279 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
281 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
283 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
285 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
287 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
289 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
291 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
293 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
295 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
297 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
299 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
301 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
303 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
305 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
307 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
309 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
311 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
313 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
315 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
317 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
319 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
321 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
323 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
325 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
327 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
329 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
331 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
333 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
335 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
337 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
339 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
341 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
343 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
345 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
347 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
349 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
351 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
353 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
355 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
357 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
359 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
361 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
363 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
365 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
367 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
369 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
371 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
373 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
375 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
377 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
379 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
381 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
383 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
385 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
387 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
389 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
391 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
393 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
395 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
397 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
399 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
401 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
403 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
405 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
407 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
409 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
411 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
413 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
415 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
417 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
419 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
421 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
423 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
425 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
427 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
429 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
431 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
433 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
435 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
437 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
439 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
441 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
443 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
445 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
447 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
449 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
451 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
453 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
455 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
457 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
459 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
461 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
463 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
465 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
467 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
469 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
471 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
473 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
475 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
477 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
479 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
483 throw ExpException(2);
486 // if we get here then we found the match.
487 m_exp_queue.erase(it_exp);
488 m_act_queue.erase(it_act);
492 // return any injected failures to the agent
493 if (rc_t::OK != rc && rc_t::NOOP != rc)
501 catch (ExpException &e)
503 // The expected and actual do not match
506 // in strict ordering mode this is fatal, so rethrow
511 // move the iterator onto the next in the expected list and
519 throw ExpException(3);
526 template <typename T>
527 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
532 i_exp = dynamic_cast<const T*>(f_exp);
533 i_act = dynamic_cast<T*>(f_act);
534 if (!(*i_exp == *i_act))
536 throw ExpException(4);
538 // pass the data and return code to the agent
539 i_act->item() = i_exp->item();
541 return (i_act->item().rc());
544 // The Q to push the expectations on
545 std::deque<cmd*> m_exp_queue;
547 // the queue to push the actual events on
548 std::deque<cmd*> m_act_queue;
550 // control whether the expected queue is strictly ordered.
565 logger().set(log_level_t::DEBUG);
573 BOOST_AUTO_TEST_SUITE(vom)
575 #define TRY_CHECK_RC(stmt) \
578 BOOST_CHECK(rc_t::OK == stmt); \
580 catch (ExpException &e) \
582 BOOST_CHECK(false); \
584 BOOST_CHECK(vi.f->is_empty()); \
587 #define TRY_CHECK(stmt) \
592 catch (ExpException &e) \
594 BOOST_CHECK(false); \
596 BOOST_CHECK(vi.f->is_empty()); \
599 #define ADD_EXPECT(stmt) \
600 vi.f->expect(new stmt)
602 #define STRICT_ORDER_OFF() \
603 vi.f->strict_order(false)
605 BOOST_AUTO_TEST_CASE(test_interface) {
607 const std::string go = "GeorgeOrwell";
608 const std::string js = "JohnSteinbeck";
612 * George creates and deletes the interface
614 std::string itf1_name = "afpacket1";
615 interface itf1(itf1_name,
616 interface::type_t::AFPACKET,
617 interface::admin_state_t::UP);
620 * set the expectation for a afpacket interface create.
621 * 2 is the interface handle VPP [mock] assigns
623 HW::item<handle_t> hw_ifh(2, rc_t::OK);
624 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
626 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
627 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
629 TRY_CHECK_RC(OM::write(go, itf1));
631 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
632 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
633 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
635 TRY_CHECK(OM::remove(go));
638 * George creates the interface, then John brings it down.
639 * George's remove is a no-op, sice John also owns the interface
641 interface itf1b(itf1_name,
642 interface::type_t::AFPACKET,
643 interface::admin_state_t::DOWN);
645 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
646 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
647 TRY_CHECK_RC(OM::write(go, itf1));
649 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
650 TRY_CHECK_RC(OM::write(js, itf1b));
652 TRY_CHECK(OM::remove(go));
654 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
655 TRY_CHECK(OM::remove(js));
658 * George adds an interface, then we flush all of Geroge's state
660 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
661 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
662 TRY_CHECK_RC(OM::write(go, itf1));
664 TRY_CHECK(OM::mark(go));
666 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
667 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
668 TRY_CHECK(OM::sweep(go));
671 * George adds an interface. mark stale. update the same interface. sweep
672 * and expect no delete
674 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
675 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
676 TRY_CHECK_RC(OM::write(go, itf1b));
678 TRY_CHECK(OM::mark(go));
680 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
681 TRY_CHECK_RC(OM::write(go, itf1));
683 TRY_CHECK(OM::sweep(go));
685 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
686 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
687 TRY_CHECK(OM::remove(go));
690 * George adds an insterface, then we mark that state. Add a second interface
691 * an flush the first that is now stale.
693 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
694 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
695 TRY_CHECK_RC(OM::write(go, itf1));
697 TRY_CHECK(OM::mark(go));
699 std::string itf2_name = "afpacket2";
700 std::string itf2_tag = "uuid-of-afpacket2-interface";
701 interface itf2(itf2_name,
702 interface::type_t::AFPACKET,
703 interface::admin_state_t::UP,
705 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
707 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
708 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
709 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
710 TRY_CHECK_RC(OM::write(go, itf2));
712 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
713 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
714 TRY_CHECK(OM::sweep(go));
716 TRY_CHECK(OM::mark(go));
718 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
719 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
720 TRY_CHECK(OM::sweep(go));
723 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
724 std::string itf3_tag = "uuid-of-vhost_user1-interface";
725 interface itf3(itf3_name,
726 interface::type_t::VHOST,
727 interface::admin_state_t::UP,
729 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
731 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
732 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
733 TRY_CHECK_RC(OM::write(go, itf3));
735 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
736 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
737 TRY_CHECK(OM::remove(go));
740 BOOST_AUTO_TEST_CASE(test_bvi) {
742 const std::string ernest = "ErnestHemmingway";
743 const std::string graham = "GrahamGreene";
747 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
749 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
753 * Enrest creates a BVI with address 10.10.10.10/24
755 route::prefix_t pfx_10("10.10.10.10", 24);
757 const std::string bvi_name = "bvi1";
758 interface itf(bvi_name,
759 interface::type_t::BVI,
760 interface::admin_state_t::UP);
761 HW::item<handle_t> hw_ifh(4, rc_t::OK);
762 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
764 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
765 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
766 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
767 TRY_CHECK_RC(OM::write(ernest, itf));
769 l3 = new l3_binding(itf, pfx_10);
770 HW::item<bool> hw_l3_bind(true, rc_t::OK);
771 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
772 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
773 TRY_CHECK_RC(OM::write(ernest, *l3));
775 // change the MAC address on the BVI
776 interface itf_new_mac(bvi_name,
777 interface::type_t::BVI,
778 interface::admin_state_t::UP);
779 l2_address_t l2_addr({0,1,2,3,4,5});
780 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
781 itf_new_mac.set(l2_addr);
782 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
783 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
785 // create/write the interface to the OM again but with an unset MAC
786 // this should not generate a MAC address update
787 TRY_CHECK_RC(OM::write(ernest, itf));
789 // change the MAC address on the BVI - again
790 interface itf_new_mac2(bvi_name,
791 interface::type_t::BVI,
792 interface::admin_state_t::UP);
793 l2_address_t l2_addr2({0,1,2,3,4,6});
794 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
795 itf_new_mac2.set(l2_addr2);
796 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
797 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
800 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
801 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
802 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
803 TRY_CHECK(OM::remove(ernest));
806 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
809 HW::item<bool> hw_rd4_create(true, rc_t::OK);
810 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
811 HW::item<bool> hw_rd6_create(true, rc_t::OK);
812 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
813 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
814 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
815 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
816 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
817 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
818 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
819 TRY_CHECK_RC(OM::write(graham, rd));
821 const std::string bvi2_name = "bvi2";
822 interface *itf2 = new interface(bvi2_name,
823 interface::type_t::BVI,
824 interface::admin_state_t::UP,
826 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
828 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
829 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
830 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
831 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
832 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
834 TRY_CHECK_RC(OM::write(graham, *itf2));
836 l3 = new l3_binding(*itf2, pfx_10);
837 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
838 TRY_CHECK_RC(OM::write(graham, *l3));
843 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
844 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
845 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
846 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
847 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
848 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
849 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
850 TRY_CHECK(OM::remove(graham));
853 BOOST_AUTO_TEST_CASE(test_bond) {
855 const std::string cb = "CarolBerg";
859 * creates the interfaces
861 std::string itf1_name = "afpacket1";
862 interface itf1(itf1_name,
863 interface::type_t::AFPACKET,
864 interface::admin_state_t::UP);
866 HW::item<handle_t> hw_ifh(2, rc_t::OK);
867 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
869 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
870 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
872 TRY_CHECK_RC(OM::write(cb, itf1));
874 std::string itf2_name = "afpacket2";
875 interface itf2(itf2_name,
876 interface::type_t::AFPACKET,
877 interface::admin_state_t::UP);
880 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
881 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
882 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
884 TRY_CHECK_RC(OM::write(cb, itf2));
886 std::string bond_name = "bond";
887 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
888 bond_interface::mode_t::LACP);
890 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
891 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
892 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
893 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
895 TRY_CHECK_RC(OM::write(cb, bond_itf));
897 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
898 bond_member::rate_t::SLOW);
899 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
900 bond_member::rate_t::SLOW);
901 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
903 HW::item<bool> bond_hw_bind(true, rc_t::OK);
904 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
905 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
907 TRY_CHECK_RC(OM::write(cb, *bgb));
914 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
915 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
916 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
917 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
918 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
919 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
920 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
921 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
922 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
924 TRY_CHECK(OM::remove(cb));
927 BOOST_AUTO_TEST_CASE(test_bridge) {
929 const std::string franz = "FranzKafka";
930 const std::string dante = "Dante";
931 const std::string jkr = "jkrowling";
935 * Franz creates an interface, Bridge-domain, then binds the two
939 std::string itf1_name = "afpacket1";
940 interface itf1(itf1_name,
941 interface::type_t::AFPACKET,
942 interface::admin_state_t::UP);
944 HW::item<handle_t> hw_ifh(3, rc_t::OK);
945 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
947 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
948 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
950 TRY_CHECK_RC(OM::write(franz, itf1));
952 // bridge-domain create
953 bridge_domain bd1(33);
955 HW::item<uint32_t> hw_bd(33, rc_t::OK);
956 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
957 bridge_domain::learning_mode_t::ON,
958 bridge_domain::arp_term_mode_t::ON,
959 bridge_domain::flood_mode_t::ON,
960 bridge_domain::mac_age_mode_t::OFF));
962 TRY_CHECK_RC(OM::write(franz, bd1));
964 // L2-interface create and bind
965 // this needs to be delete'd before the flush below, since it too maintains
966 // references to the BD and Interface
967 l2_binding *l2itf = new l2_binding(itf1, bd1);
968 HW::item<bool> hw_l2_bind(true, rc_t::OK);
970 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
973 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
974 TRY_CHECK_RC(OM::write(franz, *l2itf));
977 * Dante adds an interface to the same BD
979 std::string itf2_name = "afpacket2";
980 interface itf2(itf2_name,
981 interface::type_t::AFPACKET,
982 interface::admin_state_t::UP);
984 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
985 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
986 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
987 TRY_CHECK_RC(OM::write(dante, itf2));
989 // BD add is a no-op since it exists
990 TRY_CHECK_RC(OM::write(dante, bd1));
992 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
993 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
994 l2itf2->set(l2_vtr::option_t::POP_1, 68);
996 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
999 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1000 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
1001 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1003 // Add some static entries to the bridge-domain
1004 HW::item<bool> hw_be1(true, rc_t::OK);
1005 mac_address_t mac1({0,1,2,3,4,5});
1006 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
1007 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1009 TRY_CHECK_RC(OM::write(dante, *be1));
1011 // Add some entries to the bridge-domain ARP termination table
1012 HW::item<bool> hw_bea1(true, rc_t::OK);
1013 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1015 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
1016 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
1017 TRY_CHECK_RC(OM::write(dante, *bea1));
1019 // flush Franz's state
1021 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1023 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1026 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1027 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1028 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1029 TRY_CHECK(OM::remove(franz));
1031 // flush Dante's state - the order the interface and BD are deleted
1032 // is an uncontrollable artifact of the C++ object destruction.
1037 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1038 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
1039 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1042 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1044 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1045 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1046 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1047 TRY_CHECK(OM::remove(dante));
1049 // test the BVI entry in l2fib
1050 bridge_domain bd2(99);
1052 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1053 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1054 bridge_domain::learning_mode_t::ON,
1055 bridge_domain::arp_term_mode_t::ON,
1056 bridge_domain::flood_mode_t::ON,
1057 bridge_domain::mac_age_mode_t::OFF));
1059 TRY_CHECK_RC(OM::write(jkr, bd2));
1061 std::string itf3_name = "bvi";
1062 interface itf3(itf3_name,
1063 interface::type_t::BVI,
1064 interface::admin_state_t::UP);
1066 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1067 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1068 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1069 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1070 TRY_CHECK_RC(OM::write(jkr, itf3));
1072 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1073 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1076 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1077 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1079 HW::item<bool> hw_be2(true, rc_t::OK);
1080 mac_address_t mac2({0,1,2,3,4,5});
1081 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1082 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1083 TRY_CHECK_RC(OM::write(jkr, *be2));
1088 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1091 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1092 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1093 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1094 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1095 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1096 TRY_CHECK(OM::remove(jkr));
1099 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1101 const std::string nicholas = "NicholasAbercrombie";
1107 std::string itf1_name = "host1";
1108 interface itf1(itf1_name,
1109 interface::type_t::AFPACKET,
1110 interface::admin_state_t::UP);
1111 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1112 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1113 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1114 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1115 TRY_CHECK_RC(OM::write(nicholas, itf1));
1120 std::string itf2_name = "host2";
1121 interface itf2(itf2_name,
1122 interface::type_t::AFPACKET,
1123 interface::admin_state_t::UP);
1125 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1126 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1127 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1128 TRY_CHECK_RC(OM::write(nicholas, itf2));
1130 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1131 HW::item<bool> xconnect_east(true, rc_t::OK);
1132 HW::item<bool> xconnect_west(true, rc_t::OK);
1133 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1134 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1135 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1136 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1137 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1141 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1143 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1144 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1145 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1146 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1147 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1148 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1150 TRY_CHECK(OM::remove(nicholas));
1153 BOOST_AUTO_TEST_CASE(test_vxlan) {
1155 const std::string franz = "FranzKafka";
1159 * Franz creates an interface, Bridge-domain, then binds the two
1163 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1164 boost::asio::ip::address::from_string("10.10.10.11"),
1167 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1169 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1170 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1171 handle_t::INVALID));
1173 TRY_CHECK_RC(OM::write(franz, vxt));
1175 // bridge-domain create
1176 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1177 bridge_domain::arp_term_mode_t::OFF,
1178 bridge_domain::flood_mode_t::OFF,
1179 bridge_domain::mac_age_mode_t::ON);
1181 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1182 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1183 bridge_domain::learning_mode_t::OFF,
1184 bridge_domain::arp_term_mode_t::OFF,
1185 bridge_domain::flood_mode_t::OFF,
1186 bridge_domain::mac_age_mode_t::ON));
1188 TRY_CHECK_RC(OM::write(franz, bd1));
1190 // L2-interface create and bind
1191 // this needs to be delete'd before the flush below, since it too maintains
1192 // references to the BD and Interface
1193 l2_binding *l2itf = new l2_binding(vxt, bd1);
1194 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1196 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1199 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1200 TRY_CHECK_RC(OM::write(franz, *l2itf));
1202 // flush Franz's state
1204 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1206 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1209 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1210 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1211 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1212 TRY_CHECK(OM::remove(franz));
1215 BOOST_AUTO_TEST_CASE(test_vlan) {
1217 const std::string noam = "NoamChomsky";
1220 std::string itf1_name = "host1";
1221 interface itf1(itf1_name,
1222 interface::type_t::AFPACKET,
1223 interface::admin_state_t::UP);
1225 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1226 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1228 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1229 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1231 TRY_CHECK_RC(OM::write(noam, itf1));
1233 sub_interface *vl33 = new sub_interface(itf1,
1234 interface::admin_state_t::UP,
1237 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1238 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1239 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1241 TRY_CHECK_RC(OM::write(noam, *vl33));
1244 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1245 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1246 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1247 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1248 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1249 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1251 TRY_CHECK(OM::remove(noam));
1254 BOOST_AUTO_TEST_CASE(test_acl) {
1256 const std::string fyodor = "FyodorDostoyevsky";
1257 const std::string leo = "LeoTolstoy";
1261 * Fyodor adds an ACL in the input direction
1263 std::string itf1_name = "host1";
1264 interface itf1(itf1_name,
1265 interface::type_t::AFPACKET,
1266 interface::admin_state_t::UP);
1267 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1268 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1269 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1270 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1271 TRY_CHECK_RC(OM::write(fyodor, itf1));
1273 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1274 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1275 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1276 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1277 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1278 HW::item<bool> ae_binding(true, rc_t::OK);
1279 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1280 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1282 route::prefix_t src("10.10.10.10", 32);
1283 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1284 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1286 std::string acl_name = "acl1";
1287 ACL::l3_list acl1(acl_name);
1290 ACL::l3_list::rules_t rules = {r1, r2};
1292 HW::item<handle_t> hw_acl(2, rc_t::OK);
1293 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1294 TRY_CHECK_RC(OM::write(fyodor, acl1));
1296 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1297 ACL::l3_list acl2(acl_name);
1299 ACL::l3_list::rules_t rules2 = {r3};
1300 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1301 TRY_CHECK_RC(OM::write(fyodor, acl2));
1303 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1304 HW::item<bool> hw_binding(true, rc_t::OK);
1305 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1306 hw_ifh.data(), hw_acl.data()));
1307 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1310 * Leo adds an L2 ACL in the output direction
1312 TRY_CHECK_RC(OM::write(leo, itf1));
1314 std::string l2_acl_name = "l2_acl1";
1315 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1316 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1317 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1318 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1320 ACL::l2_list l2_acl(l2_acl_name);
1321 l2_acl.insert(l2_r2);
1322 l2_acl.insert(l2_r1);
1324 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1326 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1327 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1328 TRY_CHECK_RC(OM::write(leo, l2_acl));
1330 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1331 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1332 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1333 hw_ifh.data(), l2_hw_acl.data()));
1334 TRY_CHECK_RC(OM::write(leo, *l2b));
1337 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1338 hw_ifh.data(), l2_hw_acl.data()));
1339 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1340 TRY_CHECK(OM::remove(leo));
1344 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1347 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1348 hw_ifh.data(), hw_acl.data()));
1349 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1350 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1351 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1352 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1354 TRY_CHECK(OM::remove(fyodor));
1357 BOOST_AUTO_TEST_CASE(test_igmp) {
1359 const std::string Isaiah = "IsaiahBerlin";
1362 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1363 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1364 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
1366 std::string itf3_name = "host3";
1367 interface itf3(itf3_name,
1368 interface::type_t::AFPACKET,
1369 interface::admin_state_t::UP);
1370 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1371 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1372 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1373 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1374 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1376 igmp_binding *ib = new igmp_binding(itf3);
1377 HW::item<bool> hw_binding(true, rc_t::OK);
1378 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1379 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1381 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1383 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1384 HW::item<bool> hw_as_listen(true, rc_t::OK);
1385 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1386 TRY_CHECK_RC(OM::write(Isaiah, *il));
1391 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1394 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1395 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1396 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1397 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1399 TRY_CHECK(OM::remove(Isaiah));
1402 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1404 const std::string kurt = "KurtVonnegut";
1407 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1408 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1410 arp_proxy_config ap(low, high);
1411 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1412 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1413 TRY_CHECK_RC(OM::write(kurt, ap));
1415 std::string itf3_name = "host3";
1416 interface itf3(itf3_name,
1417 interface::type_t::AFPACKET,
1418 interface::admin_state_t::UP);
1419 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1420 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1421 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1422 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1423 TRY_CHECK_RC(OM::write(kurt, itf3));
1425 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1426 HW::item<bool> hw_binding(true, rc_t::OK);
1427 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1428 TRY_CHECK_RC(OM::write(kurt, *apb));
1432 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1435 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1436 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1437 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1438 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1440 TRY_CHECK(OM::remove(kurt));
1443 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1445 const std::string eliot = "EliotReed";
1449 * Interface 1 is the tx interface
1451 std::string itf1_name = "tx-itf";
1452 interface itf1(itf1_name,
1453 interface::type_t::AFPACKET,
1454 interface::admin_state_t::UP);
1455 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1456 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1457 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1458 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1459 TRY_CHECK_RC(OM::write(eliot, itf1));
1461 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1464 * Interface 2 is the rx interface
1466 std::string itf2_name = "rx-itf";
1467 interface itf2(itf2_name,
1468 interface::type_t::AFPACKET,
1469 interface::admin_state_t::UP);
1471 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1472 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1473 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1474 TRY_CHECK_RC(OM::write(eliot, itf2));
1476 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1477 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1478 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1479 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1480 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1484 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1486 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1487 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1488 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1489 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1490 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1492 TRY_CHECK(OM::remove(eliot));
1495 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1497 const std::string eric = "EricAmbler";
1501 * Interface 1 has the L3 address
1503 std::string itf1_name = "host1";
1504 interface itf1(itf1_name,
1505 interface::type_t::AFPACKET,
1506 interface::admin_state_t::UP);
1507 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1508 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1509 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1510 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1511 TRY_CHECK_RC(OM::write(eric, itf1));
1513 route::prefix_t pfx_10("10.10.10.10", 24);
1514 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1515 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1516 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1517 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1518 TRY_CHECK_RC(OM::write(eric, *l3));
1521 * Interface 2 is unnumbered
1523 std::string itf2_name = "host2";
1524 interface itf2(itf2_name,
1525 interface::type_t::AFPACKET,
1526 interface::admin_state_t::UP);
1528 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1529 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1530 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1531 TRY_CHECK_RC(OM::write(eric, itf2));
1533 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1534 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1535 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1536 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1537 TRY_CHECK_RC(OM::write(eric, *ipun));
1542 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1544 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1545 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1546 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1547 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1548 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1549 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1551 TRY_CHECK(OM::remove(eric));
1554 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1556 const std::string paulo = "PauloCoelho";
1562 std::string itf_name = "host_ip6nd";
1563 interface itf(itf_name,
1564 interface::type_t::AFPACKET,
1565 interface::admin_state_t::UP);
1566 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1567 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1568 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1569 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1570 TRY_CHECK_RC(OM::write(paulo, itf));
1572 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1573 l3_binding *l3 = new l3_binding(itf, pfx_10);
1574 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1575 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1576 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1577 TRY_CHECK_RC(OM::write(paulo, *l3));
1579 ra_config ra(0, 1, 0, 4);
1580 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1581 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1582 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1583 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1584 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1589 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1590 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1591 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1592 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1593 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1594 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1598 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1603 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1606 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1607 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1608 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1609 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1611 TRY_CHECK(OM::remove(paulo));
1614 BOOST_AUTO_TEST_CASE(test_interface_span) {
1616 const std::string elif = "ElifShafak";
1620 * Interface 1 to be mirrored
1622 std::string itf1_name = "port-from";
1623 interface itf1(itf1_name,
1624 interface::type_t::AFPACKET,
1625 interface::admin_state_t::UP);
1626 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1627 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1628 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1629 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1630 TRY_CHECK_RC(OM::write(elif, itf1));
1633 * Interface 2 where traffic is mirrored
1635 std::string itf2_name = "port-to";
1636 interface itf2(itf2_name,
1637 interface::type_t::AFPACKET,
1638 interface::admin_state_t::UP);
1640 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1641 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1643 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1644 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1645 TRY_CHECK_RC(OM::write(elif, itf2));
1647 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1648 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1649 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1650 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1651 TRY_CHECK_RC(OM::write(elif, *itf_span));
1653 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1654 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1658 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1659 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1660 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1661 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1662 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1664 TRY_CHECK(OM::remove(elif));
1667 BOOST_AUTO_TEST_CASE(test_routing) {
1669 const std::string ian = "IanFleming";
1673 * non-default route domain
1675 route_domain rd4(1);
1676 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1677 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1678 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1679 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1680 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1681 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1682 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1683 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1684 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1685 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1686 TRY_CHECK_RC(OM::write(ian, rd4));
1689 * a couple of interfaces
1691 std::string itf1_name = "af1";
1692 interface itf1(itf1_name,
1693 interface::type_t::AFPACKET,
1694 interface::admin_state_t::UP);
1695 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1696 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1697 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1698 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1699 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1700 TRY_CHECK_RC(OM::write(ian, itf1));
1702 std::string itf2_name = "af2";
1703 interface *itf2 = new interface(itf2_name,
1704 interface::type_t::AFPACKET,
1705 interface::admin_state_t::UP,
1708 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1709 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1710 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1711 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1712 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1713 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1714 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1715 TRY_CHECK_RC(OM::write(ian, *itf2));
1718 * prefix on each interface
1720 route::prefix_t pfx_10("10.10.10.10", 24);
1721 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1722 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1723 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1724 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1725 TRY_CHECK_RC(OM::write(ian, *l3_10));
1726 route::prefix_t pfx_11("11.11.11.11", 24);
1727 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1728 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1729 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1730 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1731 TRY_CHECK_RC(OM::write(ian, *l3_11));
1734 * A route via interface 1 in the default table
1736 route::prefix_t pfx_5("5.5.5.5", 32);
1737 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1738 route::path *path_9 = new route::path(nh_9, itf1);
1739 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1740 route::path *path_10 = new route::path(nh_10, itf1);
1741 route::ip_route *route_5 = new route::ip_route(pfx_5);
1742 route_5->add(*path_10);
1743 route_5->add(*path_9);
1744 HW::item<bool> hw_route_5(true, rc_t::OK);
1745 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_9));
1746 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_10));
1747 TRY_CHECK_RC(OM::write(ian, *route_5));
1749 route_5->remove(*path_9);
1750 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_9));
1751 TRY_CHECK_RC(OM::write(ian, *route_5));
1756 * A route via interface 2 in the non-default table
1758 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1759 route::path *path_11 = new route::path(nh_11, *itf2);
1760 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1761 route::path *path_12 = new route::path(nh_12, *itf2);
1762 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1763 route_5_2->add(*path_11);
1764 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1765 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1766 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1768 route_5_2->add(*path_12);
1769 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1770 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1773 * An ARP entry for the neighbour on itf1
1775 HW::item<bool> hw_neighbour(true, rc_t::OK);
1776 mac_address_t mac_n({0,1,2,4,5,6});
1777 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1778 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1780 neighbour::flags_t::STATIC));
1781 TRY_CHECK_RC(OM::write(ian, *ne));
1786 route::prefix_t pfx_6("6.6.6.6", 32);
1787 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1788 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1789 route_dvr->add(*path_l2);
1790 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1791 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1792 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1797 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1798 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1800 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1801 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1802 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1803 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1804 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1805 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1806 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1807 *mp1, route::itf_flags_t::FORWARD));
1808 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1809 *mp2, route::itf_flags_t::FORWARD));
1810 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1811 *mp1, route::itf_flags_t::ACCEPT));
1812 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1815 // delete the stack objects that hold references to others
1816 // so the OM::remove is the call that removes the last reference
1826 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1827 *mp1, route::itf_flags_t::FORWARD));
1828 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1829 *mp2, route::itf_flags_t::FORWARD));
1830 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1831 *mp1, route::itf_flags_t::ACCEPT));
1836 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1838 neighbour::flags_t::STATIC));
1839 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1840 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1841 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1842 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_10));
1849 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1850 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1851 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1852 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1853 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1854 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1855 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1856 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1857 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1858 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1860 TRY_CHECK(OM::remove(ian));
1863 BOOST_AUTO_TEST_CASE(test_nat) {
1865 const std::string gs = "GeorgeSimenon";
1871 std::string itf_in_name = "inside";
1872 interface itf_in(itf_in_name,
1873 interface::type_t::AFPACKET,
1874 interface::admin_state_t::UP);
1875 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1876 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1877 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1878 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1879 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1880 TRY_CHECK_RC(OM::write(gs, itf_in));
1885 std::string itf_out_name = "port-to";
1886 interface itf_out(itf_out_name,
1887 interface::type_t::AFPACKET,
1888 interface::admin_state_t::UP);
1890 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1891 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1892 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1894 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1895 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1896 TRY_CHECK_RC(OM::write(gs, itf_out));
1899 * A NAT static mapping
1901 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1902 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1904 nat_static ns(in_addr, out_addr);
1905 HW::item<bool> hw_ns(true, rc_t::OK);
1907 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1908 TRY_CHECK_RC(OM::write(gs, ns));
1911 * bind nat inside and out
1913 nat_binding *nb_in = new nat_binding(itf_in,
1916 nat_binding::zone_t::INSIDE);
1917 HW::item<bool> hw_nb_in(true, rc_t::OK);
1919 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1920 hw_ifh.data().value(),
1921 nat_binding::zone_t::INSIDE));
1922 TRY_CHECK_RC(OM::write(gs, *nb_in));
1924 nat_binding *nb_out = new nat_binding(itf_out,
1927 nat_binding::zone_t::OUTSIDE);
1928 HW::item<bool> hw_nb_out(true, rc_t::OK);
1930 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1931 hw_ifh2.data().value(),
1932 nat_binding::zone_t::OUTSIDE));
1933 TRY_CHECK_RC(OM::write(gs, *nb_out));
1939 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1940 hw_ifh.data().value(),
1941 nat_binding::zone_t::INSIDE));
1942 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1943 hw_ifh2.data().value(),
1944 nat_binding::zone_t::OUTSIDE));
1945 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1946 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1947 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1948 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1949 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1951 TRY_CHECK(OM::remove(gs));
1954 BOOST_AUTO_TEST_CASE(test_interface_events) {
1958 HW::item<bool> hw_want(true, rc_t::OK);
1960 ADD_EXPECT(interface_cmds::events_cmd(ml));
1961 cmd* itf = new interface_cmds::events_cmd(ml);
1967 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1969 const std::string rene = "ReneGoscinny";
1973 * Create an interface with two IP addresses
1975 std::string itf1_name = "host1";
1976 interface itf1(itf1_name,
1977 interface::type_t::AFPACKET,
1978 interface::admin_state_t::UP);
1979 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1980 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1981 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1982 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1983 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1984 TRY_CHECK_RC(OM::write(rene, itf1));
1986 route::prefix_t pfx_10("10.10.10.10", 24);
1987 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1988 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1989 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1990 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1991 TRY_CHECK_RC(OM::write(rene, *l3_1));
1993 route::prefix_t pfx_11("10.10.11.11", 24);
1994 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1995 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1996 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1997 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1998 TRY_CHECK_RC(OM::write(rene, *l3_2));
2001 HW::item<bool> hw_rd_create(true, rc_t::OK);
2002 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2003 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2004 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2005 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2006 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2007 TRY_CHECK_RC(OM::write(rene, rd));
2010 * update the interface to change to a new route-domain
2011 * expect that the l3-bindings are removed and readded.
2013 interface *itf2 = new interface(itf1_name,
2014 interface::type_t::AFPACKET,
2015 interface::admin_state_t::UP,
2017 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2018 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2019 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2020 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2021 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2022 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2023 TRY_CHECK_RC(OM::write(rene, *itf2));
2026 * mve the interface back to the default route-domain
2028 interface itf3(itf1_name,
2029 interface::type_t::AFPACKET,
2030 interface::admin_state_t::UP);
2031 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2032 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2033 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2034 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2035 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2036 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2037 TRY_CHECK_RC(OM::write(rene, itf3));
2044 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2045 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2046 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2047 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2048 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2049 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2051 TRY_CHECK(OM::remove(rene));
2054 BOOST_AUTO_TEST_CASE(test_prefixes) {
2055 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2057 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2059 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2061 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2062 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2064 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2065 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2066 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2068 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2070 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2072 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2074 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2075 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2076 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2078 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2080 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2081 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2082 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2084 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2086 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2087 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2088 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2092 BOOST_AUTO_TEST_CASE(test_pipes) {
2094 const std::string gk = "GKChesterton";
2096 const std::string pipe_name_1 = "pipe1";
2097 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2098 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2099 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2101 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2103 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2105 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2106 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2107 TRY_CHECK_RC(OM::write(gk, pipe1));
2109 pipe1.set_ends(hw_hdl_pair.data());
2111 // put each end of the pipe in a BD
2112 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2113 bridge_domain::arp_term_mode_t::OFF,
2114 bridge_domain::flood_mode_t::OFF,
2115 bridge_domain::mac_age_mode_t::ON);
2117 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2118 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2119 bridge_domain::learning_mode_t::OFF,
2120 bridge_domain::arp_term_mode_t::OFF,
2121 bridge_domain::flood_mode_t::OFF,
2122 bridge_domain::mac_age_mode_t::ON));
2124 TRY_CHECK_RC(OM::write(gk, bd1));
2126 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2127 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2129 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2130 pipe1.east()->handle(),
2132 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2133 TRY_CHECK_RC(OM::write(gk, *l2_1));
2135 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2136 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2138 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2139 pipe1.west()->handle(),
2141 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2142 TRY_CHECK_RC(OM::write(gk, *l2_2));
2148 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2149 pipe1.east()->handle(),
2151 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2152 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2153 pipe1.west()->handle(),
2155 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2156 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2157 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2158 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2159 TRY_CHECK(OM::remove(gk));
2162 BOOST_AUTO_TEST_SUITE_END()