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::bvi_create_cmd))
195 rc = handle_derived<interface_cmds::bvi_create_cmd>(f_exp, f_act);
197 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
199 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
201 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
203 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
205 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
207 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
209 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_delete_cmd))
211 rc = handle_derived<interface_cmds::bvi_delete_cmd>(f_exp, f_act);
213 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
215 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
217 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
219 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
221 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
223 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
225 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
227 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
229 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
231 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
233 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
235 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
237 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
239 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
241 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
243 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
245 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
247 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
249 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
251 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
253 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
255 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
257 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
259 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
261 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
263 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
265 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
267 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
269 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
271 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
273 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
275 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
277 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
279 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
281 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
283 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
285 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
287 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
289 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
291 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
293 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
295 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
297 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
299 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
301 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
303 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
305 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
307 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
309 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
311 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
313 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
315 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
317 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
319 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
321 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
323 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
325 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
327 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
329 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
331 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
333 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
335 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
337 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
339 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
341 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
343 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
345 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
347 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
349 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
351 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
353 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
355 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
357 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
359 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
361 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
363 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
365 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
367 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
369 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
371 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
373 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
375 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
377 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
379 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
381 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
383 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
385 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
387 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
389 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
391 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
393 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
395 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
397 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
399 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
401 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
403 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
405 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
407 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
409 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
411 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
413 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
415 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
417 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
419 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
421 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
423 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
425 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
427 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
429 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
431 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
433 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
435 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
437 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
439 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
441 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
443 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
445 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
447 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
449 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
451 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
453 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
455 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
457 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
459 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
461 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
463 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
465 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
467 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
469 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
471 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
473 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
475 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
477 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
479 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
481 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
483 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
485 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
487 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
491 throw ExpException(2);
494 // if we get here then we found the match.
495 m_exp_queue.erase(it_exp);
496 m_act_queue.erase(it_act);
500 // return any injected failures to the agent
501 if (rc_t::OK != rc && rc_t::NOOP != rc)
509 catch (ExpException &e)
511 // The expected and actual do not match
514 // in strict ordering mode this is fatal, so rethrow
519 // move the iterator onto the next in the expected list and
527 throw ExpException(3);
534 template <typename T>
535 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
540 i_exp = dynamic_cast<const T*>(f_exp);
541 i_act = dynamic_cast<T*>(f_act);
542 if (!(*i_exp == *i_act))
544 throw ExpException(4);
546 // pass the data and return code to the agent
547 i_act->item() = i_exp->item();
549 return (i_act->item().rc());
552 // The Q to push the expectations on
553 std::deque<cmd*> m_exp_queue;
555 // the queue to push the actual events on
556 std::deque<cmd*> m_act_queue;
558 // control whether the expected queue is strictly ordered.
573 logger().set(log_level_t::DEBUG);
581 BOOST_AUTO_TEST_SUITE(vom)
583 #define TRY_CHECK_RC(stmt) \
586 BOOST_CHECK(rc_t::OK == stmt); \
588 catch (ExpException &e) \
590 BOOST_CHECK(false); \
592 BOOST_CHECK(vi.f->is_empty()); \
595 #define TRY_CHECK(stmt) \
600 catch (ExpException &e) \
602 BOOST_CHECK(false); \
604 BOOST_CHECK(vi.f->is_empty()); \
607 #define ADD_EXPECT(stmt) \
608 vi.f->expect(new stmt)
610 #define STRICT_ORDER_OFF() \
611 vi.f->strict_order(false)
613 BOOST_AUTO_TEST_CASE(test_interface) {
615 const std::string go = "GeorgeOrwell";
616 const std::string js = "JohnSteinbeck";
620 * George creates and deletes the interface
622 std::string itf1_name = "afpacket1";
623 interface itf1(itf1_name,
624 interface::type_t::AFPACKET,
625 interface::admin_state_t::UP);
628 * set the expectation for a afpacket interface create.
629 * 2 is the interface handle VPP [mock] assigns
631 HW::item<handle_t> hw_ifh(2, rc_t::OK);
632 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
634 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
635 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
637 TRY_CHECK_RC(OM::write(go, itf1));
639 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
640 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
641 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
643 TRY_CHECK(OM::remove(go));
646 * George creates the interface, then John brings it down.
647 * George's remove is a no-op, sice John also owns the interface
649 interface itf1b(itf1_name,
650 interface::type_t::AFPACKET,
651 interface::admin_state_t::DOWN);
653 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
654 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
655 TRY_CHECK_RC(OM::write(go, itf1));
657 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
658 TRY_CHECK_RC(OM::write(js, itf1b));
660 TRY_CHECK(OM::remove(go));
662 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
663 TRY_CHECK(OM::remove(js));
666 * George adds an interface, then we flush all of Geroge's state
668 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
669 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
670 TRY_CHECK_RC(OM::write(go, itf1));
672 TRY_CHECK(OM::mark(go));
674 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
675 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
676 TRY_CHECK(OM::sweep(go));
679 * George adds an interface. mark stale. update the same interface. sweep
680 * and expect no delete
682 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
683 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
684 TRY_CHECK_RC(OM::write(go, itf1b));
686 TRY_CHECK(OM::mark(go));
688 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
689 TRY_CHECK_RC(OM::write(go, itf1));
691 TRY_CHECK(OM::sweep(go));
693 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
694 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
695 TRY_CHECK(OM::remove(go));
698 * George adds an insterface, then we mark that state. Add a second interface
699 * an flush the first that is now stale.
701 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
702 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
703 TRY_CHECK_RC(OM::write(go, itf1));
705 TRY_CHECK(OM::mark(go));
707 std::string itf2_name = "afpacket2";
708 std::string itf2_tag = "uuid-of-afpacket2-interface";
709 interface itf2(itf2_name,
710 interface::type_t::AFPACKET,
711 interface::admin_state_t::UP,
713 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
715 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
716 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
717 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
718 TRY_CHECK_RC(OM::write(go, itf2));
720 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
721 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
722 TRY_CHECK(OM::sweep(go));
724 TRY_CHECK(OM::mark(go));
726 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
727 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
728 TRY_CHECK(OM::sweep(go));
731 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
732 std::string itf3_tag = "uuid-of-vhost_user1-interface";
733 interface itf3(itf3_name,
734 interface::type_t::VHOST,
735 interface::admin_state_t::UP,
737 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
739 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
740 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
741 TRY_CHECK_RC(OM::write(go, itf3));
743 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
744 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
745 TRY_CHECK(OM::remove(go));
748 BOOST_AUTO_TEST_CASE(test_bvi) {
750 const std::string ernest = "ErnestHemmingway";
751 const std::string graham = "GrahamGreene";
755 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
757 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
761 * Enrest creates a BVI with address 10.10.10.10/24
763 route::prefix_t pfx_10("10.10.10.10", 24);
765 const std::string bvi_name = "bvi1";
766 interface itf(bvi_name,
767 interface::type_t::BVI,
768 interface::admin_state_t::UP);
769 HW::item<handle_t> hw_ifh(4, rc_t::OK);
770 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
772 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh, bvi_name));
773 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
774 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
775 TRY_CHECK_RC(OM::write(ernest, itf));
777 l3 = new l3_binding(itf, pfx_10);
778 HW::item<bool> hw_l3_bind(true, rc_t::OK);
779 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
780 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
781 TRY_CHECK_RC(OM::write(ernest, *l3));
783 // change the MAC address on the BVI
784 interface itf_new_mac(bvi_name,
785 interface::type_t::BVI,
786 interface::admin_state_t::UP);
787 l2_address_t l2_addr({0,1,2,3,4,5});
788 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
789 itf_new_mac.set(l2_addr);
790 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
791 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
793 // create/write the interface to the OM again but with an unset MAC
794 // this should not generate a MAC address update
795 TRY_CHECK_RC(OM::write(ernest, itf));
797 // change the MAC address on the BVI - again
798 interface itf_new_mac2(bvi_name,
799 interface::type_t::BVI,
800 interface::admin_state_t::UP);
801 l2_address_t l2_addr2({0,1,2,3,4,6});
802 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
803 itf_new_mac2.set(l2_addr2);
804 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
805 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
808 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
809 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
810 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh));
811 TRY_CHECK(OM::remove(ernest));
814 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
817 HW::item<bool> hw_rd4_create(true, rc_t::OK);
818 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
819 HW::item<bool> hw_rd6_create(true, rc_t::OK);
820 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
821 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
822 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
823 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
824 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
825 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
826 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
827 TRY_CHECK_RC(OM::write(graham, rd));
829 const std::string bvi2_name = "bvi2";
830 interface *itf2 = new interface(bvi2_name,
831 interface::type_t::BVI,
832 interface::admin_state_t::UP,
834 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
836 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh2, bvi2_name));
837 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
838 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
839 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
840 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
842 TRY_CHECK_RC(OM::write(graham, *itf2));
844 l3 = new l3_binding(*itf2, pfx_10);
845 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
846 TRY_CHECK_RC(OM::write(graham, *l3));
851 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
852 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
853 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
854 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
855 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh2));
856 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
857 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
858 TRY_CHECK(OM::remove(graham));
861 BOOST_AUTO_TEST_CASE(test_bond) {
863 const std::string cb = "CarolBerg";
867 * creates the interfaces
869 std::string itf1_name = "afpacket1";
870 interface itf1(itf1_name,
871 interface::type_t::AFPACKET,
872 interface::admin_state_t::UP);
874 HW::item<handle_t> hw_ifh(2, rc_t::OK);
875 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
877 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
880 TRY_CHECK_RC(OM::write(cb, itf1));
882 std::string itf2_name = "afpacket2";
883 interface itf2(itf2_name,
884 interface::type_t::AFPACKET,
885 interface::admin_state_t::UP);
888 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
889 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
890 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
892 TRY_CHECK_RC(OM::write(cb, itf2));
894 std::string bond_name = "bond";
895 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
896 bond_interface::mode_t::LACP);
898 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
899 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
900 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
901 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
903 TRY_CHECK_RC(OM::write(cb, bond_itf));
905 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
906 bond_member::rate_t::SLOW);
907 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
908 bond_member::rate_t::SLOW);
909 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
911 HW::item<bool> bond_hw_bind(true, rc_t::OK);
912 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
913 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
915 TRY_CHECK_RC(OM::write(cb, *bgb));
922 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
923 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
924 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
925 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
926 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
927 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
928 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
929 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
930 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
932 TRY_CHECK(OM::remove(cb));
935 BOOST_AUTO_TEST_CASE(test_bridge) {
937 const std::string franz = "FranzKafka";
938 const std::string dante = "Dante";
939 const std::string jkr = "jkrowling";
943 * Franz creates an interface, Bridge-domain, then binds the two
947 std::string itf1_name = "afpacket1";
948 interface itf1(itf1_name,
949 interface::type_t::AFPACKET,
950 interface::admin_state_t::UP);
952 HW::item<handle_t> hw_ifh(3, rc_t::OK);
953 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
955 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
956 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
958 TRY_CHECK_RC(OM::write(franz, itf1));
960 // bridge-domain create
961 bridge_domain bd1(33);
963 HW::item<uint32_t> hw_bd(33, rc_t::OK);
964 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
965 bridge_domain::learning_mode_t::ON,
966 bridge_domain::arp_term_mode_t::ON,
967 bridge_domain::arp_ufwd_mode_t::ON,
968 bridge_domain::flood_mode_t::ON,
969 bridge_domain::uu_flood_mode_t::ON,
970 bridge_domain::mac_age_mode_t::OFF));
972 TRY_CHECK_RC(OM::write(franz, bd1));
974 // L2-interface create and bind
975 // this needs to be delete'd before the flush below, since it too maintains
976 // references to the BD and Interface
977 l2_binding *l2itf = new l2_binding(itf1, bd1);
978 HW::item<bool> hw_l2_bind(true, rc_t::OK);
980 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
983 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
984 TRY_CHECK_RC(OM::write(franz, *l2itf));
987 * Dante adds an interface to the same BD
989 std::string itf2_name = "afpacket2";
990 interface itf2(itf2_name,
991 interface::type_t::AFPACKET,
992 interface::admin_state_t::UP);
994 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
995 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
996 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
997 TRY_CHECK_RC(OM::write(dante, itf2));
999 // BD add is a no-op since it exists
1000 TRY_CHECK_RC(OM::write(dante, bd1));
1002 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
1003 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
1004 l2itf2->set(l2_vtr::option_t::POP_1, 68);
1006 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1009 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1010 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
1011 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1013 // Add some static entries to the bridge-domain
1014 HW::item<bool> hw_be1(true, rc_t::OK);
1015 mac_address_t mac1({0,1,2,3,4,5});
1016 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
1017 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1019 TRY_CHECK_RC(OM::write(dante, *be1));
1021 // Add some entries to the bridge-domain ARP termination table
1022 HW::item<bool> hw_bea1(true, rc_t::OK);
1023 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1025 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
1026 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
1027 TRY_CHECK_RC(OM::write(dante, *bea1));
1029 // flush Franz's state
1031 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1033 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1036 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1037 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1038 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1039 TRY_CHECK(OM::remove(franz));
1041 // flush Dante's state - the order the interface and BD are deleted
1042 // is an uncontrollable artifact of the C++ object destruction.
1047 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1048 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
1049 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1052 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1054 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1055 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1056 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1057 TRY_CHECK(OM::remove(dante));
1059 // test the BVI entry in l2fib
1060 bridge_domain bd2(99);
1062 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1063 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1064 bridge_domain::learning_mode_t::ON,
1065 bridge_domain::arp_term_mode_t::ON,
1066 bridge_domain::arp_ufwd_mode_t::ON,
1067 bridge_domain::flood_mode_t::ON,
1068 bridge_domain::uu_flood_mode_t::ON,
1069 bridge_domain::mac_age_mode_t::OFF));
1071 TRY_CHECK_RC(OM::write(jkr, bd2));
1073 std::string itf3_name = "bvi";
1074 interface itf3(itf3_name,
1075 interface::type_t::BVI,
1076 interface::admin_state_t::UP);
1078 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1079 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh3, itf3_name));
1080 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1081 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1082 TRY_CHECK_RC(OM::write(jkr, itf3));
1084 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1085 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1088 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1089 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1091 HW::item<bool> hw_be2(true, rc_t::OK);
1092 mac_address_t mac2({0,1,2,3,4,5});
1093 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1094 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1095 TRY_CHECK_RC(OM::write(jkr, *be2));
1100 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1103 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1104 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1105 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1106 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh3));
1107 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1108 TRY_CHECK(OM::remove(jkr));
1111 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1113 const std::string nicholas = "NicholasAbercrombie";
1119 std::string itf1_name = "host1";
1120 interface itf1(itf1_name,
1121 interface::type_t::AFPACKET,
1122 interface::admin_state_t::UP);
1123 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1124 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1125 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1126 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1127 TRY_CHECK_RC(OM::write(nicholas, itf1));
1132 std::string itf2_name = "host2";
1133 interface itf2(itf2_name,
1134 interface::type_t::AFPACKET,
1135 interface::admin_state_t::UP);
1137 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1138 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1139 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1140 TRY_CHECK_RC(OM::write(nicholas, itf2));
1142 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1143 HW::item<bool> xconnect_east(true, rc_t::OK);
1144 HW::item<bool> xconnect_west(true, rc_t::OK);
1145 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1146 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1147 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1148 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1149 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1153 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1155 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1156 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1157 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1158 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1159 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1160 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1162 TRY_CHECK(OM::remove(nicholas));
1165 BOOST_AUTO_TEST_CASE(test_vxlan) {
1167 const std::string franz = "FranzKafka";
1171 * Franz creates an interface, Bridge-domain, then binds the two
1175 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1176 boost::asio::ip::address::from_string("10.10.10.11"),
1179 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1181 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1182 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1183 handle_t::INVALID));
1185 TRY_CHECK_RC(OM::write(franz, vxt));
1187 // bridge-domain create
1188 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1189 bridge_domain::arp_term_mode_t::OFF,
1190 bridge_domain::arp_ufwd_mode_t::OFF,
1191 bridge_domain::flood_mode_t::OFF,
1192 bridge_domain::uu_flood_mode_t::OFF,
1193 bridge_domain::mac_age_mode_t::ON);
1195 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1196 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1197 bridge_domain::learning_mode_t::OFF,
1198 bridge_domain::arp_term_mode_t::OFF,
1199 bridge_domain::arp_ufwd_mode_t::OFF,
1200 bridge_domain::flood_mode_t::OFF,
1201 bridge_domain::uu_flood_mode_t::OFF,
1202 bridge_domain::mac_age_mode_t::ON));
1204 TRY_CHECK_RC(OM::write(franz, bd1));
1206 // L2-interface create and bind
1207 // this needs to be delete'd before the flush below, since it too maintains
1208 // references to the BD and Interface
1209 l2_binding *l2itf = new l2_binding(vxt, bd1);
1210 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1212 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1215 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1216 TRY_CHECK_RC(OM::write(franz, *l2itf));
1218 // flush Franz's state
1220 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1222 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1225 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1226 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1227 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1228 TRY_CHECK(OM::remove(franz));
1231 BOOST_AUTO_TEST_CASE(test_vlan) {
1233 const std::string noam = "NoamChomsky";
1236 std::string itf1_name = "host1";
1237 interface itf1(itf1_name,
1238 interface::type_t::AFPACKET,
1239 interface::admin_state_t::UP);
1241 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1242 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1244 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1245 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1247 TRY_CHECK_RC(OM::write(noam, itf1));
1249 sub_interface *vl33 = new sub_interface(itf1,
1250 interface::admin_state_t::UP,
1253 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1254 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1255 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1257 TRY_CHECK_RC(OM::write(noam, *vl33));
1260 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1261 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1262 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1263 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1264 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1265 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1267 TRY_CHECK(OM::remove(noam));
1270 BOOST_AUTO_TEST_CASE(test_acl) {
1272 const std::string fyodor = "FyodorDostoyevsky";
1273 const std::string leo = "LeoTolstoy";
1277 * Fyodor adds an ACL in the input direction
1279 std::string itf1_name = "host1";
1280 interface itf1(itf1_name,
1281 interface::type_t::AFPACKET,
1282 interface::admin_state_t::UP);
1283 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1284 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1285 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1286 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1287 TRY_CHECK_RC(OM::write(fyodor, itf1));
1289 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1290 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1291 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1292 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1293 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1294 HW::item<bool> ae_binding(true, rc_t::OK);
1295 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1296 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1298 route::prefix_t src("10.10.10.10", 32);
1299 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1300 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1302 std::string acl_name = "acl1";
1303 ACL::l3_list acl1(acl_name);
1306 ACL::l3_list::rules_t rules = {r1, r2};
1308 HW::item<handle_t> hw_acl(2, rc_t::OK);
1309 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1310 TRY_CHECK_RC(OM::write(fyodor, acl1));
1312 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1313 ACL::l3_list acl2(acl_name);
1315 ACL::l3_list::rules_t rules2 = {r3};
1316 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1317 TRY_CHECK_RC(OM::write(fyodor, acl2));
1319 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1320 HW::item<bool> hw_binding(true, rc_t::OK);
1321 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1322 hw_ifh.data(), hw_acl.data()));
1323 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1326 * Leo adds an L2 ACL in the output direction
1328 TRY_CHECK_RC(OM::write(leo, itf1));
1330 std::string l2_acl_name = "l2_acl1";
1331 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1332 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1333 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1334 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1336 ACL::l2_list l2_acl(l2_acl_name);
1337 l2_acl.insert(l2_r2);
1338 l2_acl.insert(l2_r1);
1340 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1342 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1343 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1344 TRY_CHECK_RC(OM::write(leo, l2_acl));
1346 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1347 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1348 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1349 hw_ifh.data(), l2_hw_acl.data()));
1350 TRY_CHECK_RC(OM::write(leo, *l2b));
1353 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1354 hw_ifh.data(), l2_hw_acl.data()));
1355 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1356 TRY_CHECK(OM::remove(leo));
1360 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1363 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1364 hw_ifh.data(), hw_acl.data()));
1365 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1366 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1367 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1368 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1370 TRY_CHECK(OM::remove(fyodor));
1373 BOOST_AUTO_TEST_CASE(test_igmp) {
1375 const std::string Isaiah = "IsaiahBerlin";
1378 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1379 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1380 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
1382 std::string itf3_name = "host3";
1383 interface itf3(itf3_name,
1384 interface::type_t::AFPACKET,
1385 interface::admin_state_t::UP);
1386 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1387 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1388 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1389 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1390 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1392 igmp_binding *ib = new igmp_binding(itf3);
1393 HW::item<bool> hw_binding(true, rc_t::OK);
1394 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1395 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1397 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1399 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1400 HW::item<bool> hw_as_listen(true, rc_t::OK);
1401 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1402 TRY_CHECK_RC(OM::write(Isaiah, *il));
1407 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1410 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1411 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1412 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1413 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1415 TRY_CHECK(OM::remove(Isaiah));
1418 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1420 const std::string kurt = "KurtVonnegut";
1423 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1424 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1426 arp_proxy_config ap(low, high);
1427 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1428 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1429 TRY_CHECK_RC(OM::write(kurt, ap));
1431 std::string itf3_name = "host3";
1432 interface itf3(itf3_name,
1433 interface::type_t::AFPACKET,
1434 interface::admin_state_t::UP);
1435 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1436 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1437 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1438 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1439 TRY_CHECK_RC(OM::write(kurt, itf3));
1441 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1442 HW::item<bool> hw_binding(true, rc_t::OK);
1443 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1444 TRY_CHECK_RC(OM::write(kurt, *apb));
1448 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1451 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1452 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1453 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1454 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1456 TRY_CHECK(OM::remove(kurt));
1459 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1461 const std::string eliot = "EliotReed";
1465 * Interface 1 is the tx interface
1467 std::string itf1_name = "tx-itf";
1468 interface itf1(itf1_name,
1469 interface::type_t::AFPACKET,
1470 interface::admin_state_t::UP);
1471 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1472 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1473 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1474 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1475 TRY_CHECK_RC(OM::write(eliot, itf1));
1477 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1480 * Interface 2 is the rx interface
1482 std::string itf2_name = "rx-itf";
1483 interface itf2(itf2_name,
1484 interface::type_t::AFPACKET,
1485 interface::admin_state_t::UP);
1487 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1488 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1489 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1490 TRY_CHECK_RC(OM::write(eliot, itf2));
1492 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1493 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1494 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1495 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1496 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1500 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1502 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1503 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1504 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1505 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1506 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1508 TRY_CHECK(OM::remove(eliot));
1511 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1513 const std::string eric = "EricAmbler";
1517 * Interface 1 has the L3 address
1519 std::string itf1_name = "host1";
1520 interface itf1(itf1_name,
1521 interface::type_t::AFPACKET,
1522 interface::admin_state_t::UP);
1523 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1524 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1525 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1526 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1527 TRY_CHECK_RC(OM::write(eric, itf1));
1529 route::prefix_t pfx_10("10.10.10.10", 24);
1530 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1531 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1532 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1533 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1534 TRY_CHECK_RC(OM::write(eric, *l3));
1537 * Interface 2 is unnumbered
1539 std::string itf2_name = "host2";
1540 interface itf2(itf2_name,
1541 interface::type_t::AFPACKET,
1542 interface::admin_state_t::UP);
1544 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1545 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1546 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1547 TRY_CHECK_RC(OM::write(eric, itf2));
1549 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1550 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1551 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1552 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1553 TRY_CHECK_RC(OM::write(eric, *ipun));
1558 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1560 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1561 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1562 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1563 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1564 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1565 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1567 TRY_CHECK(OM::remove(eric));
1570 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1572 const std::string paulo = "PauloCoelho";
1578 std::string itf_name = "host_ip6nd";
1579 interface itf(itf_name,
1580 interface::type_t::AFPACKET,
1581 interface::admin_state_t::UP);
1582 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1583 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1584 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1585 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1586 TRY_CHECK_RC(OM::write(paulo, itf));
1588 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1589 l3_binding *l3 = new l3_binding(itf, pfx_10);
1590 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1591 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1592 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1593 TRY_CHECK_RC(OM::write(paulo, *l3));
1595 ra_config ra(0, 1, 0, 4);
1596 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1597 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1598 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1599 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1600 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1605 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1606 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1607 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1608 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1609 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1610 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1614 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1619 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1622 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1623 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1624 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1625 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1627 TRY_CHECK(OM::remove(paulo));
1630 BOOST_AUTO_TEST_CASE(test_interface_span) {
1632 const std::string elif = "ElifShafak";
1636 * Interface 1 to be mirrored
1638 std::string itf1_name = "port-from";
1639 interface itf1(itf1_name,
1640 interface::type_t::AFPACKET,
1641 interface::admin_state_t::UP);
1642 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1643 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1644 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1645 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1646 TRY_CHECK_RC(OM::write(elif, itf1));
1649 * Interface 2 where traffic is mirrored
1651 std::string itf2_name = "port-to";
1652 interface itf2(itf2_name,
1653 interface::type_t::AFPACKET,
1654 interface::admin_state_t::UP);
1656 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1657 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1659 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1660 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1661 TRY_CHECK_RC(OM::write(elif, itf2));
1663 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1664 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1665 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1666 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1667 TRY_CHECK_RC(OM::write(elif, *itf_span));
1669 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1670 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1674 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1675 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1676 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1677 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1678 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1680 TRY_CHECK(OM::remove(elif));
1683 BOOST_AUTO_TEST_CASE(test_routing) {
1685 const std::string ian = "IanFleming";
1689 * non-default route domain
1691 route_domain rd4(1);
1692 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1693 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1694 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1695 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1696 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1697 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1698 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1699 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1700 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1701 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1702 TRY_CHECK_RC(OM::write(ian, rd4));
1705 * a couple of interfaces
1707 std::string itf1_name = "af1";
1708 interface itf1(itf1_name,
1709 interface::type_t::AFPACKET,
1710 interface::admin_state_t::UP);
1711 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1712 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1713 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1714 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1715 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1716 TRY_CHECK_RC(OM::write(ian, itf1));
1718 std::string itf2_name = "af2";
1719 interface *itf2 = new interface(itf2_name,
1720 interface::type_t::AFPACKET,
1721 interface::admin_state_t::UP,
1724 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1725 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1726 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1727 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1728 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1729 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1730 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1731 TRY_CHECK_RC(OM::write(ian, *itf2));
1734 * prefix on each interface
1736 route::prefix_t pfx_10("10.10.10.10", 24);
1737 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1738 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1739 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1740 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1741 TRY_CHECK_RC(OM::write(ian, *l3_10));
1742 route::prefix_t pfx_11("11.11.11.11", 24);
1743 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1744 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1745 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1746 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1747 TRY_CHECK_RC(OM::write(ian, *l3_11));
1750 * A route via interface 1 in the default table
1752 route::prefix_t pfx_5("5.5.5.5", 32);
1753 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1754 route::path *path_9 = new route::path(nh_9, itf1);
1755 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1756 route::path *path_10 = new route::path(nh_10, itf1);
1757 route::ip_route *route_5 = new route::ip_route(pfx_5);
1758 route_5->add(*path_10);
1759 route_5->add(*path_9);
1760 HW::item<bool> hw_route_5(true, rc_t::OK);
1761 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_9));
1762 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, *path_10));
1763 TRY_CHECK_RC(OM::write(ian, *route_5));
1765 route_5->remove(*path_9);
1766 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_9));
1767 TRY_CHECK_RC(OM::write(ian, *route_5));
1772 * A route via interface 2 in the non-default table
1774 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1775 route::path *path_11 = new route::path(nh_11, *itf2);
1776 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1777 route::path *path_12 = new route::path(nh_12, *itf2);
1778 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1779 route_5_2->add(*path_11);
1780 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1781 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1782 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1784 route_5_2->add(*path_12);
1785 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1786 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1789 * An ARP entry for the neighbour on itf1
1791 HW::item<bool> hw_neighbour(true, rc_t::OK);
1792 mac_address_t mac_n({0,1,2,4,5,6});
1793 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1794 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1796 neighbour::flags_t::STATIC));
1797 TRY_CHECK_RC(OM::write(ian, *ne));
1802 route::prefix_t pfx_6("6.6.6.6", 32);
1803 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1804 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1805 route_dvr->add(*path_l2);
1806 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1807 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1808 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1813 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1814 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1816 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1817 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1818 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1819 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1820 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1821 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1822 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1823 *mp1, route::itf_flags_t::FORWARD));
1824 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1825 *mp2, route::itf_flags_t::FORWARD));
1826 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1827 *mp1, route::itf_flags_t::ACCEPT));
1828 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1831 // delete the stack objects that hold references to others
1832 // so the OM::remove is the call that removes the last reference
1842 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1843 *mp1, route::itf_flags_t::FORWARD));
1844 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1845 *mp2, route::itf_flags_t::FORWARD));
1846 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1847 *mp1, route::itf_flags_t::ACCEPT));
1852 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1854 neighbour::flags_t::STATIC));
1855 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6, *path_l2));
1856 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_11));
1857 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5, *path_12));
1858 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5, *path_10));
1865 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1866 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1867 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1868 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1869 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1870 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1871 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1872 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1873 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1874 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1876 TRY_CHECK(OM::remove(ian));
1879 BOOST_AUTO_TEST_CASE(test_nat) {
1881 const std::string gs = "GeorgeSimenon";
1887 std::string itf_in_name = "inside";
1888 interface itf_in(itf_in_name,
1889 interface::type_t::AFPACKET,
1890 interface::admin_state_t::UP);
1891 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1892 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1893 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1894 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1895 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1896 TRY_CHECK_RC(OM::write(gs, itf_in));
1901 std::string itf_out_name = "port-to";
1902 interface itf_out(itf_out_name,
1903 interface::type_t::AFPACKET,
1904 interface::admin_state_t::UP);
1906 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1907 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1908 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1910 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1911 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1912 TRY_CHECK_RC(OM::write(gs, itf_out));
1915 * A NAT static mapping
1917 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1918 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1920 nat_static ns(in_addr, out_addr);
1921 HW::item<bool> hw_ns(true, rc_t::OK);
1923 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1924 TRY_CHECK_RC(OM::write(gs, ns));
1927 * bind nat inside and out
1929 nat_binding *nb_in = new nat_binding(itf_in,
1932 nat_binding::zone_t::INSIDE);
1933 HW::item<bool> hw_nb_in(true, rc_t::OK);
1935 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1936 hw_ifh.data().value(),
1937 nat_binding::zone_t::INSIDE));
1938 TRY_CHECK_RC(OM::write(gs, *nb_in));
1940 nat_binding *nb_out = new nat_binding(itf_out,
1943 nat_binding::zone_t::OUTSIDE);
1944 HW::item<bool> hw_nb_out(true, rc_t::OK);
1946 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1947 hw_ifh2.data().value(),
1948 nat_binding::zone_t::OUTSIDE));
1949 TRY_CHECK_RC(OM::write(gs, *nb_out));
1955 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1956 hw_ifh.data().value(),
1957 nat_binding::zone_t::INSIDE));
1958 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1959 hw_ifh2.data().value(),
1960 nat_binding::zone_t::OUTSIDE));
1961 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1962 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1963 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1964 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1965 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1967 TRY_CHECK(OM::remove(gs));
1970 BOOST_AUTO_TEST_CASE(test_interface_events) {
1974 HW::item<bool> hw_want(true, rc_t::OK);
1976 ADD_EXPECT(interface_cmds::events_cmd(ml));
1977 cmd* itf = new interface_cmds::events_cmd(ml);
1983 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1985 const std::string rene = "ReneGoscinny";
1989 * Create an interface with two IP addresses
1991 std::string itf1_name = "host1";
1992 interface itf1(itf1_name,
1993 interface::type_t::AFPACKET,
1994 interface::admin_state_t::UP);
1995 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1996 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1997 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1998 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1999 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
2000 TRY_CHECK_RC(OM::write(rene, itf1));
2002 route::prefix_t pfx_10("10.10.10.10", 24);
2003 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
2004 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
2005 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
2006 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2007 TRY_CHECK_RC(OM::write(rene, *l3_1));
2009 route::prefix_t pfx_11("10.10.11.11", 24);
2010 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
2011 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
2012 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
2013 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2014 TRY_CHECK_RC(OM::write(rene, *l3_2));
2017 HW::item<bool> hw_rd_create(true, rc_t::OK);
2018 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2019 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2020 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2021 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2022 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2023 TRY_CHECK_RC(OM::write(rene, rd));
2026 * update the interface to change to a new route-domain
2027 * expect that the l3-bindings are removed and readded.
2029 interface *itf2 = new interface(itf1_name,
2030 interface::type_t::AFPACKET,
2031 interface::admin_state_t::UP,
2033 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2034 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2035 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2036 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2037 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2038 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2039 TRY_CHECK_RC(OM::write(rene, *itf2));
2042 * mve the interface back to the default route-domain
2044 interface itf3(itf1_name,
2045 interface::type_t::AFPACKET,
2046 interface::admin_state_t::UP);
2047 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2048 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2049 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2050 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2051 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2052 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2053 TRY_CHECK_RC(OM::write(rene, itf3));
2060 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2061 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2062 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2063 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2064 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2065 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2067 TRY_CHECK(OM::remove(rene));
2070 BOOST_AUTO_TEST_CASE(test_prefixes) {
2071 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2073 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2075 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2077 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2078 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2080 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2081 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2082 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2084 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2086 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2088 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2090 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2091 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2092 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2094 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2096 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2097 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2098 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2100 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2102 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2103 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2104 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2108 BOOST_AUTO_TEST_CASE(test_pipes) {
2110 const std::string gk = "GKChesterton";
2112 const std::string pipe_name_1 = "pipe1";
2113 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2114 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2115 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2117 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2119 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2121 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2122 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2123 TRY_CHECK_RC(OM::write(gk, pipe1));
2125 pipe1.set_ends(hw_hdl_pair.data());
2127 // put each end of the pipe in a BD
2128 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2129 bridge_domain::arp_term_mode_t::OFF,
2130 bridge_domain::arp_ufwd_mode_t::ON,
2131 bridge_domain::flood_mode_t::OFF,
2132 bridge_domain::uu_flood_mode_t::ON,
2133 bridge_domain::mac_age_mode_t::ON);
2135 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2136 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2137 bridge_domain::learning_mode_t::OFF,
2138 bridge_domain::arp_term_mode_t::OFF,
2139 bridge_domain::arp_ufwd_mode_t::ON,
2140 bridge_domain::flood_mode_t::OFF,
2141 bridge_domain::uu_flood_mode_t::ON,
2142 bridge_domain::mac_age_mode_t::ON));
2144 TRY_CHECK_RC(OM::write(gk, bd1));
2146 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2147 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2149 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2150 pipe1.east()->handle(),
2152 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2153 TRY_CHECK_RC(OM::write(gk, *l2_1));
2155 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2156 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2158 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2159 pipe1.west()->handle(),
2161 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2162 TRY_CHECK_RC(OM::write(gk, *l2_2));
2168 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2169 pipe1.east()->handle(),
2171 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2172 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2173 pipe1.west()->handle(),
2175 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2176 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2177 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2178 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2179 TRY_CHECK(OM::remove(gk));
2182 BOOST_AUTO_TEST_SUITE_END()