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"
87 #include "vom/qos_store.hpp"
88 #include "vom/qos_store_cmds.hpp"
90 using namespace boost;
94 * An expectation exception
99 ExpException(unsigned int number)
101 // a neat place to add a break point
102 // std::cout << " ExpException here: " << number << std::endl;
106 class MockListener : public interface::event_listener,
107 public interface::stat_listener
109 void handle_interface_stat(const interface& itf)
112 void handle_interface_event(std::vector<VOM::interface::event> events)
117 class MockCmdQ : public HW::cmd_q
129 m_exp_queue.push_back(f);
133 m_act_queue.push_back(f);
135 void enqueue(std::queue<cmd*> &cmds)
139 m_act_queue.push_back(cmds.front());
143 void enqueue(std::shared_ptr<cmd> f)
145 m_act_queue.push_back(f.get());
152 void dequeue(std::shared_ptr<cmd> cmd)
156 void strict_order(bool on)
163 return ((0 == m_exp_queue.size()) &&
164 (0 == m_act_queue.size()));
172 while (m_act_queue.size())
174 bool matched = false;
175 auto it_exp = m_exp_queue.begin();
176 auto it_act = m_act_queue.begin();
180 std::cout << " Act: " << f_act->to_string() << std::endl;
181 while (it_exp != m_exp_queue.end())
186 std::cout << " Exp: " << f_exp->to_string() << std::endl;
188 if (typeid(*f_exp) != typeid(*f_act))
190 throw ExpException(1);
193 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
195 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
197 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
199 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
201 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_create_cmd))
203 rc = handle_derived<interface_cmds::bvi_create_cmd>(f_exp, f_act);
205 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
207 rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
209 else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
211 rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
213 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
215 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
217 else if (typeid(*f_exp) == typeid(interface_cmds::bvi_delete_cmd))
219 rc = handle_derived<interface_cmds::bvi_delete_cmd>(f_exp, f_act);
221 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
223 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
225 else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
227 rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
229 else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
231 rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
233 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
235 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
237 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
239 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
241 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
243 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
245 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
247 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
249 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
251 rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
253 else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
255 rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
257 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
259 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
261 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
263 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
265 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
267 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
269 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
271 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
273 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd))
275 rc = handle_derived<route::ip_mroute_cmds::update_cmd>(f_exp, f_act);
277 else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd))
279 rc = handle_derived<route::ip_mroute_cmds::delete_cmd>(f_exp, f_act);
281 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
283 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
285 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
287 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
289 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
291 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
293 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
295 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
297 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
299 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
301 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
303 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
305 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
307 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
309 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
311 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
313 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
315 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
317 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
319 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
321 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
323 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
325 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
327 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
329 else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd))
331 rc = handle_derived<l2_vtr_cmds::set_cmd>(f_exp, f_act);
333 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
335 rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
337 else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
339 rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
341 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
343 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
345 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
347 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
349 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
351 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
353 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
355 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
357 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
359 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
361 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
363 rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
365 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
367 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
369 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
371 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
373 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
375 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
377 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
379 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
381 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
383 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
385 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
387 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
389 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
391 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
393 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
395 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
397 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
399 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
401 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
403 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
405 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
407 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
409 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
411 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
413 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd))
415 rc = handle_derived<igmp_binding_cmds::bind_cmd>(f_exp, f_act);
417 else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd))
419 rc = handle_derived<igmp_binding_cmds::unbind_cmd>(f_exp, f_act);
421 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd))
423 rc = handle_derived<igmp_listen_cmds::listen_cmd>(f_exp, f_act);
425 else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd))
427 rc = handle_derived<igmp_listen_cmds::unlisten_cmd>(f_exp, f_act);
429 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd))
431 rc = handle_derived<ip_punt_redirect_cmds::config_cmd>(f_exp, f_act);
433 else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd))
435 rc = handle_derived<ip_punt_redirect_cmds::unconfig_cmd>(f_exp, f_act);
437 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
439 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
441 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
443 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
445 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
447 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
449 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
451 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
453 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
455 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
457 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
459 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
461 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
463 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
465 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
467 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
469 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
471 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
473 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
475 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
477 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
479 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
481 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
483 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
485 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
487 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
489 else if (typeid(*f_exp) == typeid(pipe_cmds::create_cmd))
491 rc = handle_derived<pipe_cmds::create_cmd>(f_exp, f_act);
493 else if (typeid(*f_exp) == typeid(pipe_cmds::delete_cmd))
495 rc = handle_derived<pipe_cmds::delete_cmd>(f_exp, f_act);
497 else if (typeid(*f_exp) == typeid(QoS::mark_cmds::create_cmd))
499 rc = handle_derived<QoS::mark_cmds::create_cmd>(f_exp, f_act);
501 else if (typeid(*f_exp) == typeid(QoS::mark_cmds::delete_cmd))
503 rc = handle_derived<QoS::mark_cmds::delete_cmd>(f_exp, f_act);
505 else if (typeid(*f_exp) == typeid(QoS::record_cmds::create_cmd))
507 rc = handle_derived<QoS::record_cmds::create_cmd>(f_exp, f_act);
509 else if (typeid(*f_exp) == typeid(QoS::record_cmds::delete_cmd))
511 rc = handle_derived<QoS::record_cmds::delete_cmd>(f_exp, f_act);
513 else if (typeid(*f_exp) == typeid(QoS::store_cmds::create_cmd))
515 rc = handle_derived<QoS::store_cmds::create_cmd>(f_exp, f_act);
517 else if (typeid(*f_exp) == typeid(QoS::store_cmds::delete_cmd))
519 rc = handle_derived<QoS::store_cmds::delete_cmd>(f_exp, f_act);
521 else if (typeid(*f_exp) == typeid(QoS::map_cmds::create_cmd))
523 rc = handle_derived<QoS::map_cmds::create_cmd>(f_exp, f_act);
525 else if (typeid(*f_exp) == typeid(QoS::map_cmds::delete_cmd))
527 rc = handle_derived<QoS::map_cmds::delete_cmd>(f_exp, f_act);
531 throw ExpException(2);
534 // if we get here then we found the match.
535 m_exp_queue.erase(it_exp);
536 m_act_queue.erase(it_act);
540 // return any injected failures to the agent
541 if (rc_t::OK != rc && rc_t::NOOP != rc)
549 catch (ExpException &e)
551 // The expected and actual do not match
554 // in strict ordering mode this is fatal, so rethrow
559 // move the iterator onto the next in the expected list and
567 throw ExpException(3);
574 template <typename T>
575 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
580 i_exp = dynamic_cast<const T*>(f_exp);
581 i_act = dynamic_cast<T*>(f_act);
582 if (!(*i_exp == *i_act))
584 throw ExpException(4);
586 // pass the data and return code to the agent
587 i_act->item() = i_exp->item();
589 return (i_act->item().rc());
592 // The Q to push the expectations on
593 std::deque<cmd*> m_exp_queue;
595 // the queue to push the actual events on
596 std::deque<cmd*> m_act_queue;
598 // control whether the expected queue is strictly ordered.
613 logger().set(log_level_t::DEBUG);
621 BOOST_AUTO_TEST_SUITE(vom)
623 #define TRY_CHECK_RC(stmt) \
626 BOOST_CHECK(rc_t::OK == stmt); \
628 catch (ExpException &e) \
630 BOOST_CHECK(false); \
632 BOOST_CHECK(vi.f->is_empty()); \
635 #define TRY_CHECK(stmt) \
640 catch (ExpException &e) \
642 BOOST_CHECK(false); \
644 BOOST_CHECK(vi.f->is_empty()); \
647 #define ADD_EXPECT(stmt) \
648 vi.f->expect(new stmt)
650 #define STRICT_ORDER_OFF() \
651 vi.f->strict_order(false)
653 BOOST_AUTO_TEST_CASE(test_interface) {
655 const std::string go = "GeorgeOrwell";
656 const std::string js = "JohnSteinbeck";
660 * George creates and deletes the interface
662 std::string itf1_name = "afpacket1";
663 interface itf1(itf1_name,
664 interface::type_t::AFPACKET,
665 interface::admin_state_t::UP);
668 * set the expectation for a afpacket interface create.
669 * 2 is the interface handle VPP [mock] assigns
671 HW::item<handle_t> hw_ifh(2, rc_t::OK);
672 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
674 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
675 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
677 TRY_CHECK_RC(OM::write(go, itf1));
679 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
680 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
681 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
683 TRY_CHECK(OM::remove(go));
686 * George creates the interface, then John brings it down.
687 * George's remove is a no-op, sice John also owns the interface
689 interface itf1b(itf1_name,
690 interface::type_t::AFPACKET,
691 interface::admin_state_t::DOWN);
693 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
694 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
695 TRY_CHECK_RC(OM::write(go, itf1));
697 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
698 TRY_CHECK_RC(OM::write(js, itf1b));
700 TRY_CHECK(OM::remove(go));
702 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
703 TRY_CHECK(OM::remove(js));
706 * George adds an interface, then we flush all of Geroge's state
708 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
709 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
710 TRY_CHECK_RC(OM::write(go, itf1));
712 TRY_CHECK(OM::mark(go));
714 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
715 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
716 TRY_CHECK(OM::sweep(go));
719 * George adds an interface. mark stale. update the same interface. sweep
720 * and expect no delete
722 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
723 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
724 TRY_CHECK_RC(OM::write(go, itf1b));
726 TRY_CHECK(OM::mark(go));
728 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
729 TRY_CHECK_RC(OM::write(go, itf1));
731 TRY_CHECK(OM::sweep(go));
733 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
734 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
735 TRY_CHECK(OM::remove(go));
738 * George adds an insterface, then we mark that state. Add a second interface
739 * an flush the first that is now stale.
741 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
742 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
743 TRY_CHECK_RC(OM::write(go, itf1));
745 TRY_CHECK(OM::mark(go));
747 std::string itf2_name = "afpacket2";
748 std::string itf2_tag = "uuid-of-afpacket2-interface";
749 interface itf2(itf2_name,
750 interface::type_t::AFPACKET,
751 interface::admin_state_t::UP,
753 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
755 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
756 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
757 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
758 TRY_CHECK_RC(OM::write(go, itf2));
760 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
761 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
762 TRY_CHECK(OM::sweep(go));
764 TRY_CHECK(OM::mark(go));
766 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
767 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
768 TRY_CHECK(OM::sweep(go));
771 std::string itf3_name = "/PATH/TO/vhost_user1.sock";
772 std::string itf3_tag = "uuid-of-vhost_user1-interface";
773 interface itf3(itf3_name,
774 interface::type_t::VHOST,
775 interface::admin_state_t::UP,
777 HW::item<handle_t> hw_ifh3(4, rc_t::OK);
779 ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
780 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
781 TRY_CHECK_RC(OM::write(go, itf3));
783 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
784 ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
785 TRY_CHECK(OM::remove(go));
788 BOOST_AUTO_TEST_CASE(test_bvi) {
790 const std::string ernest = "ErnestHemmingway";
791 const std::string graham = "GrahamGreene";
795 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
797 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
801 * Enrest creates a BVI with address 10.10.10.10/24
803 route::prefix_t pfx_10("10.10.10.10", 24);
805 const std::string bvi_name = "bvi1";
806 interface itf(bvi_name,
807 interface::type_t::BVI,
808 interface::admin_state_t::UP);
809 HW::item<handle_t> hw_ifh(4, rc_t::OK);
810 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
812 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh, bvi_name));
813 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
814 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
815 TRY_CHECK_RC(OM::write(ernest, itf));
817 l3 = new l3_binding(itf, pfx_10);
818 HW::item<bool> hw_l3_bind(true, rc_t::OK);
819 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
820 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
821 TRY_CHECK_RC(OM::write(ernest, *l3));
823 // change the MAC address on the BVI
824 interface itf_new_mac(bvi_name,
825 interface::type_t::BVI,
826 interface::admin_state_t::UP);
827 l2_address_t l2_addr({0,1,2,3,4,5});
828 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
829 itf_new_mac.set(l2_addr);
830 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
831 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
833 // create/write the interface to the OM again but with an unset MAC
834 // this should not generate a MAC address update
835 TRY_CHECK_RC(OM::write(ernest, itf));
837 // change the MAC address on the BVI - again
838 interface itf_new_mac2(bvi_name,
839 interface::type_t::BVI,
840 interface::admin_state_t::UP);
841 l2_address_t l2_addr2({0,1,2,3,4,6});
842 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
843 itf_new_mac2.set(l2_addr2);
844 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
845 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
848 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
849 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
850 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh));
851 TRY_CHECK(OM::remove(ernest));
854 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
857 HW::item<bool> hw_rd4_create(true, rc_t::OK);
858 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
859 HW::item<bool> hw_rd6_create(true, rc_t::OK);
860 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
861 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
862 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
863 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
864 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
865 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
866 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
867 TRY_CHECK_RC(OM::write(graham, rd));
869 const std::string bvi2_name = "bvi2";
870 interface *itf2 = new interface(bvi2_name,
871 interface::type_t::BVI,
872 interface::admin_state_t::UP,
874 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
876 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh2, bvi2_name));
877 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
878 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
879 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
880 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
882 TRY_CHECK_RC(OM::write(graham, *itf2));
884 l3 = new l3_binding(*itf2, pfx_10);
885 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
886 TRY_CHECK_RC(OM::write(graham, *l3));
891 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
892 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
893 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
894 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
895 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh2));
896 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
897 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
898 TRY_CHECK(OM::remove(graham));
901 BOOST_AUTO_TEST_CASE(test_bond) {
903 const std::string cb = "CarolBerg";
907 * creates the interfaces
909 std::string itf1_name = "afpacket1";
910 interface itf1(itf1_name,
911 interface::type_t::AFPACKET,
912 interface::admin_state_t::UP);
914 HW::item<handle_t> hw_ifh(2, rc_t::OK);
915 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
917 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
918 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
920 TRY_CHECK_RC(OM::write(cb, itf1));
922 std::string itf2_name = "afpacket2";
923 interface itf2(itf2_name,
924 interface::type_t::AFPACKET,
925 interface::admin_state_t::UP);
928 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
929 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
930 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
932 TRY_CHECK_RC(OM::write(cb, itf2));
934 std::string bond_name = "bond";
935 bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
936 bond_interface::mode_t::LACP);
938 HW::item<handle_t> hw_ifh3(6, rc_t::OK);
939 ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
940 bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
941 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
943 TRY_CHECK_RC(OM::write(cb, bond_itf));
945 bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
946 bond_member::rate_t::SLOW);
947 bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
948 bond_member::rate_t::SLOW);
949 bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
951 HW::item<bool> bond_hw_bind(true, rc_t::OK);
952 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
953 ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
955 TRY_CHECK_RC(OM::write(cb, *bgb));
962 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
963 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
964 ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
965 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
966 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
967 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
968 ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
969 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
970 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
972 TRY_CHECK(OM::remove(cb));
975 BOOST_AUTO_TEST_CASE(test_bridge) {
977 const std::string franz = "FranzKafka";
978 const std::string dante = "Dante";
979 const std::string jkr = "jkrowling";
983 * Franz creates an interface, Bridge-domain, then binds the two
987 std::string itf1_name = "afpacket1";
988 interface itf1(itf1_name,
989 interface::type_t::AFPACKET,
990 interface::admin_state_t::UP);
992 HW::item<handle_t> hw_ifh(3, rc_t::OK);
993 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
995 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
996 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
998 TRY_CHECK_RC(OM::write(franz, itf1));
1000 // bridge-domain create
1001 bridge_domain bd1(33);
1003 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1004 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1005 bridge_domain::learning_mode_t::ON,
1006 bridge_domain::arp_term_mode_t::ON,
1007 bridge_domain::arp_ufwd_mode_t::ON,
1008 bridge_domain::flood_mode_t::ON,
1009 bridge_domain::uu_flood_mode_t::ON,
1010 bridge_domain::mac_age_mode_t::OFF));
1012 TRY_CHECK_RC(OM::write(franz, bd1));
1014 // L2-interface create and bind
1015 // this needs to be delete'd before the flush below, since it too maintains
1016 // references to the BD and Interface
1017 l2_binding *l2itf = new l2_binding(itf1, bd1);
1018 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1020 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1023 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1024 TRY_CHECK_RC(OM::write(franz, *l2itf));
1027 * Dante adds an interface to the same BD
1029 std::string itf2_name = "afpacket2";
1030 interface itf2(itf2_name,
1031 interface::type_t::AFPACKET,
1032 interface::admin_state_t::UP);
1034 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1035 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1036 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1037 TRY_CHECK_RC(OM::write(dante, itf2));
1039 // BD add is a no-op since it exists
1040 TRY_CHECK_RC(OM::write(dante, bd1));
1042 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
1043 HW::item<l2_vtr::option_t> hw_set_vtr(l2_vtr::option_t::POP_1, rc_t::OK);
1044 l2itf2->set(l2_vtr::option_t::POP_1, 68);
1046 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1049 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1050 ADD_EXPECT(l2_vtr_cmds::set_cmd(hw_set_vtr, hw_ifh2.data(), 68));
1051 TRY_CHECK_RC(OM::write(dante, *l2itf2));
1053 // Add some static entries to the bridge-domain
1054 HW::item<bool> hw_be1(true, rc_t::OK);
1055 mac_address_t mac1({0,1,2,3,4,5});
1056 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
1057 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
1059 TRY_CHECK_RC(OM::write(dante, *be1));
1061 // Add some entries to the bridge-domain ARP termination table
1062 HW::item<bool> hw_bea1(true, rc_t::OK);
1063 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
1065 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
1066 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
1067 TRY_CHECK_RC(OM::write(dante, *bea1));
1069 // flush Franz's state
1071 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1073 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1076 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1077 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1078 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1079 TRY_CHECK(OM::remove(franz));
1081 // flush Dante's state - the order the interface and BD are deleted
1082 // is an uncontrollable artifact of the C++ object destruction.
1087 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1088 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
1089 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1092 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1094 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1095 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1096 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1097 TRY_CHECK(OM::remove(dante));
1099 // test the BVI entry in l2fib
1100 bridge_domain bd2(99);
1102 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1103 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1104 bridge_domain::learning_mode_t::ON,
1105 bridge_domain::arp_term_mode_t::ON,
1106 bridge_domain::arp_ufwd_mode_t::ON,
1107 bridge_domain::flood_mode_t::ON,
1108 bridge_domain::uu_flood_mode_t::ON,
1109 bridge_domain::mac_age_mode_t::OFF));
1111 TRY_CHECK_RC(OM::write(jkr, bd2));
1113 std::string itf3_name = "bvi";
1114 interface itf3(itf3_name,
1115 interface::type_t::BVI,
1116 interface::admin_state_t::UP);
1118 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1119 ADD_EXPECT(interface_cmds::bvi_create_cmd(hw_ifh3, itf3_name));
1120 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1121 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1122 TRY_CHECK_RC(OM::write(jkr, itf3));
1124 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1125 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1128 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1129 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1131 HW::item<bool> hw_be2(true, rc_t::OK);
1132 mac_address_t mac2({0,1,2,3,4,5});
1133 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1134 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1135 TRY_CHECK_RC(OM::write(jkr, *be2));
1140 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1143 l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1144 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1145 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1146 ADD_EXPECT(interface_cmds::bvi_delete_cmd(hw_ifh3));
1147 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1148 TRY_CHECK(OM::remove(jkr));
1151 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1153 const std::string nicholas = "NicholasAbercrombie";
1159 std::string itf1_name = "host1";
1160 interface itf1(itf1_name,
1161 interface::type_t::AFPACKET,
1162 interface::admin_state_t::UP);
1163 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1164 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1165 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1166 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1167 TRY_CHECK_RC(OM::write(nicholas, itf1));
1172 std::string itf2_name = "host2";
1173 interface itf2(itf2_name,
1174 interface::type_t::AFPACKET,
1175 interface::admin_state_t::UP);
1177 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1178 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1179 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1180 TRY_CHECK_RC(OM::write(nicholas, itf2));
1182 l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1183 HW::item<bool> xconnect_east(true, rc_t::OK);
1184 HW::item<bool> xconnect_west(true, rc_t::OK);
1185 HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1186 HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1187 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1188 ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1189 TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1193 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1195 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1196 ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1197 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1198 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1199 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1200 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1202 TRY_CHECK(OM::remove(nicholas));
1205 BOOST_AUTO_TEST_CASE(test_vxlan) {
1207 const std::string franz = "FranzKafka";
1211 * Franz creates an interface, Bridge-domain, then binds the two
1215 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1216 boost::asio::ip::address::from_string("10.10.10.11"),
1219 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1221 HW::item<handle_t> hw_vxt(3, rc_t::OK);
1222 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep,
1223 handle_t::INVALID));
1225 TRY_CHECK_RC(OM::write(franz, vxt));
1227 // bridge-domain create
1228 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1229 bridge_domain::arp_term_mode_t::OFF,
1230 bridge_domain::arp_ufwd_mode_t::OFF,
1231 bridge_domain::flood_mode_t::OFF,
1232 bridge_domain::uu_flood_mode_t::OFF,
1233 bridge_domain::mac_age_mode_t::ON);
1235 HW::item<uint32_t> hw_bd(33, rc_t::OK);
1236 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1237 bridge_domain::learning_mode_t::OFF,
1238 bridge_domain::arp_term_mode_t::OFF,
1239 bridge_domain::arp_ufwd_mode_t::OFF,
1240 bridge_domain::flood_mode_t::OFF,
1241 bridge_domain::uu_flood_mode_t::OFF,
1242 bridge_domain::mac_age_mode_t::ON));
1244 TRY_CHECK_RC(OM::write(franz, bd1));
1246 // L2-interface create and bind
1247 // this needs to be delete'd before the flush below, since it too maintains
1248 // references to the BD and Interface
1249 l2_binding *l2itf = new l2_binding(vxt, bd1);
1250 HW::item<bool> hw_l2_bind(true, rc_t::OK);
1252 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1255 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1256 TRY_CHECK_RC(OM::write(franz, *l2itf));
1258 // flush Franz's state
1260 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1262 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1265 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1266 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1267 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1268 TRY_CHECK(OM::remove(franz));
1271 BOOST_AUTO_TEST_CASE(test_vlan) {
1273 const std::string noam = "NoamChomsky";
1276 std::string itf1_name = "host1";
1277 interface itf1(itf1_name,
1278 interface::type_t::AFPACKET,
1279 interface::admin_state_t::UP);
1281 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1282 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1284 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1285 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1287 TRY_CHECK_RC(OM::write(noam, itf1));
1289 sub_interface *vl33 = new sub_interface(itf1,
1290 interface::admin_state_t::UP,
1293 HW::item<handle_t> hw_vl33(3, rc_t::OK);
1294 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1295 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1297 TRY_CHECK_RC(OM::write(noam, *vl33));
1300 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1301 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1302 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1303 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1304 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1305 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1307 TRY_CHECK(OM::remove(noam));
1310 BOOST_AUTO_TEST_CASE(test_acl) {
1312 const std::string fyodor = "FyodorDostoyevsky";
1313 const std::string leo = "LeoTolstoy";
1317 * Fyodor adds an ACL in the input direction
1319 std::string itf1_name = "host1";
1320 interface itf1(itf1_name,
1321 interface::type_t::AFPACKET,
1322 interface::admin_state_t::UP);
1323 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1324 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1325 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1326 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1327 TRY_CHECK_RC(OM::write(fyodor, itf1));
1329 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1330 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1331 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1332 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1333 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1334 HW::item<bool> ae_binding(true, rc_t::OK);
1335 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1336 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1338 route::prefix_t src("10.10.10.10", 32);
1339 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1340 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1342 std::string acl_name = "acl1";
1343 ACL::l3_list acl1(acl_name);
1346 ACL::l3_list::rules_t rules = {r1, r2};
1348 HW::item<handle_t> hw_acl(2, rc_t::OK);
1349 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1350 TRY_CHECK_RC(OM::write(fyodor, acl1));
1352 ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1353 ACL::l3_list acl2(acl_name);
1355 ACL::l3_list::rules_t rules2 = {r3};
1356 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1357 TRY_CHECK_RC(OM::write(fyodor, acl2));
1359 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1360 HW::item<bool> hw_binding(true, rc_t::OK);
1361 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1362 hw_ifh.data(), hw_acl.data()));
1363 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1366 * Leo adds an L2 ACL in the output direction
1368 TRY_CHECK_RC(OM::write(leo, itf1));
1370 std::string l2_acl_name = "l2_acl1";
1371 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1372 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1373 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1374 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1376 ACL::l2_list l2_acl(l2_acl_name);
1377 l2_acl.insert(l2_r2);
1378 l2_acl.insert(l2_r1);
1380 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1382 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1383 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1384 TRY_CHECK_RC(OM::write(leo, l2_acl));
1386 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1387 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1388 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1389 hw_ifh.data(), l2_hw_acl.data()));
1390 TRY_CHECK_RC(OM::write(leo, *l2b));
1393 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1394 hw_ifh.data(), l2_hw_acl.data()));
1395 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1396 TRY_CHECK(OM::remove(leo));
1400 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1403 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1404 hw_ifh.data(), hw_acl.data()));
1405 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1406 ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1407 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1408 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1410 TRY_CHECK(OM::remove(fyodor));
1413 BOOST_AUTO_TEST_CASE(test_igmp) {
1415 const std::string Isaiah = "IsaiahBerlin";
1418 boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1");
1419 boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20");
1420 boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30");
1422 std::string itf3_name = "host3";
1423 interface itf3(itf3_name,
1424 interface::type_t::AFPACKET,
1425 interface::admin_state_t::UP);
1426 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1427 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1428 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1429 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1430 TRY_CHECK_RC(OM::write(Isaiah, itf3));
1432 igmp_binding *ib = new igmp_binding(itf3);
1433 HW::item<bool> hw_binding(true, rc_t::OK);
1434 ADD_EXPECT(igmp_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1435 TRY_CHECK_RC(OM::write(Isaiah, *ib));
1437 igmp_listen::src_addrs_t saddrs = {saddr1, saddr2};
1439 igmp_listen *il = new igmp_listen(*ib, gaddr, saddrs);
1440 HW::item<bool> hw_as_listen(true, rc_t::OK);
1441 ADD_EXPECT(igmp_listen_cmds::listen_cmd(hw_as_listen, hw_ifh.data(), gaddr, saddrs));
1442 TRY_CHECK_RC(OM::write(Isaiah, *il));
1447 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1450 ADD_EXPECT(igmp_listen_cmds::unlisten_cmd(hw_as_listen, hw_ifh.data(), gaddr));
1451 ADD_EXPECT(igmp_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));
1455 TRY_CHECK(OM::remove(Isaiah));
1458 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1460 const std::string kurt = "KurtVonnegut";
1463 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1464 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1466 arp_proxy_config ap(low, high);
1467 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1468 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1469 TRY_CHECK_RC(OM::write(kurt, ap));
1471 std::string itf3_name = "host3";
1472 interface itf3(itf3_name,
1473 interface::type_t::AFPACKET,
1474 interface::admin_state_t::UP);
1475 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1476 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1477 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1478 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1479 TRY_CHECK_RC(OM::write(kurt, itf3));
1481 arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1482 HW::item<bool> hw_binding(true, rc_t::OK);
1483 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1484 TRY_CHECK_RC(OM::write(kurt, *apb));
1488 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1491 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1492 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1493 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1494 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1496 TRY_CHECK(OM::remove(kurt));
1499 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1501 const std::string eliot = "EliotReed";
1505 * Interface 1 is the tx interface
1507 std::string itf1_name = "tx-itf";
1508 interface itf1(itf1_name,
1509 interface::type_t::AFPACKET,
1510 interface::admin_state_t::UP);
1511 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1512 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1513 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1514 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1515 TRY_CHECK_RC(OM::write(eliot, itf1));
1517 boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1520 * Interface 2 is the rx interface
1522 std::string itf2_name = "rx-itf";
1523 interface itf2(itf2_name,
1524 interface::type_t::AFPACKET,
1525 interface::admin_state_t::UP);
1527 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1528 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1529 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1530 TRY_CHECK_RC(OM::write(eliot, itf2));
1532 ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1533 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1534 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1535 ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1536 TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1540 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1542 ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1543 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1544 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1545 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1546 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1548 TRY_CHECK(OM::remove(eliot));
1551 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1553 const std::string eric = "EricAmbler";
1557 * Interface 1 has the L3 address
1559 std::string itf1_name = "host1";
1560 interface itf1(itf1_name,
1561 interface::type_t::AFPACKET,
1562 interface::admin_state_t::UP);
1563 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1564 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1565 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1566 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1567 TRY_CHECK_RC(OM::write(eric, itf1));
1569 route::prefix_t pfx_10("10.10.10.10", 24);
1570 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1571 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1572 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1573 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1574 TRY_CHECK_RC(OM::write(eric, *l3));
1577 * Interface 2 is unnumbered
1579 std::string itf2_name = "host2";
1580 interface itf2(itf2_name,
1581 interface::type_t::AFPACKET,
1582 interface::admin_state_t::UP);
1584 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1585 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1586 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1587 TRY_CHECK_RC(OM::write(eric, itf2));
1589 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1590 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1591 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1592 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1593 TRY_CHECK_RC(OM::write(eric, *ipun));
1598 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1600 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1601 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1602 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1603 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1604 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1605 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1607 TRY_CHECK(OM::remove(eric));
1610 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1612 const std::string paulo = "PauloCoelho";
1618 std::string itf_name = "host_ip6nd";
1619 interface itf(itf_name,
1620 interface::type_t::AFPACKET,
1621 interface::admin_state_t::UP);
1622 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1623 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1624 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1625 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1626 TRY_CHECK_RC(OM::write(paulo, itf));
1628 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1629 l3_binding *l3 = new l3_binding(itf, pfx_10);
1630 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1631 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1632 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1633 TRY_CHECK_RC(OM::write(paulo, *l3));
1635 ra_config ra(0, 1, 0, 4);
1636 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1637 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1638 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1639 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1640 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1645 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1646 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1647 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1648 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1649 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1650 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1654 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1659 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1662 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1663 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1664 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1665 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1667 TRY_CHECK(OM::remove(paulo));
1670 BOOST_AUTO_TEST_CASE(test_interface_span) {
1672 const std::string elif = "ElifShafak";
1676 * Interface 1 to be mirrored
1678 std::string itf1_name = "port-from";
1679 interface itf1(itf1_name,
1680 interface::type_t::AFPACKET,
1681 interface::admin_state_t::UP);
1682 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1683 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1684 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1685 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1686 TRY_CHECK_RC(OM::write(elif, itf1));
1689 * Interface 2 where traffic is mirrored
1691 std::string itf2_name = "port-to";
1692 interface itf2(itf2_name,
1693 interface::type_t::AFPACKET,
1694 interface::admin_state_t::UP);
1696 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1697 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1699 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1700 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1701 TRY_CHECK_RC(OM::write(elif, itf2));
1703 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1704 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1705 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1706 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1707 TRY_CHECK_RC(OM::write(elif, *itf_span));
1709 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1710 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1714 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1715 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1716 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1717 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1718 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1720 TRY_CHECK(OM::remove(elif));
1723 BOOST_AUTO_TEST_CASE(test_routing) {
1725 const std::string ian = "IanFleming";
1729 * non-default route domain
1731 route_domain rd4(1);
1732 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1733 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1734 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1735 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1736 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1737 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1738 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1739 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1740 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1741 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1742 TRY_CHECK_RC(OM::write(ian, rd4));
1745 * a couple of interfaces
1747 std::string itf1_name = "af1";
1748 interface itf1(itf1_name,
1749 interface::type_t::AFPACKET,
1750 interface::admin_state_t::UP);
1751 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1752 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1753 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1754 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1755 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1756 TRY_CHECK_RC(OM::write(ian, itf1));
1758 std::string itf2_name = "af2";
1759 interface *itf2 = new interface(itf2_name,
1760 interface::type_t::AFPACKET,
1761 interface::admin_state_t::UP,
1764 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1765 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1766 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1767 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1768 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1769 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1770 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1771 TRY_CHECK_RC(OM::write(ian, *itf2));
1774 * prefix on each interface
1776 route::prefix_t pfx_10("10.10.10.10", 24);
1777 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1778 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1779 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1780 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1781 TRY_CHECK_RC(OM::write(ian, *l3_10));
1782 route::prefix_t pfx_11("11.11.11.11", 24);
1783 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1784 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1785 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1786 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1787 TRY_CHECK_RC(OM::write(ian, *l3_11));
1790 * A route via interface 1 in the default table
1792 route::prefix_t pfx_5("5.5.5.5", 32);
1793 boost::asio::ip::address nh_9 = boost::asio::ip::address::from_string("10.10.10.9");
1794 route::path *path_9 = new route::path(nh_9, itf1);
1795 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1796 route::path *path_10 = new route::path(nh_10, itf1);
1797 route::ip_route *route_5 = new route::ip_route(pfx_5);
1798 route_5->add(*path_10);
1799 route_5->add(*path_9);
1800 route::path_list_t pl_9_10 = {*path_9, *path_10};
1801 HW::item<handle_t> hw_route_5(0, rc_t::OK);
1802 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_9_10));
1803 TRY_CHECK_RC(OM::write(ian, *route_5));
1805 route_5->remove(*path_9);
1806 route::path_list_t pl_10 = {*path_10};
1807 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_10));
1808 TRY_CHECK_RC(OM::write(ian, *route_5));
1813 * A route via interface 2 in the non-default table
1815 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1816 route::path *path_11 = new route::path(nh_11, *itf2);
1817 boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12");
1818 route::path *path_12 = new route::path(nh_12, *itf2);
1819 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1820 route::path_list_t pl_11 = {*path_11};
1821 route_5_2->add(*path_11);
1822 HW::item<handle_t> hw_route_5_2(1, rc_t::OK);
1823 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11));
1824 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1826 route::path_list_t pl_11_12 = {*path_11, *path_12};
1827 route_5_2->add(*path_12);
1828 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11_12));
1829 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1832 * An ARP entry for the neighbour on itf1
1834 HW::item<handle_t> hw_neighbour(0, rc_t::OK);
1835 mac_address_t mac_n({0,1,2,4,5,6});
1836 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1837 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(),
1839 neighbour::flags_t::STATIC));
1840 TRY_CHECK_RC(OM::write(ian, *ne));
1845 route::prefix_t pfx_6("6.6.6.6", 32);
1846 route::path *path_13 = new route::path(*itf2, nh_proto_t::ETHERNET);
1847 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1848 route_dvr->add(*path_13);
1849 route::path_list_t pl_13 = {*path_13};
1850 HW::item<handle_t> hw_route_dvr(2, rc_t::OK);
1851 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, pl_13));
1852 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1857 route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32);
1858 route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4);
1860 route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4);
1861 route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4);
1862 mroute_4->add(*mp1, route::itf_flags_t::FORWARD);
1863 mroute_4->add(*mp1, route::itf_flags_t::ACCEPT);
1864 mroute_4->add(*mp2, route::itf_flags_t::FORWARD);
1865 HW::item<bool> hw_mroute_4(true, rc_t::OK);
1866 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1867 *mp1, route::itf_flags_t::FORWARD));
1868 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1869 *mp2, route::itf_flags_t::FORWARD));
1870 ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4,
1871 *mp1, route::itf_flags_t::ACCEPT));
1872 TRY_CHECK_RC(OM::write(ian, *mroute_4));
1875 // delete the stack objects that hold references to others
1876 // so the OM::remove is the call that removes the last reference
1886 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1887 *mp1, route::itf_flags_t::FORWARD));
1888 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1889 *mp2, route::itf_flags_t::FORWARD));
1890 ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4,
1891 *mp1, route::itf_flags_t::ACCEPT));
1896 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(),
1898 neighbour::flags_t::STATIC));
1899 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1900 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1901 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1913 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1914 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1915 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1916 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1917 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1918 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1919 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1920 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1921 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1922 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1924 TRY_CHECK(OM::remove(ian));
1927 BOOST_AUTO_TEST_CASE(test_nat) {
1929 const std::string gs = "GeorgeSimenon";
1935 std::string itf_in_name = "inside";
1936 interface itf_in(itf_in_name,
1937 interface::type_t::AFPACKET,
1938 interface::admin_state_t::UP);
1939 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1940 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1941 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1942 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1943 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1944 TRY_CHECK_RC(OM::write(gs, itf_in));
1949 std::string itf_out_name = "port-to";
1950 interface itf_out(itf_out_name,
1951 interface::type_t::AFPACKET,
1952 interface::admin_state_t::UP);
1954 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1955 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1956 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1958 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1959 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1960 TRY_CHECK_RC(OM::write(gs, itf_out));
1963 * A NAT static mapping
1965 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1966 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1968 nat_static ns(in_addr, out_addr);
1969 HW::item<bool> hw_ns(true, rc_t::OK);
1971 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1972 TRY_CHECK_RC(OM::write(gs, ns));
1975 * bind nat inside and out
1977 nat_binding *nb_in = new nat_binding(itf_in,
1980 nat_binding::zone_t::INSIDE);
1981 HW::item<bool> hw_nb_in(true, rc_t::OK);
1983 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1984 hw_ifh.data().value(),
1985 nat_binding::zone_t::INSIDE));
1986 TRY_CHECK_RC(OM::write(gs, *nb_in));
1988 nat_binding *nb_out = new nat_binding(itf_out,
1991 nat_binding::zone_t::OUTSIDE);
1992 HW::item<bool> hw_nb_out(true, rc_t::OK);
1994 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1995 hw_ifh2.data().value(),
1996 nat_binding::zone_t::OUTSIDE));
1997 TRY_CHECK_RC(OM::write(gs, *nb_out));
2003 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
2004 hw_ifh.data().value(),
2005 nat_binding::zone_t::INSIDE));
2006 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
2007 hw_ifh2.data().value(),
2008 nat_binding::zone_t::OUTSIDE));
2009 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
2010 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
2011 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
2012 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
2013 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
2015 TRY_CHECK(OM::remove(gs));
2018 BOOST_AUTO_TEST_CASE(test_interface_events) {
2022 HW::item<bool> hw_want(true, rc_t::OK);
2024 ADD_EXPECT(interface_cmds::events_cmd(ml));
2025 cmd* itf = new interface_cmds::events_cmd(ml);
2031 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
2033 const std::string rene = "ReneGoscinny";
2037 * Create an interface with two IP addresses
2039 std::string itf1_name = "host1";
2040 interface itf1(itf1_name,
2041 interface::type_t::AFPACKET,
2042 interface::admin_state_t::UP);
2043 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
2044 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
2045 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
2046 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
2047 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
2048 TRY_CHECK_RC(OM::write(rene, itf1));
2050 route::prefix_t pfx_10("10.10.10.10", 24);
2051 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
2052 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
2053 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
2054 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2055 TRY_CHECK_RC(OM::write(rene, *l3_1));
2057 route::prefix_t pfx_11("10.10.11.11", 24);
2058 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
2059 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
2060 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
2061 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2062 TRY_CHECK_RC(OM::write(rene, *l3_2));
2065 HW::item<bool> hw_rd_create(true, rc_t::OK);
2066 HW::item<bool> hw_rd_delete(false, rc_t::OK);
2067 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
2068 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
2069 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
2070 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
2071 TRY_CHECK_RC(OM::write(rene, rd));
2074 * update the interface to change to a new route-domain
2075 * expect that the l3-bindings are removed and readded.
2077 interface *itf2 = new interface(itf1_name,
2078 interface::type_t::AFPACKET,
2079 interface::admin_state_t::UP,
2081 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2082 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2083 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
2084 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
2085 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2086 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2087 TRY_CHECK_RC(OM::write(rene, *itf2));
2090 * mve the interface back to the default route-domain
2092 interface itf3(itf1_name,
2093 interface::type_t::AFPACKET,
2094 interface::admin_state_t::UP);
2095 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2096 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2097 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
2098 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
2099 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
2100 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
2101 TRY_CHECK_RC(OM::write(rene, itf3));
2108 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
2109 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
2110 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
2111 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
2112 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
2113 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
2115 TRY_CHECK(OM::remove(rene));
2118 BOOST_AUTO_TEST_CASE(test_prefixes) {
2119 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
2121 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
2123 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
2125 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
2126 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
2128 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
2129 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
2130 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
2132 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
2134 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
2136 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
2138 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
2139 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2140 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
2142 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
2144 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
2145 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
2146 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
2148 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
2150 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
2151 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2152 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
2156 BOOST_AUTO_TEST_CASE(test_pipes) {
2158 const std::string gk = "GKChesterton";
2160 const std::string pipe_name_1 = "pipe1";
2161 VOM::pipe pipe1(1, interface::admin_state_t::UP);
2162 HW::item<handle_t> hw_hdl(4, rc_t::OK);
2163 HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
2165 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
2167 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
2169 ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
2170 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
2171 TRY_CHECK_RC(OM::write(gk, pipe1));
2173 pipe1.set_ends(hw_hdl_pair.data());
2175 // put each end of the pipe in a BD
2176 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
2177 bridge_domain::arp_term_mode_t::OFF,
2178 bridge_domain::arp_ufwd_mode_t::ON,
2179 bridge_domain::flood_mode_t::OFF,
2180 bridge_domain::uu_flood_mode_t::ON,
2181 bridge_domain::mac_age_mode_t::ON);
2183 HW::item<uint32_t> hw_bd(33, rc_t::OK);
2184 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
2185 bridge_domain::learning_mode_t::OFF,
2186 bridge_domain::arp_term_mode_t::OFF,
2187 bridge_domain::arp_ufwd_mode_t::ON,
2188 bridge_domain::flood_mode_t::OFF,
2189 bridge_domain::uu_flood_mode_t::ON,
2190 bridge_domain::mac_age_mode_t::ON));
2192 TRY_CHECK_RC(OM::write(gk, bd1));
2194 l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
2195 HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
2197 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
2198 pipe1.east()->handle(),
2200 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2201 TRY_CHECK_RC(OM::write(gk, *l2_1));
2203 l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2204 HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2206 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2207 pipe1.west()->handle(),
2209 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2210 TRY_CHECK_RC(OM::write(gk, *l2_2));
2216 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2217 pipe1.east()->handle(),
2219 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2220 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2221 pipe1.west()->handle(),
2223 l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2224 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2225 ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2226 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2227 TRY_CHECK(OM::remove(gk));
2230 BOOST_AUTO_TEST_CASE(test_qos) {
2232 const std::string albert = "AlbertCamus";
2236 * Create an interface on which to enable QoS
2238 std::string itf_name = "host1";
2239 interface itf(itf_name,
2240 interface::type_t::AFPACKET,
2241 interface::admin_state_t::UP);
2242 HW::item<handle_t> hw_ifh(2, rc_t::OK);
2243 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
2244 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
2245 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
2246 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
2247 TRY_CHECK_RC(OM::write(albert, itf));
2249 QoS::map::outputs_t out;
2253 QoS::map qem(1, out);
2255 HW::item<bool> hw_qem(true, rc_t::OK);
2256 ADD_EXPECT(QoS::map_cmds::create_cmd(hw_qem, 1, out));
2257 TRY_CHECK_RC(OM::write(albert, qem));
2259 QoS::record *qr = new QoS::record(itf, QoS::source_t::IP);
2260 HW::item<bool> hw_qr(true, rc_t::OK);
2261 ADD_EXPECT(QoS::record_cmds::create_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP));
2262 TRY_CHECK_RC(OM::write(albert, *qr));
2264 QoS::store *qs = new QoS::store(itf, QoS::source_t::IP, 55);
2265 HW::item<bool> hw_qs(true, rc_t::OK);
2266 ADD_EXPECT(QoS::store_cmds::create_cmd(hw_qs, hw_ifh.data(), QoS::source_t::IP, 55));
2267 TRY_CHECK_RC(OM::write(albert, *qs));
2269 QoS::mark *qm = new QoS::mark(itf, qem, QoS::source_t::IP);
2270 HW::item<bool> hw_qm(true, rc_t::OK);
2271 ADD_EXPECT(QoS::mark_cmds::create_cmd(hw_qm, hw_ifh.data(), 1, QoS::source_t::IP));
2272 TRY_CHECK_RC(OM::write(albert, *qm));
2278 ADD_EXPECT(QoS::mark_cmds::delete_cmd(hw_qm, hw_ifh.data(), QoS::source_t::IP));
2279 ADD_EXPECT(QoS::map_cmds::delete_cmd(hw_qem, 1));
2280 ADD_EXPECT(QoS::record_cmds::delete_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP));
2281 ADD_EXPECT(QoS::store_cmds::delete_cmd(hw_qs, hw_ifh.data(), QoS::source_t::IP));
2282 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
2283 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
2284 TRY_CHECK(OM::remove(albert));
2287 BOOST_AUTO_TEST_SUITE_END()