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"
81 #include "vom/qos_mark.hpp"
82 #include "vom/qos_mark_cmds.hpp"
83 #include "vom/qos_map.hpp"
84 #include "vom/qos_map_cmds.hpp"
85 #include "vom/qos_record.hpp"
86 #include "vom/qos_record_cmds.hpp"
88 using namespace boost;
92 * An expectation exception
97 ExpException(unsigned int number)
99 // a neat place to add a break point
100 // std::cout << " ExpException here: " << number << std::endl;
104 class MockListener : public interface::event_listener,
105 public interface::stat_listener
107 void handle_interface_stat(const interface& itf)
110 void handle_interface_event(std::vector<VOM::interface::event> events)
115 class MockCmdQ : public HW::cmd_q
127 m_exp_queue.push_back(f);
131 m_act_queue.push_back(f);
133 void enqueue(std::queue<cmd*> &cmds)
137 m_act_queue.push_back(cmds.front());
141 void enqueue(std::shared_ptr<cmd> f)
143 m_act_queue.push_back(f.get());
150 void dequeue(std::shared_ptr<cmd> cmd)
154 void strict_order(bool on)
161 return ((0 == m_exp_queue.size()) &&
162 (0 == m_act_queue.size()));
170 while (m_act_queue.size())
172 bool matched = false;
173 auto it_exp = m_exp_queue.begin();
174 auto it_act = m_act_queue.begin();
178 std::cout << " Act: " << f_act->to_string() << std::endl;
179 while (it_exp != m_exp_queue.end())
184 std::cout << " Exp: " << f_exp->to_string() << std::endl;
186 if (typeid(*f_exp) != typeid(*f_act))
188 throw ExpException(1);
191 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
193 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
195 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
197 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
199 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_create_cmd))
201 rc = handle_derived<interface_cmds::bvi_create_cmd>(f_exp, f_act);
203 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
205 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
207 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
209 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
211 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
213 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
215 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_delete_cmd))
217 rc = handle_derived<interface_cmds::bvi_delete_cmd>(f_exp, f_act);
219 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
221 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
223 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
225 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
227 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
229 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
231 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
233 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
235 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
237 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
239 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
241 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
243 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
245 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
247 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
249 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
251 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
253 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
255 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
257 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
259 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
261 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
263 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
265 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
267 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
269 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
271 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
273 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
275 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
277 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
279 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
281 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
283 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
285 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
287 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
289 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
291 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
293 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
295 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
297 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
299 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
301 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
303 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
305 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
307 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
309 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
311 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
313 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
315 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
317 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
319 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
321 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
323 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
325 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
327 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
329 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
331 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
333 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
335 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
337 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
339 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
341 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
343 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
345 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
347 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
349 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
351 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
353 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
355 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
357 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
359 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
361 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
363 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
365 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
367 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
369 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
371 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
373 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
375 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
377 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
379 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
381 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
383 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
385 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
387 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
389 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
391 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
393 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
395 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
397 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
399 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
401 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
403 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
405 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
407 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
409 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
411 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
413 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
415 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
417 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
419 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
421 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
423 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
425 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
427 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
429 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
431 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
433 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
435 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
437 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
439 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
441 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
443 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
445 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
447 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
449 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
451 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
453 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
455 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
457 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
459 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
461 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
463 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
465 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
467 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
469 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
471 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
473 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
475 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
477 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
479 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
481 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
483 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
485 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
487 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
489 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
491 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
493 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
495 else if (typeid(*f_exp) == typeid(QoS::mark_cmds::create_cmd))
497 rc = handle_derived<QoS::mark_cmds::create_cmd>(f_exp, f_act);
499 else if (typeid(*f_exp) == typeid(QoS::mark_cmds::delete_cmd))
501 rc = handle_derived<QoS::mark_cmds::delete_cmd>(f_exp, f_act);
503 else if (typeid(*f_exp) == typeid(QoS::record_cmds::create_cmd))
505 rc = handle_derived<QoS::record_cmds::create_cmd>(f_exp, f_act);
507 else if (typeid(*f_exp) == typeid(QoS::record_cmds::delete_cmd))
509 rc = handle_derived<QoS::record_cmds::delete_cmd>(f_exp, f_act);
511 else if (typeid(*f_exp) == typeid(QoS::map_cmds::create_cmd))
513 rc = handle_derived<QoS::map_cmds::create_cmd>(f_exp, f_act);
515 else if (typeid(*f_exp) == typeid(QoS::map_cmds::delete_cmd))
517 rc = handle_derived<QoS::map_cmds::delete_cmd>(f_exp, f_act);
521 throw ExpException(2);
524 // if we get here then we found the match.
525 m_exp_queue.erase(it_exp);
526 m_act_queue.erase(it_act);
530 // return any injected failures to the agent
531 if (rc_t::OK != rc && rc_t::NOOP != rc)
539 catch (ExpException &e)
541 // The expected and actual do not match
544 // in strict ordering mode this is fatal, so rethrow
549 // move the iterator onto the next in the expected list and
557 throw ExpException(3);
564 template <typename T>
565 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
570 i_exp = dynamic_cast<const T*>(f_exp);
571 i_act = dynamic_cast<T*>(f_act);
572 if (!(*i_exp == *i_act))
574 throw ExpException(4);
576 // pass the data and return code to the agent
577 i_act->item() = i_exp->item();
579 return (i_act->item().rc());
582 // The Q to push the expectations on
583 std::deque<cmd*> m_exp_queue;
585 // the queue to push the actual events on
586 std::deque<cmd*> m_act_queue;
588 // control whether the expected queue is strictly ordered.
603 logger().set(log_level_t::DEBUG);
611 BOOST_AUTO_TEST_SUITE(vom)
613 #define TRY_CHECK_RC(stmt) \
616 BOOST_CHECK(rc_t::OK == stmt); \
618 catch (ExpException &e) \
620 BOOST_CHECK(false); \
622 BOOST_CHECK(vi.f->is_empty()); \
625 #define TRY_CHECK(stmt) \
630 catch (ExpException &e) \
632 BOOST_CHECK(false); \
634 BOOST_CHECK(vi.f->is_empty()); \
637 #define ADD_EXPECT(stmt) \
638 vi.f->expect(new stmt)
640 #define STRICT_ORDER_OFF() \
641 vi.f->strict_order(false)
643 BOOST_AUTO_TEST_CASE(test_interface) {
645 const std::string go = "GeorgeOrwell";
646 const std::string js = "JohnSteinbeck";
650 * George creates and deletes the interface
652 std::string itf1_name = "afpacket1";
653 interface itf1(itf1_name,
654 interface::type_t::AFPACKET,
655 interface::admin_state_t::UP);
658 * set the expectation for a afpacket interface create.
659 * 2 is the interface handle VPP [mock] assigns
661 HW::item<handle_t> hw_ifh(2, rc_t::OK);
662 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
664 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
665 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
667 TRY_CHECK_RC(OM::write(go, itf1));
669 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
670 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
671 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
673 TRY_CHECK(OM::remove(go));
676 * George creates the interface, then John brings it down.
677 * George's remove is a no-op, sice John also owns the interface
679 interface itf1b(itf1_name,
680 interface::type_t::AFPACKET,
681 interface::admin_state_t::DOWN);
683 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
684 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
685 TRY_CHECK_RC(OM::write(go, itf1));
687 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
688 TRY_CHECK_RC(OM::write(js, itf1b));
690 TRY_CHECK(OM::remove(go));
692 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
693 TRY_CHECK(OM::remove(js));
696 * George adds an interface, then we flush all of Geroge's state
698 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
699 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
700 TRY_CHECK_RC(OM::write(go, itf1));
702 TRY_CHECK(OM::mark(go));
704 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
705 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
706 TRY_CHECK(OM::sweep(go));
709 * George adds an interface. mark stale. update the same interface. sweep
710 * and expect no delete
712 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
713 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
714 TRY_CHECK_RC(OM::write(go, itf1b));
716 TRY_CHECK(OM::mark(go));
718 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
719 TRY_CHECK_RC(OM::write(go, itf1));
721 TRY_CHECK(OM::sweep(go));
723 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
724 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
725 TRY_CHECK(OM::remove(go));
728 * George adds an insterface, then we mark that state. Add a second interface
729 * an flush the first that is now stale.
731 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
732 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
733 TRY_CHECK_RC(OM::write(go, itf1));
735 TRY_CHECK(OM::mark(go));
737 std::string itf2_name = "afpacket2";
738 std::string itf2_tag = "uuid-of-afpacket2-interface";
739 interface itf2(itf2_name,
740 interface::type_t::AFPACKET,
741 interface::admin_state_t::UP,
743 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
745 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
746 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
747 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
748 TRY_CHECK_RC(OM::write(go, itf2));
750 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
751 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
752 TRY_CHECK(OM::sweep(go));
754 TRY_CHECK(OM::mark(go));
756 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
757 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
758 TRY_CHECK(OM::sweep(go));
761 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
762 std::string itf3_tag = "uuid-of-vhost_user1-interface";
763 interface itf3(itf3_name,
764 interface::type_t::VHOST,
765 interface::admin_state_t::UP,
767 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
769 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
770 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
771 TRY_CHECK_RC(OM::write(go, itf3));
773 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
774 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
775 TRY_CHECK(OM::remove(go));
778 BOOST_AUTO_TEST_CASE(test_bvi) {
780 const std::string ernest = "ErnestHemmingway";
781 const std::string graham = "GrahamGreene";
785 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
787 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
791 * Enrest creates a BVI with address 10.10.10.10/24
793 route::prefix_t pfx_10("10.10.10.10", 24);
795 const std::string bvi_name = "bvi1";
796 interface itf(bvi_name,
797 interface::type_t::BVI,
798 interface::admin_state_t::UP);
799 HW::item<handle_t> hw_ifh(4, rc_t::OK);
800 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
802 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh, bvi_name));
803 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
804 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
805 TRY_CHECK_RC(OM::write(ernest, itf));
807 l3 = new l3_binding(itf, pfx_10);
808 HW::item<bool> hw_l3_bind(true, rc_t::OK);
809 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
810 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
811 TRY_CHECK_RC(OM::write(ernest, *l3));
813 // change the MAC address on the BVI
814 interface itf_new_mac(bvi_name,
815 interface::type_t::BVI,
816 interface::admin_state_t::UP);
817 l2_address_t l2_addr({0,1,2,3,4,5});
818 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
819 itf_new_mac.set(l2_addr);
820 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
821 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
823 // create/write the interface to the OM again but with an unset MAC
824 // this should not generate a MAC address update
825 TRY_CHECK_RC(OM::write(ernest, itf));
827 // change the MAC address on the BVI - again
828 interface itf_new_mac2(bvi_name,
829 interface::type_t::BVI,
830 interface::admin_state_t::UP);
831 l2_address_t l2_addr2({0,1,2,3,4,6});
832 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
833 itf_new_mac2.set(l2_addr2);
834 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
835 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
838 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
839 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
840 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh));
841 TRY_CHECK(OM::remove(ernest));
844 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
847 HW::item<bool> hw_rd4_create(true, rc_t::OK);
848 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
849 HW::item<bool> hw_rd6_create(true, rc_t::OK);
850 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
851 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
852 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
853 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
854 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
855 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
856 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
857 TRY_CHECK_RC(OM::write(graham, rd));
859 const std::string bvi2_name = "bvi2";
860 interface *itf2 = new interface(bvi2_name,
861 interface::type_t::BVI,
862 interface::admin_state_t::UP,
864 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
866 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh2, bvi2_name));
867 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
868 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
869 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
870 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
872 TRY_CHECK_RC(OM::write(graham, *itf2));
874 l3 = new l3_binding(*itf2, pfx_10);
875 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
876 TRY_CHECK_RC(OM::write(graham, *l3));
881 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
882 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
883 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
884 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
885 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh2));
886 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
887 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
888 TRY_CHECK(OM::remove(graham));
891 BOOST_AUTO_TEST_CASE(test_bond) {
893 const std::string cb = "CarolBerg";
897 * creates the interfaces
899 std::string itf1_name = "afpacket1";
900 interface itf1(itf1_name,
901 interface::type_t::AFPACKET,
902 interface::admin_state_t::UP);
904 HW::item<handle_t> hw_ifh(2, rc_t::OK);
905 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
907 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
908 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
910 TRY_CHECK_RC(OM::write(cb, itf1));
912 std::string itf2_name = "afpacket2";
913 interface itf2(itf2_name,
914 interface::type_t::AFPACKET,
915 interface::admin_state_t::UP);
918 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
919 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
920 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
922 TRY_CHECK_RC(OM::write(cb, itf2));
924 std::string bond_name = "bond";
925 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
926 bond_interface::mode_t::LACP);
928 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
929 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
930 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
931 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
933 TRY_CHECK_RC(OM::write(cb, bond_itf));
935 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
936 bond_member::rate_t::SLOW);
937 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
938 bond_member::rate_t::SLOW);
939 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
941 HW::item<bool> bond_hw_bind(true, rc_t::OK);
942 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
943 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
945 TRY_CHECK_RC(OM::write(cb, *bgb));
952 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
953 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
954 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
955 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
956 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
957 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
958 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
959 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
960 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
962 TRY_CHECK(OM::remove(cb));
965 BOOST_AUTO_TEST_CASE(test_bridge) {
967 const std::string franz = "FranzKafka";
968 const std::string dante = "Dante";
969 const std::string jkr = "jkrowling";
973 * Franz creates an interface, Bridge-domain, then binds the two
977 std::string itf1_name = "afpacket1";
978 interface itf1(itf1_name,
979 interface::type_t::AFPACKET,
980 interface::admin_state_t::UP);
982 HW::item<handle_t> hw_ifh(3, rc_t::OK);
983 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
985 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
986 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
988 TRY_CHECK_RC(OM::write(franz, itf1));
990 // bridge-domain create
991 bridge_domain bd1(33);
993 HW::item<uint32_t> hw_bd(33, rc_t::OK);
994 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
995 bridge_domain::learning_mode_t::ON,
996 bridge_domain::arp_term_mode_t::ON,
997 bridge_domain::arp_ufwd_mode_t::ON,
998 bridge_domain::flood_mode_t::ON,
999 bridge_domain::uu_flood_mode_t::ON,
1000 bridge_domain::mac_age_mode_t::OFF));
1002 TRY_CHECK_RC(OM::write(franz, bd1));
1004 // L2-interface create and bind
1005 // this needs to be delete'd before the flush below, since it too maintains
1006 // references to the BD and Interface
1007 l2_binding *l2itf = new l2_binding(itf1, bd1);
1008 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1010 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1013 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1014 TRY_CHECK_RC(OM::write(franz, *l2itf));
1017 * Dante adds an interface to the same BD
1019 std::string itf2_name = "afpacket2";
1020 interface itf2(itf2_name,
1021 interface::type_t::AFPACKET,
1022 interface::admin_state_t::UP);
1024 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1025 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1026 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1027 TRY_CHECK_RC(OM::write(dante, itf2));
1029 // BD add is a no-op since it exists
1030 TRY_CHECK_RC(OM::write(dante, bd1));
1032 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
1033 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
1034 l2itf2->set(l2_vtr::option_t::POP_1, 68);
1036 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1039 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1040 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
1041 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1043 // Add some static entries to the bridge-domain
1044 HW::item<bool> hw_be1(true, rc_t::OK);
1045 mac_address_t mac1({0,1,2,3,4,5});
1046 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
1047 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1049 TRY_CHECK_RC(OM::write(dante, *be1));
1051 // Add some entries to the bridge-domain ARP termination table
1052 HW::item<bool> hw_bea1(true, rc_t::OK);
1053 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1055 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
1056 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
1057 TRY_CHECK_RC(OM::write(dante, *bea1));
1059 // flush Franz's state
1061 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1063 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1066 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1067 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1068 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1069 TRY_CHECK(OM::remove(franz));
1071 // flush Dante's state - the order the interface and BD are deleted
1072 // is an uncontrollable artifact of the C++ object destruction.
1077 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1078 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
1079 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1082 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1084 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1085 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1086 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1087 TRY_CHECK(OM::remove(dante));
1089 // test the BVI entry in l2fib
1090 bridge_domain bd2(99);
1092 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1093 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1094 bridge_domain::learning_mode_t::ON,
1095 bridge_domain::arp_term_mode_t::ON,
1096 bridge_domain::arp_ufwd_mode_t::ON,
1097 bridge_domain::flood_mode_t::ON,
1098 bridge_domain::uu_flood_mode_t::ON,
1099 bridge_domain::mac_age_mode_t::OFF));
1101 TRY_CHECK_RC(OM::write(jkr, bd2));
1103 std::string itf3_name = "bvi";
1104 interface itf3(itf3_name,
1105 interface::type_t::BVI,
1106 interface::admin_state_t::UP);
1108 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1109 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh3, itf3_name));
1110 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1111 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1112 TRY_CHECK_RC(OM::write(jkr, itf3));
1114 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1115 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1118 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1119 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1121 HW::item<bool> hw_be2(true, rc_t::OK);
1122 mac_address_t mac2({0,1,2,3,4,5});
1123 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1124 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1125 TRY_CHECK_RC(OM::write(jkr, *be2));
1130 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1133 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1134 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1135 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1136 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh3));
1137 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1138 TRY_CHECK(OM::remove(jkr));
1141 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1143 const std::string nicholas = "NicholasAbercrombie";
1149 std::string itf1_name = "host1";
1150 interface itf1(itf1_name,
1151 interface::type_t::AFPACKET,
1152 interface::admin_state_t::UP);
1153 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1154 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1155 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1156 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1157 TRY_CHECK_RC(OM::write(nicholas, itf1));
1162 std::string itf2_name = "host2";
1163 interface itf2(itf2_name,
1164 interface::type_t::AFPACKET,
1165 interface::admin_state_t::UP);
1167 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1168 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1169 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1170 TRY_CHECK_RC(OM::write(nicholas, itf2));
1172 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1173 HW::item<bool> xconnect_east(true, rc_t::OK);
1174 HW::item<bool> xconnect_west(true, rc_t::OK);
1175 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1176 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1177 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1178 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1179 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1183 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1185 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1186 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1187 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1188 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1189 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1190 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1192 TRY_CHECK(OM::remove(nicholas));
1195 BOOST_AUTO_TEST_CASE(test_vxlan) {
1197 const std::string franz = "FranzKafka";
1201 * Franz creates an interface, Bridge-domain, then binds the two
1205 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1206 boost::asio::ip::address::from_string("10.10.10.11"),
1209 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1211 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1212 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1213 handle_t::INVALID));
1215 TRY_CHECK_RC(OM::write(franz, vxt));
1217 // bridge-domain create
1218 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1219 bridge_domain::arp_term_mode_t::OFF,
1220 bridge_domain::arp_ufwd_mode_t::OFF,
1221 bridge_domain::flood_mode_t::OFF,
1222 bridge_domain::uu_flood_mode_t::OFF,
1223 bridge_domain::mac_age_mode_t::ON);
1225 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1226 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1227 bridge_domain::learning_mode_t::OFF,
1228 bridge_domain::arp_term_mode_t::OFF,
1229 bridge_domain::arp_ufwd_mode_t::OFF,
1230 bridge_domain::flood_mode_t::OFF,
1231 bridge_domain::uu_flood_mode_t::OFF,
1232 bridge_domain::mac_age_mode_t::ON));
1234 TRY_CHECK_RC(OM::write(franz, bd1));
1236 // L2-interface create and bind
1237 // this needs to be delete'd before the flush below, since it too maintains
1238 // references to the BD and Interface
1239 l2_binding *l2itf = new l2_binding(vxt, bd1);
1240 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1242 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1245 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1246 TRY_CHECK_RC(OM::write(franz, *l2itf));
1248 // flush Franz's state
1250 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1252 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1255 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1256 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1257 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1258 TRY_CHECK(OM::remove(franz));
1261 BOOST_AUTO_TEST_CASE(test_vlan) {
1263 const std::string noam = "NoamChomsky";
1266 std::string itf1_name = "host1";
1267 interface itf1(itf1_name,
1268 interface::type_t::AFPACKET,
1269 interface::admin_state_t::UP);
1271 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1272 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1274 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1275 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1277 TRY_CHECK_RC(OM::write(noam, itf1));
1279 sub_interface *vl33 = new sub_interface(itf1,
1280 interface::admin_state_t::UP,
1283 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1284 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1285 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1287 TRY_CHECK_RC(OM::write(noam, *vl33));
1290 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1291 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1292 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1293 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1294 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1295 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1297 TRY_CHECK(OM::remove(noam));
1300 BOOST_AUTO_TEST_CASE(test_acl) {
1302 const std::string fyodor = "FyodorDostoyevsky";
1303 const std::string leo = "LeoTolstoy";
1307 * Fyodor adds an ACL in the input direction
1309 std::string itf1_name = "host1";
1310 interface itf1(itf1_name,
1311 interface::type_t::AFPACKET,
1312 interface::admin_state_t::UP);
1313 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1314 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1315 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1316 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1317 TRY_CHECK_RC(OM::write(fyodor, itf1));
1319 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1320 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1321 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1322 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1323 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1324 HW::item<bool> ae_binding(true, rc_t::OK);
1325 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1326 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1328 route::prefix_t src("10.10.10.10", 32);
1329 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1330 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1332 std::string acl_name = "acl1";
1333 ACL::l3_list acl1(acl_name);
1336 ACL::l3_list::rules_t rules = {r1, r2};
1338 HW::item<handle_t> hw_acl(2, rc_t::OK);
1339 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1340 TRY_CHECK_RC(OM::write(fyodor, acl1));
1342 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1343 ACL::l3_list acl2(acl_name);
1345 ACL::l3_list::rules_t rules2 = {r3};
1346 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1347 TRY_CHECK_RC(OM::write(fyodor, acl2));
1349 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1350 HW::item<bool> hw_binding(true, rc_t::OK);
1351 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1352 hw_ifh.data(), hw_acl.data()));
1353 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1356 * Leo adds an L2 ACL in the output direction
1358 TRY_CHECK_RC(OM::write(leo, itf1));
1360 std::string l2_acl_name = "l2_acl1";
1361 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1362 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1363 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1364 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1366 ACL::l2_list l2_acl(l2_acl_name);
1367 l2_acl.insert(l2_r2);
1368 l2_acl.insert(l2_r1);
1370 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1372 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1373 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1374 TRY_CHECK_RC(OM::write(leo, l2_acl));
1376 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1377 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1378 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1379 hw_ifh.data(), l2_hw_acl.data()));
1380 TRY_CHECK_RC(OM::write(leo, *l2b));
1383 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1384 hw_ifh.data(), l2_hw_acl.data()));
1385 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1386 TRY_CHECK(OM::remove(leo));
1390 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1393 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1394 hw_ifh.data(), hw_acl.data()));
1395 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1396 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1397 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1398 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1400 TRY_CHECK(OM::remove(fyodor));
1403 BOOST_AUTO_TEST_CASE(test_igmp) {
1405 const std::string Isaiah = "IsaiahBerlin";
1408 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1409 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1410 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
1412 std::string itf3_name = "host3";
1413 interface itf3(itf3_name,
1414 interface::type_t::AFPACKET,
1415 interface::admin_state_t::UP);
1416 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1417 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1418 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1419 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1420 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1422 igmp_binding *ib = new igmp_binding(itf3);
1423 HW::item<bool> hw_binding(true, rc_t::OK);
1424 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1425 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1427 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1429 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1430 HW::item<bool> hw_as_listen(true, rc_t::OK);
1431 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1432 TRY_CHECK_RC(OM::write(Isaiah, *il));
1437 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1440 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1441 ADD_EXPECT(igmp_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1442 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1443 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1445 TRY_CHECK(OM::remove(Isaiah));
1448 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1450 const std::string kurt = "KurtVonnegut";
1453 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1454 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1456 arp_proxy_config ap(low, high);
1457 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1458 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1459 TRY_CHECK_RC(OM::write(kurt, ap));
1461 std::string itf3_name = "host3";
1462 interface itf3(itf3_name,
1463 interface::type_t::AFPACKET,
1464 interface::admin_state_t::UP);
1465 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1466 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1467 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1468 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1469 TRY_CHECK_RC(OM::write(kurt, itf3));
1471 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1472 HW::item<bool> hw_binding(true, rc_t::OK);
1473 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1474 TRY_CHECK_RC(OM::write(kurt, *apb));
1478 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1481 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1482 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1483 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1484 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1486 TRY_CHECK(OM::remove(kurt));
1489 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1491 const std::string eliot = "EliotReed";
1495 * Interface 1 is the tx interface
1497 std::string itf1_name = "tx-itf";
1498 interface itf1(itf1_name,
1499 interface::type_t::AFPACKET,
1500 interface::admin_state_t::UP);
1501 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1502 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1503 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1504 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1505 TRY_CHECK_RC(OM::write(eliot, itf1));
1507 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1510 * Interface 2 is the rx interface
1512 std::string itf2_name = "rx-itf";
1513 interface itf2(itf2_name,
1514 interface::type_t::AFPACKET,
1515 interface::admin_state_t::UP);
1517 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1518 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1519 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1520 TRY_CHECK_RC(OM::write(eliot, itf2));
1522 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1523 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1524 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1525 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1526 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1530 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1532 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1533 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1534 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1535 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1536 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1538 TRY_CHECK(OM::remove(eliot));
1541 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1543 const std::string eric = "EricAmbler";
1547 * Interface 1 has the L3 address
1549 std::string itf1_name = "host1";
1550 interface itf1(itf1_name,
1551 interface::type_t::AFPACKET,
1552 interface::admin_state_t::UP);
1553 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1554 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1555 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1556 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1557 TRY_CHECK_RC(OM::write(eric, itf1));
1559 route::prefix_t pfx_10("10.10.10.10", 24);
1560 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1561 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1562 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1563 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1564 TRY_CHECK_RC(OM::write(eric, *l3));
1567 * Interface 2 is unnumbered
1569 std::string itf2_name = "host2";
1570 interface itf2(itf2_name,
1571 interface::type_t::AFPACKET,
1572 interface::admin_state_t::UP);
1574 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1575 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1576 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1577 TRY_CHECK_RC(OM::write(eric, itf2));
1579 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1580 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1581 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1582 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1583 TRY_CHECK_RC(OM::write(eric, *ipun));
1588 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1590 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1591 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1592 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1593 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1594 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1595 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1597 TRY_CHECK(OM::remove(eric));
1600 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1602 const std::string paulo = "PauloCoelho";
1608 std::string itf_name = "host_ip6nd";
1609 interface itf(itf_name,
1610 interface::type_t::AFPACKET,
1611 interface::admin_state_t::UP);
1612 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1613 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1614 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1615 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1616 TRY_CHECK_RC(OM::write(paulo, itf));
1618 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1619 l3_binding *l3 = new l3_binding(itf, pfx_10);
1620 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1621 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1622 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1623 TRY_CHECK_RC(OM::write(paulo, *l3));
1625 ra_config ra(0, 1, 0, 4);
1626 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1627 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1628 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1629 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1630 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1635 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1636 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1637 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1638 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1639 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1640 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1644 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1649 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1652 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1653 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1654 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1655 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1657 TRY_CHECK(OM::remove(paulo));
1660 BOOST_AUTO_TEST_CASE(test_interface_span) {
1662 const std::string elif = "ElifShafak";
1666 * Interface 1 to be mirrored
1668 std::string itf1_name = "port-from";
1669 interface itf1(itf1_name,
1670 interface::type_t::AFPACKET,
1671 interface::admin_state_t::UP);
1672 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1673 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1674 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1675 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1676 TRY_CHECK_RC(OM::write(elif, itf1));
1679 * Interface 2 where traffic is mirrored
1681 std::string itf2_name = "port-to";
1682 interface itf2(itf2_name,
1683 interface::type_t::AFPACKET,
1684 interface::admin_state_t::UP);
1686 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1687 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1689 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1690 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1691 TRY_CHECK_RC(OM::write(elif, itf2));
1693 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1694 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1695 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1696 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1697 TRY_CHECK_RC(OM::write(elif, *itf_span));
1699 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1700 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1704 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1705 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1706 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1707 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1708 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1710 TRY_CHECK(OM::remove(elif));
1713 BOOST_AUTO_TEST_CASE(test_routing) {
1715 const std::string ian = "IanFleming";
1719 * non-default route domain
1721 route_domain rd4(1);
1722 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1723 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1724 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1725 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1726 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1727 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1728 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1729 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1730 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1731 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1732 TRY_CHECK_RC(OM::write(ian, rd4));
1735 * a couple of interfaces
1737 std::string itf1_name = "af1";
1738 interface itf1(itf1_name,
1739 interface::type_t::AFPACKET,
1740 interface::admin_state_t::UP);
1741 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1742 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1743 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1744 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1745 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1746 TRY_CHECK_RC(OM::write(ian, itf1));
1748 std::string itf2_name = "af2";
1749 interface *itf2 = new interface(itf2_name,
1750 interface::type_t::AFPACKET,
1751 interface::admin_state_t::UP,
1754 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1755 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1756 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1757 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1758 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1759 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1760 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1761 TRY_CHECK_RC(OM::write(ian, *itf2));
1764 * prefix on each interface
1766 route::prefix_t pfx_10("10.10.10.10", 24);
1767 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1768 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1769 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1770 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1771 TRY_CHECK_RC(OM::write(ian, *l3_10));
1772 route::prefix_t pfx_11("11.11.11.11", 24);
1773 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1774 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1775 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1776 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1777 TRY_CHECK_RC(OM::write(ian, *l3_11));
1780 * A route via interface 1 in the default table
1782 route::prefix_t pfx_5("5.5.5.5", 32);
1783 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1784 route::path *path_9 = new route::path(nh_9, itf1);
1785 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1786 route::path *path_10 = new route::path(nh_10, itf1);
1787 route::ip_route *route_5 = new route::ip_route(pfx_5);
1788 route_5->add(*path_10);
1789 route_5->add(*path_9);
1790 route::path_list_t pl_9_10 = {*path_9, *path_10};
1791 HW::item<handle_t> hw_route_5(0, rc_t::OK);
1792 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_9_10));
1793 TRY_CHECK_RC(OM::write(ian, *route_5));
1795 route_5->remove(*path_9);
1796 route::path_list_t pl_10 = {*path_10};
1797 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_10));
1798 TRY_CHECK_RC(OM::write(ian, *route_5));
1803 * A route via interface 2 in the non-default table
1805 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1806 route::path *path_11 = new route::path(nh_11, *itf2);
1807 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1808 route::path *path_12 = new route::path(nh_12, *itf2);
1809 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1810 route::path_list_t pl_11 = {*path_11};
1811 route_5_2->add(*path_11);
1812 HW::item<handle_t> hw_route_5_2(1, rc_t::OK);
1813 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11));
1814 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1816 route::path_list_t pl_11_12 = {*path_11, *path_12};
1817 route_5_2->add(*path_12);
1818 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11_12));
1819 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1822 * An ARP entry for the neighbour on itf1
1824 HW::item<handle_t> hw_neighbour(0, rc_t::OK);
1825 mac_address_t mac_n({0,1,2,4,5,6});
1826 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1827 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1829 neighbour::flags_t::STATIC));
1830 TRY_CHECK_RC(OM::write(ian, *ne));
1835 route::prefix_t pfx_6("6.6.6.6", 32);
1836 route::path *path_13 = new route::path(*itf2, nh_proto_t::ETHERNET);
1837 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1838 route_dvr->add(*path_13);
1839 route::path_list_t pl_13 = {*path_13};
1840 HW::item<handle_t> hw_route_dvr(2, rc_t::OK);
1841 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, pl_13));
1842 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1847 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1848 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1850 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1851 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1852 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1853 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1854 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1855 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1856 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1857 *mp1, route::itf_flags_t::FORWARD));
1858 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1859 *mp2, route::itf_flags_t::FORWARD));
1860 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1861 *mp1, route::itf_flags_t::ACCEPT));
1862 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1865 // delete the stack objects that hold references to others
1866 // so the OM::remove is the call that removes the last reference
1876 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1877 *mp1, route::itf_flags_t::FORWARD));
1878 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1879 *mp2, route::itf_flags_t::FORWARD));
1880 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1881 *mp1, route::itf_flags_t::ACCEPT));
1886 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1888 neighbour::flags_t::STATIC));
1889 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1890 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1891 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1903 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1904 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1905 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1906 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1907 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1908 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1909 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1910 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1911 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1912 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1914 TRY_CHECK(OM::remove(ian));
1917 BOOST_AUTO_TEST_CASE(test_nat) {
1919 const std::string gs = "GeorgeSimenon";
1925 std::string itf_in_name = "inside";
1926 interface itf_in(itf_in_name,
1927 interface::type_t::AFPACKET,
1928 interface::admin_state_t::UP);
1929 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1930 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1931 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1932 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1933 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1934 TRY_CHECK_RC(OM::write(gs, itf_in));
1939 std::string itf_out_name = "port-to";
1940 interface itf_out(itf_out_name,
1941 interface::type_t::AFPACKET,
1942 interface::admin_state_t::UP);
1944 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1945 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1946 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1948 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1949 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1950 TRY_CHECK_RC(OM::write(gs, itf_out));
1953 * A NAT static mapping
1955 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1956 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1958 nat_static ns(in_addr, out_addr);
1959 HW::item<bool> hw_ns(true, rc_t::OK);
1961 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1962 TRY_CHECK_RC(OM::write(gs, ns));
1965 * bind nat inside and out
1967 nat_binding *nb_in = new nat_binding(itf_in,
1970 nat_binding::zone_t::INSIDE);
1971 HW::item<bool> hw_nb_in(true, rc_t::OK);
1973 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1974 hw_ifh.data().value(),
1975 nat_binding::zone_t::INSIDE));
1976 TRY_CHECK_RC(OM::write(gs, *nb_in));
1978 nat_binding *nb_out = new nat_binding(itf_out,
1981 nat_binding::zone_t::OUTSIDE);
1982 HW::item<bool> hw_nb_out(true, rc_t::OK);
1984 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1985 hw_ifh2.data().value(),
1986 nat_binding::zone_t::OUTSIDE));
1987 TRY_CHECK_RC(OM::write(gs, *nb_out));
1993 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1994 hw_ifh.data().value(),
1995 nat_binding::zone_t::INSIDE));
1996 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1997 hw_ifh2.data().value(),
1998 nat_binding::zone_t::OUTSIDE));
1999 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
2000 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
2001 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
2002 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
2003 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
2005 TRY_CHECK(OM::remove(gs));
2008 BOOST_AUTO_TEST_CASE(test_interface_events) {
2012 HW::item<bool> hw_want(true, rc_t::OK);
2014 ADD_EXPECT(interface_cmds::events_cmd(ml));
2015 cmd* itf = new interface_cmds::events_cmd(ml);
2021 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
2023 const std::string rene = "ReneGoscinny";
2027 * Create an interface with two IP addresses
2029 std::string itf1_name = "host1";
2030 interface itf1(itf1_name,
2031 interface::type_t::AFPACKET,
2032 interface::admin_state_t::UP);
2033 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
2034 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
2035 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
2036 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
2037 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
2038 TRY_CHECK_RC(OM::write(rene, itf1));
2040 route::prefix_t pfx_10("10.10.10.10", 24);
2041 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
2042 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
2043 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
2044 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2045 TRY_CHECK_RC(OM::write(rene, *l3_1));
2047 route::prefix_t pfx_11("10.10.11.11", 24);
2048 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
2049 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
2050 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
2051 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2052 TRY_CHECK_RC(OM::write(rene, *l3_2));
2055 HW::item<bool> hw_rd_create(true, rc_t::OK);
2056 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2057 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2058 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2059 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2060 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2061 TRY_CHECK_RC(OM::write(rene, rd));
2064 * update the interface to change to a new route-domain
2065 * expect that the l3-bindings are removed and readded.
2067 interface *itf2 = new interface(itf1_name,
2068 interface::type_t::AFPACKET,
2069 interface::admin_state_t::UP,
2071 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2072 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2073 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2074 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2075 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2076 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2077 TRY_CHECK_RC(OM::write(rene, *itf2));
2080 * mve the interface back to the default route-domain
2082 interface itf3(itf1_name,
2083 interface::type_t::AFPACKET,
2084 interface::admin_state_t::UP);
2085 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2086 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2087 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2088 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2089 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2090 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2091 TRY_CHECK_RC(OM::write(rene, itf3));
2098 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2099 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2100 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2101 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2102 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2103 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2105 TRY_CHECK(OM::remove(rene));
2108 BOOST_AUTO_TEST_CASE(test_prefixes) {
2109 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2111 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2113 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2115 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2116 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2118 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2119 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2120 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2122 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2124 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2126 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2128 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2129 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2130 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2132 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2134 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2135 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2136 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2138 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2140 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2141 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2142 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2146 BOOST_AUTO_TEST_CASE(test_pipes) {
2148 const std::string gk = "GKChesterton";
2150 const std::string pipe_name_1 = "pipe1";
2151 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2152 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2153 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2155 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2157 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2159 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2160 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2161 TRY_CHECK_RC(OM::write(gk, pipe1));
2163 pipe1.set_ends(hw_hdl_pair.data());
2165 // put each end of the pipe in a BD
2166 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2167 bridge_domain::arp_term_mode_t::OFF,
2168 bridge_domain::arp_ufwd_mode_t::ON,
2169 bridge_domain::flood_mode_t::OFF,
2170 bridge_domain::uu_flood_mode_t::ON,
2171 bridge_domain::mac_age_mode_t::ON);
2173 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2174 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2175 bridge_domain::learning_mode_t::OFF,
2176 bridge_domain::arp_term_mode_t::OFF,
2177 bridge_domain::arp_ufwd_mode_t::ON,
2178 bridge_domain::flood_mode_t::OFF,
2179 bridge_domain::uu_flood_mode_t::ON,
2180 bridge_domain::mac_age_mode_t::ON));
2182 TRY_CHECK_RC(OM::write(gk, bd1));
2184 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2185 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2187 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2188 pipe1.east()->handle(),
2190 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2191 TRY_CHECK_RC(OM::write(gk, *l2_1));
2193 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2194 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2196 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2197 pipe1.west()->handle(),
2199 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2200 TRY_CHECK_RC(OM::write(gk, *l2_2));
2206 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2207 pipe1.east()->handle(),
2209 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2210 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2211 pipe1.west()->handle(),
2213 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2214 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2215 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2216 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2217 TRY_CHECK(OM::remove(gk));
2220 BOOST_AUTO_TEST_CASE(test_qos) {
2222 const std::string albert = "AlbertCamus";
2226 * Create an interface on which to enable QoS
2228 std::string itf_name = "host1";
2229 interface itf(itf_name,
2230 interface::type_t::AFPACKET,
2231 interface::admin_state_t::UP);
2232 HW::item<handle_t> hw_ifh(2, rc_t::OK);
2233 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
2234 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
2235 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
2236 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
2237 TRY_CHECK_RC(OM::write(albert, itf));
2239 QoS::map::outputs_t out;
2243 QoS::map qem(1, out);
2245 HW::item<bool> hw_qem(true, rc_t::OK);
2246 ADD_EXPECT(QoS::map_cmds::create_cmd(hw_qem, 1, out));
2247 TRY_CHECK_RC(OM::write(albert, qem));
2249 QoS::record *qr = new QoS::record(itf, QoS::source_t::IP);
2250 HW::item<bool> hw_qr(true, rc_t::OK);
2251 ADD_EXPECT(QoS::record_cmds::create_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP));
2252 TRY_CHECK_RC(OM::write(albert, *qr));
2254 QoS::mark *qm = new QoS::mark(itf, qem, QoS::source_t::IP);
2255 HW::item<bool> hw_qm(true, rc_t::OK);
2256 ADD_EXPECT(QoS::mark_cmds::create_cmd(hw_qm, hw_ifh.data(), 1, QoS::source_t::IP));
2257 TRY_CHECK_RC(OM::write(albert, *qm));
2261 ADD_EXPECT(QoS::mark_cmds::delete_cmd(hw_qm, hw_ifh.data(), QoS::source_t::IP));
2262 ADD_EXPECT(QoS::map_cmds::delete_cmd(hw_qem, 1));
2263 ADD_EXPECT(QoS::record_cmds::delete_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP));
2264 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
2265 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
2266 TRY_CHECK(OM::remove(albert));
2269 BOOST_AUTO_TEST_SUITE_END()