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/l2_binding.hpp"
24 #include "vom/l2_binding_cmds.hpp"
25 #include "vom/l3_binding.hpp"
26 #include "vom/l3_binding_cmds.hpp"
27 #include "vom/bridge_domain.hpp"
28 #include "vom/bridge_domain_entry.hpp"
29 #include "vom/bridge_domain_arp_entry.hpp"
30 #include "vom/bridge_domain_cmds.hpp"
31 #include "vom/bridge_domain_entry_cmds.hpp"
32 #include "vom/bridge_domain_arp_entry_cmds.hpp"
33 #include "vom/prefix.hpp"
34 #include "vom/route.hpp"
35 #include "vom/route_cmds.hpp"
36 #include "vom/route_domain.hpp"
37 #include "vom/route_domain_cmds.hpp"
38 #include "vom/vxlan_tunnel.hpp"
39 #include "vom/vxlan_tunnel_cmds.hpp"
40 #include "vom/sub_interface.hpp"
41 #include "vom/sub_interface_cmds.hpp"
42 #include "vom/acl_ethertype.hpp"
43 #include "vom/acl_ethertype_cmds.hpp"
44 #include "vom/acl_list.hpp"
45 #include "vom/acl_binding.hpp"
46 #include "vom/acl_list_cmds.hpp"
47 #include "vom/acl_binding_cmds.hpp"
48 #include "vom/acl_l3_rule.hpp"
49 #include "vom/acl_l2_rule.hpp"
50 #include "vom/arp_proxy_config.hpp"
51 #include "vom/arp_proxy_binding.hpp"
52 #include "vom/arp_proxy_config_cmds.hpp"
53 #include "vom/arp_proxy_binding_cmds.hpp"
54 #include "vom/ip_unnumbered.hpp"
55 #include "vom/ip_unnumbered_cmds.hpp"
56 #include "vom/interface_ip6_nd.hpp"
57 #include "vom/interface_span.hpp"
58 #include "vom/interface_span_cmds.hpp"
59 #include "vom/neighbour.hpp"
60 #include "vom/neighbour_cmds.hpp"
61 #include "vom/nat_static.hpp"
62 #include "vom/nat_static_cmds.hpp"
63 #include "vom/nat_binding.hpp"
64 #include "vom/nat_binding_cmds.hpp"
66 using namespace boost;
70 * An expectation exception
75 ExpException(unsigned int number)
77 // a neat place to add a break point
78 std::cout << " ExpException here: " << number << std::endl;
82 class MockListener : public interface::event_listener,
83 public interface::stat_listener
85 void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
88 void handle_interface_event(interface_cmds::events_cmd *cmd)
93 class MockCmdQ : public HW::cmd_q
105 m_exp_queue.push_back(f);
109 m_act_queue.push_back(f);
111 void enqueue(std::queue<cmd*> &cmds)
115 m_act_queue.push_back(cmds.front());
119 void enqueue(std::shared_ptr<cmd> f)
121 m_act_queue.push_back(f.get());
128 void dequeue(std::shared_ptr<cmd> cmd)
132 void strict_order(bool on)
139 return ((0 == m_exp_queue.size()) &&
140 (0 == m_act_queue.size()));
148 while (m_act_queue.size())
150 bool matched = false;
151 auto it_exp = m_exp_queue.begin();
152 auto it_act = m_act_queue.begin();
156 std::cout << " Act: " << f_act->to_string() << std::endl;
157 while (it_exp != m_exp_queue.end())
162 std::cout << " Exp: " << f_exp->to_string() << std::endl;
164 if (typeid(*f_exp) != typeid(*f_act))
166 throw ExpException(1);
169 if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
171 rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
173 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
175 rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
177 else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
179 rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
181 else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
183 rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
185 else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
187 rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
189 else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
191 rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
193 else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
195 rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
197 else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
199 rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
201 else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
203 rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
205 else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
207 rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
209 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
211 rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
213 else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
215 rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
217 else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
219 rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
221 else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
223 rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
225 else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
227 rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
229 else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
231 rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
233 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
235 rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
237 else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
239 rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
241 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
243 rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
245 else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
247 rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
249 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
251 rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
253 else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
255 rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
257 else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
259 rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
261 else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
263 rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
265 else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
267 rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
269 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
271 rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
273 else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
275 rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
277 else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
279 rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
281 else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
283 rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
285 else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
287 rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
289 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
291 rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
293 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
295 rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
297 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
299 rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
301 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
303 rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
305 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
307 rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
309 else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
311 rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
313 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
315 rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
317 else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
319 rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
321 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
323 rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
325 else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
327 rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
329 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
331 rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
333 else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
335 rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
337 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
339 rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
341 else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
343 rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
345 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
347 rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
349 else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
351 rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
353 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
355 rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
357 else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
359 rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
361 else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
363 rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
365 else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
367 rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
369 else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
371 rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
373 else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
375 rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
377 else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
379 rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
381 else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
383 rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
385 else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
387 rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
391 throw ExpException(2);
394 // if we get here then we found the match.
395 m_exp_queue.erase(it_exp);
396 m_act_queue.erase(it_act);
400 // return any injected failures to the agent
401 if (rc_t::OK != rc && rc_t::NOOP != rc)
409 catch (ExpException &e)
411 // The expected and actual do not match
414 // in strict ordering mode this is fatal, so rethrow
419 // move the iterator onto the next in the expected list and
427 throw ExpException(3);
434 template <typename T>
435 rc_t handle_derived(const cmd *f_exp, cmd *f_act)
440 i_exp = dynamic_cast<const T*>(f_exp);
441 i_act = dynamic_cast<T*>(f_act);
442 if (!(*i_exp == *i_act))
444 throw ExpException(4);
446 // pass the data and return code to the agent
447 i_act->item() = i_exp->item();
449 return (i_act->item().rc());
452 // The Q to push the expectations on
453 std::deque<cmd*> m_exp_queue;
455 // the queue to push the actual events on
456 std::deque<cmd*> m_act_queue;
458 // control whether the expected queue is strictly ordered.
473 logger().set(log_level_t::DEBUG);
481 BOOST_AUTO_TEST_SUITE(vom)
483 #define TRY_CHECK_RC(stmt) \
486 BOOST_CHECK(rc_t::OK == stmt); \
488 catch (ExpException &e) \
490 BOOST_CHECK(false); \
492 BOOST_CHECK(vi.f->is_empty()); \
495 #define TRY_CHECK(stmt) \
500 catch (ExpException &e) \
502 BOOST_CHECK(false); \
504 BOOST_CHECK(vi.f->is_empty()); \
507 #define ADD_EXPECT(stmt) \
508 vi.f->expect(new stmt)
510 #define STRICT_ORDER_OFF() \
511 vi.f->strict_order(false)
513 BOOST_AUTO_TEST_CASE(test_interface) {
515 const std::string go = "GeorgeOrwell";
516 const std::string js = "JohnSteinbeck";
520 * George creates and deletes the interface
522 std::string itf1_name = "afpacket1";
523 interface itf1(itf1_name,
524 interface::type_t::AFPACKET,
525 interface::admin_state_t::UP);
528 * set the expectation for a afpacket interface create.
529 * 2 is the interface handle VPP [mock] assigns
531 HW::item<handle_t> hw_ifh(2, rc_t::OK);
532 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
534 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
535 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
537 TRY_CHECK_RC(OM::write(go, itf1));
539 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
540 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
541 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
543 TRY_CHECK(OM::remove(go));
546 * George creates the interface, then John brings it down.
547 * George's remove is a no-op, sice John also owns the interface
549 interface itf1b(itf1_name,
550 interface::type_t::AFPACKET,
551 interface::admin_state_t::DOWN);
553 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
554 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
555 TRY_CHECK_RC(OM::write(go, itf1));
557 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
558 TRY_CHECK_RC(OM::write(js, itf1b));
560 TRY_CHECK(OM::remove(go));
562 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
563 TRY_CHECK(OM::remove(js));
566 * George adds an interface, then we flush all of Geroge's state
568 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
569 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
570 TRY_CHECK_RC(OM::write(go, itf1));
572 TRY_CHECK(OM::mark(go));
574 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
575 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
576 TRY_CHECK(OM::sweep(go));
579 * George adds an interface. mark stale. update the same interface. sweep
580 * and expect no delete
582 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
583 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
584 TRY_CHECK_RC(OM::write(go, itf1b));
586 TRY_CHECK(OM::mark(go));
588 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
589 TRY_CHECK_RC(OM::write(go, itf1));
591 TRY_CHECK(OM::sweep(go));
593 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
594 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
595 TRY_CHECK(OM::remove(go));
598 * George adds an insterface, then we mark that state. Add a second interface
599 * an flush the first that is now stale.
601 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
602 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
603 TRY_CHECK_RC(OM::write(go, itf1));
605 TRY_CHECK(OM::mark(go));
607 std::string itf2_name = "afpacket2";
608 interface itf2(itf2_name,
609 interface::type_t::AFPACKET,
610 interface::admin_state_t::UP);
611 HW::item<handle_t> hw_ifh2(3, rc_t::OK);
613 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
614 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
615 TRY_CHECK_RC(OM::write(go, itf2));
617 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
618 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
619 TRY_CHECK(OM::sweep(go));
621 TRY_CHECK(OM::mark(go));
623 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
624 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
625 TRY_CHECK(OM::sweep(go));
628 BOOST_AUTO_TEST_CASE(test_bvi) {
630 const std::string ernest = "ErnestHemmingway";
631 const std::string graham = "GrahamGreene";
635 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
637 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
641 * Enrest creates a BVI with address 10.10.10.10/24
643 route::prefix_t pfx_10("10.10.10.10", 24);
645 const std::string bvi_name = "bvi1";
646 interface itf(bvi_name,
647 interface::type_t::BVI,
648 interface::admin_state_t::UP);
649 HW::item<handle_t> hw_ifh(4, rc_t::OK);
650 HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
652 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
653 ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
654 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
655 TRY_CHECK_RC(OM::write(ernest, itf));
657 l3 = new l3_binding(itf, pfx_10);
658 HW::item<bool> hw_l3_bind(true, rc_t::OK);
659 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
660 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
661 TRY_CHECK_RC(OM::write(ernest, *l3));
663 // change the MAC address on the BVI
664 interface itf_new_mac(bvi_name,
665 interface::type_t::BVI,
666 interface::admin_state_t::UP);
667 l2_address_t l2_addr({0,1,2,3,4,5});
668 HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
669 itf_new_mac.set(l2_addr);
670 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
671 TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
673 // create/write the interface to the OM again but with an unset MAC
674 // this should not generate a MAC address update
675 TRY_CHECK_RC(OM::write(ernest, itf));
677 // change the MAC address on the BVI - again
678 interface itf_new_mac2(bvi_name,
679 interface::type_t::BVI,
680 interface::admin_state_t::UP);
681 l2_address_t l2_addr2({0,1,2,3,4,6});
682 HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
683 itf_new_mac2.set(l2_addr2);
684 ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
685 TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
688 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
689 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
690 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
691 TRY_CHECK(OM::remove(ernest));
694 * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
697 HW::item<bool> hw_rd4_create(true, rc_t::OK);
698 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
699 HW::item<bool> hw_rd6_create(true, rc_t::OK);
700 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
701 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
702 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
703 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
704 HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
705 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
706 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
707 TRY_CHECK_RC(OM::write(graham, rd));
709 const std::string bvi2_name = "bvi2";
710 interface *itf2 = new interface(bvi2_name,
711 interface::type_t::BVI,
712 interface::admin_state_t::UP,
714 HW::item<handle_t> hw_ifh2(5, rc_t::OK);
716 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
717 ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
718 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
719 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
720 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
722 TRY_CHECK_RC(OM::write(graham, *itf2));
724 l3 = new l3_binding(*itf2, pfx_10);
725 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
726 TRY_CHECK_RC(OM::write(graham, *l3));
731 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
732 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
733 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
734 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
735 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
736 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
737 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
738 TRY_CHECK(OM::remove(graham));
741 BOOST_AUTO_TEST_CASE(test_bridge) {
743 const std::string franz = "FranzKafka";
744 const std::string dante = "Dante";
745 const std::string jkr = "jkrowling";
749 * Franz creates an interface, Bridge-domain, then binds the two
753 std::string itf1_name = "afpacket1";
754 interface itf1(itf1_name,
755 interface::type_t::AFPACKET,
756 interface::admin_state_t::UP);
758 HW::item<handle_t> hw_ifh(3, rc_t::OK);
759 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
761 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
762 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
764 TRY_CHECK_RC(OM::write(franz, itf1));
766 // bridge-domain create
767 bridge_domain bd1(33);
769 HW::item<uint32_t> hw_bd(33, rc_t::OK);
770 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd, bridge_domain::learning_mode_t::ON));
772 TRY_CHECK_RC(OM::write(franz, bd1));
774 // L2-interface create and bind
775 // this needs to be delete'd before the flush below, since it too maintains
776 // references to the BD and Interface
777 l2_binding *l2itf = new l2_binding(itf1, bd1);
778 HW::item<bool> hw_l2_bind(true, rc_t::OK);
780 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
781 TRY_CHECK_RC(OM::write(franz, *l2itf));
784 * Dante adds an interface to the same BD
786 std::string itf2_name = "afpacket2";
787 interface itf2(itf2_name,
788 interface::type_t::AFPACKET,
789 interface::admin_state_t::UP);
791 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
792 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
793 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
794 TRY_CHECK_RC(OM::write(dante, itf2));
796 // BD add is a no-op since it exists
797 TRY_CHECK_RC(OM::write(dante, bd1));
799 l2_binding *l2itf2 = new l2_binding(itf2, bd1);
800 HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
801 l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
803 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
804 ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
805 TRY_CHECK_RC(OM::write(dante, *l2itf2));
807 // Add some static entries to the bridge-domain
808 HW::item<bool> hw_be1(true, rc_t::OK);
809 mac_address_t mac1({0,1,2,3,4,5});
810 bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
811 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
813 TRY_CHECK_RC(OM::write(dante, *be1));
815 // Add some entries to the bridge-domain ARP termination table
816 HW::item<bool> hw_bea1(true, rc_t::OK);
817 boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
819 bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
820 ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
821 TRY_CHECK_RC(OM::write(dante, *bea1));
823 // flush Franz's state
825 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
827 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
828 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
829 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
830 TRY_CHECK(OM::remove(franz));
832 // flush Dante's state - the order the interface and BD are deleted
833 // is an uncontrollable artifact of the C++ object destruction.
838 ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
839 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
840 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
842 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
843 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
844 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
845 TRY_CHECK(OM::remove(dante));
847 // test the BVI entry in l2fib
848 bridge_domain bd2(99);
850 HW::item<uint32_t> hw_bd2(99, rc_t::OK);
851 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2, bridge_domain::learning_mode_t::ON));
853 TRY_CHECK_RC(OM::write(jkr, bd2));
855 std::string itf3_name = "bvi";
856 interface itf3(itf3_name,
857 interface::type_t::BVI,
858 interface::admin_state_t::UP);
860 HW::item<handle_t> hw_ifh3(5, rc_t::OK);
861 ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
862 ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
863 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
864 TRY_CHECK_RC(OM::write(jkr, itf3));
866 l2_binding *l2itf3 = new l2_binding(itf3, bd2);
867 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
868 TRY_CHECK_RC(OM::write(jkr, *l2itf3));
870 HW::item<bool> hw_be2(true, rc_t::OK);
871 mac_address_t mac2({0,1,2,3,4,5});
872 bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
873 ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
874 TRY_CHECK_RC(OM::write(jkr, *be2));
879 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
880 ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
881 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
882 ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
883 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
884 TRY_CHECK(OM::remove(jkr));
887 BOOST_AUTO_TEST_CASE(test_vxlan) {
889 const std::string franz = "FranzKafka";
893 * Franz creates an interface, Bridge-domain, then binds the two
897 vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
898 boost::asio::ip::address::from_string("10.10.10.11"),
901 vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
903 HW::item<handle_t> hw_vxt(3, rc_t::OK);
904 ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
906 TRY_CHECK_RC(OM::write(franz, vxt));
908 // bridge-domain create
909 bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF);
911 HW::item<uint32_t> hw_bd(33, rc_t::OK);
912 ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd, bridge_domain::learning_mode_t::OFF));
914 TRY_CHECK_RC(OM::write(franz, bd1));
916 // L2-interface create and bind
917 // this needs to be delete'd before the flush below, since it too maintains
918 // references to the BD and Interface
919 l2_binding *l2itf = new l2_binding(vxt, bd1);
920 HW::item<bool> hw_l2_bind(true, rc_t::OK);
922 ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
923 TRY_CHECK_RC(OM::write(franz, *l2itf));
925 // flush Franz's state
927 HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
929 ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
930 ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
931 ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
932 TRY_CHECK(OM::remove(franz));
935 BOOST_AUTO_TEST_CASE(test_vlan) {
937 const std::string noam = "NoamChomsky";
940 std::string itf1_name = "host1";
941 interface itf1(itf1_name,
942 interface::type_t::AFPACKET,
943 interface::admin_state_t::UP);
945 HW::item<handle_t> hw_ifh(2, rc_t::OK);
946 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
948 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
949 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
951 TRY_CHECK_RC(OM::write(noam, itf1));
953 sub_interface *vl33 = new sub_interface(itf1,
954 interface::admin_state_t::UP,
957 HW::item<handle_t> hw_vl33(3, rc_t::OK);
958 ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
959 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
961 TRY_CHECK_RC(OM::write(noam, *vl33));
964 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
965 HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
966 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
967 ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
968 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
969 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
971 TRY_CHECK(OM::remove(noam));
974 BOOST_AUTO_TEST_CASE(test_acl) {
976 const std::string fyodor = "FyodorDostoyevsky";
977 const std::string leo = "LeoTolstoy";
981 * Fyodor adds an ACL in the input direction
983 std::string itf1_name = "host1";
984 interface itf1(itf1_name,
985 interface::type_t::AFPACKET,
986 interface::admin_state_t::UP);
987 HW::item<handle_t> hw_ifh(2, rc_t::OK);
988 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
989 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
990 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
991 TRY_CHECK_RC(OM::write(fyodor, itf1));
993 ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
994 ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
995 ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
996 ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
997 ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
998 HW::item<bool> ae_binding(true, rc_t::OK);
999 ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1000 TRY_CHECK_RC(OM::write(fyodor, *a_e));
1002 route::prefix_t src("10.10.10.10", 32);
1003 ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1004 ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1006 std::string acl_name = "acl1";
1007 ACL::l3_list acl1(acl_name);
1010 ACL::l3_list::rules_t rules = {r1, r2};
1012 HW::item<handle_t> hw_acl(2, rc_t::OK);
1013 ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1014 TRY_CHECK_RC(OM::write(fyodor, acl1));
1016 ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1017 HW::item<bool> hw_binding(true, rc_t::OK);
1018 ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1019 hw_ifh.data(), hw_acl.data()));
1020 TRY_CHECK_RC(OM::write(fyodor, *l3b));
1023 * Leo adds an L2 ACL in the output direction
1025 TRY_CHECK_RC(OM::write(leo, itf1));
1027 std::string l2_acl_name = "l2_acl1";
1028 mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1029 mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1030 ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1031 ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1033 ACL::l2_list l2_acl(l2_acl_name);
1034 l2_acl.insert(l2_r2);
1035 l2_acl.insert(l2_r1);
1037 ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1039 HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1040 ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1041 TRY_CHECK_RC(OM::write(leo, l2_acl));
1043 ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1044 HW::item<bool> l2_hw_binding(true, rc_t::OK);
1045 ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1046 hw_ifh.data(), l2_hw_acl.data()));
1047 TRY_CHECK_RC(OM::write(leo, *l2b));
1050 ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1051 hw_ifh.data(), l2_hw_acl.data()));
1052 ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1053 TRY_CHECK(OM::remove(leo));
1057 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1060 ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1061 hw_ifh.data(), hw_acl.data()));
1062 ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1063 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1064 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1066 TRY_CHECK(OM::remove(fyodor));
1069 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1071 const std::string kurt = "KurtVonnegut";
1074 asio::ip::address_v4 low = asio::ip::address_v4::from_string("10.0.0.0");
1075 asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1077 arp_proxy_config ap(low, high);
1078 HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1079 ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1080 TRY_CHECK_RC(OM::write(kurt, ap));
1082 std::string itf3_name = "host3";
1083 interface itf3(itf3_name,
1084 interface::type_t::AFPACKET,
1085 interface::admin_state_t::UP);
1086 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1087 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1088 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1089 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1090 TRY_CHECK_RC(OM::write(kurt, itf3));
1092 arp_proxy_binding *apb = new arp_proxy_binding(itf3, ap);
1093 HW::item<bool> hw_binding(true, rc_t::OK);
1094 ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1095 TRY_CHECK_RC(OM::write(kurt, *apb));
1099 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1102 ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1103 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1104 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1105 ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1107 TRY_CHECK(OM::remove(kurt));
1110 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1112 const std::string eric = "EricAmbler";
1116 * Interface 1 has the L3 address
1118 std::string itf1_name = "host1";
1119 interface itf1(itf1_name,
1120 interface::type_t::AFPACKET,
1121 interface::admin_state_t::UP);
1122 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1123 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1124 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1125 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1126 TRY_CHECK_RC(OM::write(eric, itf1));
1128 route::prefix_t pfx_10("10.10.10.10", 24);
1129 l3_binding *l3 = new l3_binding(itf1, pfx_10);
1130 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1131 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1132 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1133 TRY_CHECK_RC(OM::write(eric, *l3));
1136 * Interface 2 is unnumbered
1138 std::string itf2_name = "host2";
1139 interface itf2(itf2_name,
1140 interface::type_t::AFPACKET,
1141 interface::admin_state_t::UP);
1143 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1144 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1145 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1146 TRY_CHECK_RC(OM::write(eric, itf2));
1148 ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1149 HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1150 HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1151 ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1152 TRY_CHECK_RC(OM::write(eric, *ipun));
1157 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1159 ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1160 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1161 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1162 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1163 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1164 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1166 TRY_CHECK(OM::remove(eric));
1169 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1171 const std::string paulo = "PauloCoelho";
1177 std::string itf_name = "host_ip6nd";
1178 interface itf(itf_name,
1179 interface::type_t::AFPACKET,
1180 interface::admin_state_t::UP);
1181 HW::item<handle_t> hw_ifh(3, rc_t::OK);
1182 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1183 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1184 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1185 TRY_CHECK_RC(OM::write(paulo, itf));
1187 route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1188 l3_binding *l3 = new l3_binding(itf, pfx_10);
1189 HW::item<bool> hw_l3_bind(true, rc_t::OK);
1190 HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1191 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1192 TRY_CHECK_RC(OM::write(paulo, *l3));
1194 ra_config ra(0, 1, 0, 4);
1195 ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1196 HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1197 HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1198 ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1199 TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1204 ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1205 ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1206 HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1207 HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1208 ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1209 TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1213 ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1218 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1221 ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1222 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1223 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1224 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1226 TRY_CHECK(OM::remove(paulo));
1229 BOOST_AUTO_TEST_CASE(test_interface_span) {
1231 const std::string elif = "ElifShafak";
1235 * Interface 1 to be mirrored
1237 std::string itf1_name = "port-from";
1238 interface itf1(itf1_name,
1239 interface::type_t::AFPACKET,
1240 interface::admin_state_t::UP);
1241 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1242 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1243 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1244 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1245 TRY_CHECK_RC(OM::write(elif, itf1));
1248 * Interface 2 where traffic is mirrored
1250 std::string itf2_name = "port-to";
1251 interface itf2(itf2_name,
1252 interface::type_t::AFPACKET,
1253 interface::admin_state_t::UP);
1255 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1256 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1258 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1259 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1260 TRY_CHECK_RC(OM::write(elif, itf2));
1262 interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1263 HW::item<bool> hw_is_cfg(true, rc_t::OK);
1264 HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1265 ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1266 TRY_CHECK_RC(OM::write(elif, *itf_span));
1268 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1269 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1273 ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1274 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1275 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1276 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1277 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1279 TRY_CHECK(OM::remove(elif));
1282 BOOST_AUTO_TEST_CASE(test_routing) {
1284 const std::string ian = "IanFleming";
1288 * non-default route domain
1290 route_domain rd4(1);
1291 HW::item<bool> hw_rd4_create(true, rc_t::OK);
1292 HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1293 HW::item<bool> hw_rd6_create(true, rc_t::OK);
1294 HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1295 HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1296 HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1297 HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1298 HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1299 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1300 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1301 TRY_CHECK_RC(OM::write(ian, rd4));
1304 * a couple of interfaces
1306 std::string itf1_name = "af1";
1307 interface itf1(itf1_name,
1308 interface::type_t::AFPACKET,
1309 interface::admin_state_t::UP);
1310 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1311 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1312 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1313 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1314 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1315 TRY_CHECK_RC(OM::write(ian, itf1));
1317 std::string itf2_name = "af2";
1318 interface *itf2 = new interface(itf2_name,
1319 interface::type_t::AFPACKET,
1320 interface::admin_state_t::UP,
1323 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1324 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1325 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1326 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1327 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1328 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1329 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1330 TRY_CHECK_RC(OM::write(ian, *itf2));
1333 * prefix on each interface
1335 route::prefix_t pfx_10("10.10.10.10", 24);
1336 l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1337 HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1338 HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1339 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1340 TRY_CHECK_RC(OM::write(ian, *l3_10));
1341 route::prefix_t pfx_11("11.11.11.11", 24);
1342 l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1343 HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1344 HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1345 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1346 TRY_CHECK_RC(OM::write(ian, *l3_11));
1349 * A route via interface 1 in the default table
1351 route::prefix_t pfx_5("5.5.5.5", 32);
1352 boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1353 route::path *path_10 = new route::path(nh_10, itf1);
1354 route::ip_route *route_5 = new route::ip_route(pfx_5);
1355 route_5->add(*path_10);
1356 HW::item<bool> hw_route_5(true, rc_t::OK);
1357 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
1358 TRY_CHECK_RC(OM::write(ian, *route_5));
1361 * A route via interface 2 in the non-default table
1363 boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1364 route::path *path_11 = new route::path(nh_11, *itf2);
1365 route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1366 route_5_2->add(*path_11);
1367 HW::item<bool> hw_route_5_2(true, rc_t::OK);
1368 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
1369 TRY_CHECK_RC(OM::write(ian, *route_5_2));
1372 * An ARP entry for the neighbour on itf1
1374 HW::item<bool> hw_neighbour(true, rc_t::OK);
1375 mac_address_t mac_n({0,1,2,4,5,6});
1376 neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1377 ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1378 TRY_CHECK_RC(OM::write(ian, *ne));
1383 route::prefix_t pfx_6("6.6.6.6", 32);
1384 route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1385 route::ip_route *route_dvr = new route::ip_route(pfx_6);
1386 route_dvr->add(*path_l2);
1387 HW::item<bool> hw_route_dvr(true, rc_t::OK);
1388 ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
1389 TRY_CHECK_RC(OM::write(ian, *route_dvr));
1392 // delete the stack objects that hold references to others
1393 // so the OM::remove is the call that removes the last reference
1404 ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1405 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1406 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1407 ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1408 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1409 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1410 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1411 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1412 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1413 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1414 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1415 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1416 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1417 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1419 TRY_CHECK(OM::remove(ian));
1422 BOOST_AUTO_TEST_CASE(test_nat) {
1424 const std::string gs = "GeorgeSimenon";
1430 std::string itf_in_name = "inside";
1431 interface itf_in(itf_in_name,
1432 interface::type_t::AFPACKET,
1433 interface::admin_state_t::UP);
1434 HW::item<handle_t> hw_ifh(2, rc_t::OK);
1435 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1436 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1437 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1438 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1439 TRY_CHECK_RC(OM::write(gs, itf_in));
1444 std::string itf_out_name = "port-to";
1445 interface itf_out(itf_out_name,
1446 interface::type_t::AFPACKET,
1447 interface::admin_state_t::UP);
1449 HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1450 HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1451 HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1453 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1454 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1455 TRY_CHECK_RC(OM::write(gs, itf_out));
1458 * A NAT static mapping
1460 boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1461 boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1463 nat_static ns(in_addr, out_addr);
1464 HW::item<bool> hw_ns(true, rc_t::OK);
1466 ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1467 TRY_CHECK_RC(OM::write(gs, ns));
1470 * bind nat inside and out
1472 nat_binding *nb_in = new nat_binding(itf_in,
1475 nat_binding::zone_t::INSIDE);
1476 HW::item<bool> hw_nb_in(true, rc_t::OK);
1478 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1479 hw_ifh.data().value(),
1480 nat_binding::zone_t::INSIDE));
1481 TRY_CHECK_RC(OM::write(gs, *nb_in));
1483 nat_binding *nb_out = new nat_binding(itf_out,
1486 nat_binding::zone_t::OUTSIDE);
1487 HW::item<bool> hw_nb_out(true, rc_t::OK);
1489 ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1490 hw_ifh2.data().value(),
1491 nat_binding::zone_t::OUTSIDE));
1492 TRY_CHECK_RC(OM::write(gs, *nb_out));
1498 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1499 hw_ifh.data().value(),
1500 nat_binding::zone_t::INSIDE));
1501 ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1502 hw_ifh2.data().value(),
1503 nat_binding::zone_t::OUTSIDE));
1504 ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1505 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1506 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1507 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1508 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1510 TRY_CHECK(OM::remove(gs));
1513 BOOST_AUTO_TEST_CASE(test_interface_events) {
1517 HW::item<bool> hw_want(true, rc_t::OK);
1519 ADD_EXPECT(interface_cmds::events_cmd(ml));
1520 cmd* itf = new interface_cmds::events_cmd(ml);
1526 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1528 const std::string rene = "ReneGoscinny";
1532 * Create an interface with two IP addresses
1534 std::string itf1_name = "host1";
1535 interface itf1(itf1_name,
1536 interface::type_t::AFPACKET,
1537 interface::admin_state_t::UP);
1538 HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1539 HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1540 HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1541 ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1542 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1543 TRY_CHECK_RC(OM::write(rene, itf1));
1545 route::prefix_t pfx_10("10.10.10.10", 24);
1546 l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1547 HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1548 HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1549 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1550 TRY_CHECK_RC(OM::write(rene, *l3_1));
1552 route::prefix_t pfx_11("10.10.11.11", 24);
1553 l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1554 HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1555 HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1556 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1557 TRY_CHECK_RC(OM::write(rene, *l3_2));
1560 HW::item<bool> hw_rd_create(true, rc_t::OK);
1561 HW::item<bool> hw_rd_delete(false, rc_t::OK);
1562 HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1563 HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1564 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1565 ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1566 TRY_CHECK_RC(OM::write(rene, rd));
1569 * update the interface to change to a new route-domain
1570 * expect that the l3-bindings are removed and readded.
1572 interface *itf2 = new interface(itf1_name,
1573 interface::type_t::AFPACKET,
1574 interface::admin_state_t::UP,
1576 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1577 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1578 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1579 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1580 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1581 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1582 TRY_CHECK_RC(OM::write(rene, *itf2));
1585 * mve the interface back to the default route-domain
1587 interface itf3(itf1_name,
1588 interface::type_t::AFPACKET,
1589 interface::admin_state_t::UP);
1590 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1591 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1592 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1593 ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1594 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1595 ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1596 TRY_CHECK_RC(OM::write(rene, itf3));
1603 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1604 ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1605 ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1606 ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1607 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1608 ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1610 TRY_CHECK(OM::remove(rene));
1613 BOOST_AUTO_TEST_CASE(test_prefixes) {
1614 route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1616 BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1618 route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1620 BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1621 BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1623 route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1624 BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1625 BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1627 route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1629 BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1631 route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1633 BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1634 BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1635 BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1637 route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1639 BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1640 BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1641 BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1643 route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1645 BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1646 BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1647 BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1651 BOOST_AUTO_TEST_SUITE_END()