vom: Add cross connect support
[vpp.git] / test / ext / vom_test.cpp
1 /*
2  * Test suite for class VppOM
3  *
4  * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
5  *
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
9  */
10 #define BOOST_TEST_MODULE "VPP OBJECT MODEL"
11 #define BOOST_TEST_DYN_LINK
12
13 #include <boost/test/unit_test.hpp>
14 #include <boost/assign/list_inserter.hpp>
15
16
17 #include <iostream>
18 #include <deque>
19
20 #include "vom/om.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_xconnect.hpp"
29 #include "vom/l2_xconnect_cmds.hpp"
30 #include "vom/l3_binding.hpp"
31 #include "vom/l3_binding_cmds.hpp"
32 #include "vom/bridge_domain.hpp"
33 #include "vom/bridge_domain_entry.hpp"
34 #include "vom/bridge_domain_arp_entry.hpp"
35 #include "vom/bridge_domain_cmds.hpp"
36 #include "vom/bridge_domain_entry_cmds.hpp"
37 #include "vom/bridge_domain_arp_entry_cmds.hpp"
38 #include "vom/prefix.hpp"
39 #include "vom/route.hpp"
40 #include "vom/route_cmds.hpp"
41 #include "vom/route_domain.hpp"
42 #include "vom/route_domain_cmds.hpp"
43 #include "vom/vxlan_tunnel.hpp"
44 #include "vom/vxlan_tunnel_cmds.hpp"
45 #include "vom/sub_interface.hpp"
46 #include "vom/sub_interface_cmds.hpp"
47 #include "vom/acl_ethertype.hpp"
48 #include "vom/acl_ethertype_cmds.hpp"
49 #include "vom/acl_list.hpp"
50 #include "vom/acl_binding.hpp"
51 #include "vom/acl_list_cmds.hpp"
52 #include "vom/acl_binding_cmds.hpp"
53 #include "vom/acl_l3_rule.hpp"
54 #include "vom/acl_l2_rule.hpp"
55 #include "vom/arp_proxy_config.hpp"
56 #include "vom/arp_proxy_binding.hpp"
57 #include "vom/arp_proxy_config_cmds.hpp"
58 #include "vom/arp_proxy_binding_cmds.hpp"
59 #include "vom/ip_unnumbered.hpp"
60 #include "vom/ip_unnumbered_cmds.hpp"
61 #include "vom/interface_ip6_nd.hpp"
62 #include "vom/interface_span.hpp"
63 #include "vom/interface_span_cmds.hpp"
64 #include "vom/neighbour.hpp"
65 #include "vom/neighbour_cmds.hpp"
66 #include "vom/nat_static.hpp"
67 #include "vom/nat_static_cmds.hpp"
68 #include "vom/nat_binding.hpp"
69 #include "vom/nat_binding_cmds.hpp"
70
71 using namespace boost;
72 using namespace VOM;
73
74 /**
75  * An expectation exception
76  */
77 class ExpException
78 {
79 public:
80     ExpException(unsigned int number)
81     {
82         // a neat place to add a break point
83         std::cout << "  ExpException here: " << number << std::endl;
84     }
85 };
86
87 class MockListener : public interface::event_listener,
88                      public interface::stat_listener
89 {
90     void handle_interface_stat(interface_cmds::stats_enable_cmd *cmd)
91     {
92     }
93     void handle_interface_event(interface_cmds::events_cmd *cmd)
94     {
95     }
96 };
97
98 class MockCmdQ : public HW::cmd_q
99 {
100 public:
101     MockCmdQ():
102         m_strict_order(true)
103     {
104     }
105     virtual ~MockCmdQ()
106     {
107     }
108     void expect(cmd *f)
109     {
110         m_exp_queue.push_back(f);
111     }
112     void enqueue(cmd *f)
113     {
114         m_act_queue.push_back(f);
115     }
116     void enqueue(std::queue<cmd*> &cmds)
117     {
118         while (cmds.size())
119         {
120             m_act_queue.push_back(cmds.front());
121             cmds.pop();
122         }
123     }
124     void enqueue(std::shared_ptr<cmd> f)
125     {
126         m_act_queue.push_back(f.get());
127     }
128
129     void dequeue(cmd *f)
130     {
131     }
132
133     void dequeue(std::shared_ptr<cmd> cmd)
134     {
135     }
136
137     void strict_order(bool on)
138     {
139         m_strict_order = on;
140     }
141
142     bool is_empty()
143     {
144         return ((0 == m_exp_queue.size()) &&
145                 (0 == m_act_queue.size()));
146     }
147
148     rc_t write()
149     {
150         cmd *f_exp, *f_act;
151         rc_t rc = rc_t::OK;
152
153         while (m_act_queue.size())
154         {
155             bool matched = false;
156             auto it_exp = m_exp_queue.begin();
157             auto it_act = m_act_queue.begin();
158
159             f_act = *it_act;
160
161             std::cout << " Act: " << f_act->to_string() << std::endl;
162             while (it_exp != m_exp_queue.end())
163             {
164                 f_exp = *it_exp;
165                 try
166                 {
167                     std::cout << "  Exp: " << f_exp->to_string() << std::endl;
168
169                     if (typeid(*f_exp) != typeid(*f_act))
170                     {
171                         throw ExpException(1);
172                     }
173
174                     if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd))
175                     {
176                         rc = handle_derived<interface_cmds::af_packet_create_cmd>(f_exp, f_act);
177                     }
178                     else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd))
179                     {
180                         rc = handle_derived<interface_cmds::loopback_create_cmd>(f_exp, f_act);
181                     }
182                     else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd))
183                     {
184                         rc = handle_derived<interface_cmds::vhost_create_cmd>(f_exp, f_act);
185                     }
186                     else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd))
187                     {
188                        rc = handle_derived<bond_interface_cmds::create_cmd>(f_exp, f_act);
189                     }
190                     else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd))
191                     {
192                         rc = handle_derived<interface_cmds::loopback_delete_cmd>(f_exp, f_act);
193                     }
194                     else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd))
195                     {
196                         rc = handle_derived<interface_cmds::af_packet_delete_cmd>(f_exp, f_act);
197                     }
198                     else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd))
199                     {
200                        rc = handle_derived<interface_cmds::vhost_delete_cmd>(f_exp, f_act);
201                     }
202                     else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd))
203                     {
204                        rc = handle_derived<bond_interface_cmds::delete_cmd>(f_exp, f_act);
205                     }
206                     else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd))
207                     {
208                         rc = handle_derived<interface_cmds::state_change_cmd>(f_exp, f_act);
209                     }
210                     else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd))
211                     {
212                         rc = handle_derived<interface_cmds::set_table_cmd>(f_exp, f_act);
213                     }
214                     else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd))
215                     {
216                         rc = handle_derived<interface_cmds::set_mac_cmd>(f_exp, f_act);
217                     }
218                     else if (typeid(*f_exp) == typeid(interface_cmds::set_tag))
219                     {
220                         rc = handle_derived<interface_cmds::set_tag>(f_exp, f_act);
221                     }
222                     else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd))
223                     {
224                        rc = handle_derived<bond_group_binding_cmds::bind_cmd>(f_exp, f_act);
225                     }
226                     else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd))
227                     {
228                        rc = handle_derived<bond_group_binding_cmds::unbind_cmd>(f_exp, f_act);
229                     }
230                     else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd))
231                     {
232                         rc = handle_derived<route_domain_cmds::create_cmd>(f_exp, f_act);
233                     }
234                     else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd))
235                     {
236                         rc = handle_derived<route_domain_cmds::delete_cmd>(f_exp, f_act);
237                     }
238                     else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd))
239                     {
240                         rc = handle_derived<route::ip_route_cmds::update_cmd>(f_exp, f_act);
241                     }
242                     else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd))
243                     {
244                         rc = handle_derived<route::ip_route_cmds::delete_cmd>(f_exp, f_act);
245                     }
246                     else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd))
247                     {
248                         rc = handle_derived<neighbour_cmds::create_cmd>(f_exp, f_act);
249                     }
250                     else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd))
251                     {
252                         rc = handle_derived<neighbour_cmds::delete_cmd>(f_exp, f_act);
253                     }
254                     else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd))
255                     {
256                         rc = handle_derived<l3_binding_cmds::bind_cmd>(f_exp, f_act);
257                     }
258                     else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd))
259                     {
260                         rc = handle_derived<l3_binding_cmds::unbind_cmd>(f_exp, f_act);
261                     }
262                     else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd))
263                     {
264                         rc = handle_derived<bridge_domain_cmds::create_cmd>(f_exp, f_act);
265                     }
266                     else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd))
267                     {
268                         rc = handle_derived<bridge_domain_cmds::delete_cmd>(f_exp, f_act);
269                     }
270                     else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd))
271                     {
272                         rc = handle_derived<bridge_domain_entry_cmds::create_cmd>(f_exp, f_act);
273                     }
274                     else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd))
275                     {
276                         rc = handle_derived<bridge_domain_entry_cmds::delete_cmd>(f_exp, f_act);
277                     }
278                     else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd))
279                     {
280                         rc = handle_derived<bridge_domain_arp_entry_cmds::create_cmd>(f_exp, f_act);
281                     }
282                     else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd))
283                     {
284                         rc = handle_derived<bridge_domain_arp_entry_cmds::delete_cmd>(f_exp, f_act);
285                     }
286                     else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd))
287                     {
288                         rc = handle_derived<l2_binding_cmds::bind_cmd>(f_exp, f_act);
289                     }
290                     else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd))
291                     {
292                         rc = handle_derived<l2_binding_cmds::unbind_cmd>(f_exp, f_act);
293                     }
294                     else if (typeid(*f_exp) == typeid(l2_binding_cmds::set_vtr_op_cmd))
295                     {
296                         rc = handle_derived<l2_binding_cmds::set_vtr_op_cmd>(f_exp, f_act);
297                     }
298                     else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd))
299                     {
300                         rc = handle_derived<l2_xconnect_cmds::bind_cmd>(f_exp, f_act);
301                     }
302                     else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd))
303                     {
304                         rc = handle_derived<l2_xconnect_cmds::unbind_cmd>(f_exp, f_act);
305                     }
306                     else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd))
307                     {
308                         rc = handle_derived<vxlan_tunnel_cmds::create_cmd>(f_exp, f_act);
309                     }
310                     else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd))
311                     {
312                         rc = handle_derived<vxlan_tunnel_cmds::delete_cmd>(f_exp, f_act);
313                     }
314                     else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd))
315                     {
316                         rc = handle_derived<sub_interface_cmds::create_cmd>(f_exp, f_act);
317                     }
318                     else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd))
319                     {
320                         rc = handle_derived<sub_interface_cmds::delete_cmd>(f_exp, f_act);
321                     }
322                     else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd))
323                     {
324                         rc = handle_derived<ACL::acl_ethertype_cmds::bind_cmd>(f_exp, f_act);
325                     }
326                     else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd))
327                     {
328                         rc = handle_derived<ACL::acl_ethertype_cmds::unbind_cmd>(f_exp, f_act);
329                     }
330                     else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd))
331                     {
332                         rc = handle_derived<ACL::list_cmds::l3_update_cmd>(f_exp, f_act);
333                     }
334                     else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd))
335                     {
336                         rc = handle_derived<ACL::list_cmds::l3_delete_cmd>(f_exp, f_act);
337                     }
338                     else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd))
339                     {
340                         rc = handle_derived<ACL::binding_cmds::l3_bind_cmd>(f_exp, f_act);
341                     }
342                     else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd))
343                     {
344                         rc = handle_derived<ACL::binding_cmds::l3_unbind_cmd>(f_exp, f_act);
345                     }
346                     else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd))
347                     {
348                         rc = handle_derived<ACL::list_cmds::l2_update_cmd>(f_exp, f_act);
349                     }
350                     else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd))
351                     {
352                         rc = handle_derived<ACL::list_cmds::l2_delete_cmd>(f_exp, f_act);
353                     }
354                     else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd))
355                     {
356                         rc = handle_derived<ACL::binding_cmds::l2_bind_cmd>(f_exp, f_act);
357                     }
358                     else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd))
359                     {
360                         rc = handle_derived<ACL::binding_cmds::l2_unbind_cmd>(f_exp, f_act);
361                     }
362                     else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd))
363                     {
364                         rc = handle_derived<arp_proxy_binding_cmds::bind_cmd>(f_exp, f_act);
365                     }
366                     else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd))
367                     {
368                         rc = handle_derived<arp_proxy_binding_cmds::unbind_cmd>(f_exp, f_act);
369                     }
370                     else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd))
371                     {
372                         rc = handle_derived<arp_proxy_config_cmds::config_cmd>(f_exp, f_act);
373                     }
374                     else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd))
375                     {
376                         rc = handle_derived<arp_proxy_config_cmds::unconfig_cmd>(f_exp, f_act);
377                     }
378                     else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd))
379                     {
380                         rc = handle_derived<ip_unnumbered_cmds::config_cmd>(f_exp, f_act);
381                     }
382                     else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd))
383                     {
384                         rc = handle_derived<ip_unnumbered_cmds::unconfig_cmd>(f_exp, f_act);
385                     }
386                     else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd))
387                     {
388                         rc = handle_derived<ip6nd_ra_config::config_cmd>(f_exp, f_act);
389                     }
390                     else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd))
391                     {
392                         rc = handle_derived<ip6nd_ra_config::unconfig_cmd>(f_exp, f_act);
393                     }
394                     else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd))
395                     {
396                         rc = handle_derived<ip6nd_ra_prefix::config_cmd>(f_exp, f_act);
397                     }
398                     else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd))
399                     {
400                         rc = handle_derived<ip6nd_ra_prefix::unconfig_cmd>(f_exp, f_act);
401                     }
402                     else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd))
403                     {
404                         rc = handle_derived<interface_span_cmds::config_cmd>(f_exp, f_act);
405                     }
406                     else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cmd))
407                     {
408                         rc = handle_derived<interface_span_cmds::unconfig_cmd>(f_exp, f_act);
409                     }
410                     else if (typeid(*f_exp) == typeid(nat_static_cmds::create_44_cmd))
411                     {
412                         rc = handle_derived<nat_static_cmds::create_44_cmd>(f_exp, f_act);
413                     }
414                     else if (typeid(*f_exp) == typeid(nat_static_cmds::delete_44_cmd))
415                     {
416                         rc = handle_derived<nat_static_cmds::delete_44_cmd>(f_exp, f_act);
417                     }
418                     else if (typeid(*f_exp) == typeid(nat_binding_cmds::bind_44_input_cmd))
419                     {
420                         rc = handle_derived<nat_binding_cmds::bind_44_input_cmd>(f_exp, f_act);
421                     }
422                     else if (typeid(*f_exp) == typeid(nat_binding_cmds::unbind_44_input_cmd))
423                     {
424                         rc = handle_derived<nat_binding_cmds::unbind_44_input_cmd>(f_exp, f_act);
425                     }
426                     else if (typeid(*f_exp) == typeid(interface_cmds::events_cmd))
427                     {
428                         rc = handle_derived<interface_cmds::events_cmd>(f_exp, f_act);
429                     }
430                     else
431                     {
432                         throw ExpException(2);
433                     }
434
435                     // if we get here then we found the match.
436                     m_exp_queue.erase(it_exp);
437                     m_act_queue.erase(it_act);
438                     delete f_exp;
439                     delete f_act;
440
441                     // return any injected failures to the agent
442                     if (rc_t::OK != rc && rc_t::NOOP != rc)
443                     {
444                         return (rc);
445                     }
446
447                     matched = true;
448                     break;
449                 }
450                 catch (ExpException &e)
451                 {
452                     // The expected and actual do not match
453                     if (m_strict_order)
454                     {
455                         // in strict ordering mode this is fatal, so rethrow
456                         throw e;
457                     }
458                     else
459                     {
460                         // move the iterator onto the next in the expected list and
461                         // check for a match
462                         ++it_exp;
463                     }
464                 }
465             }
466
467             if (!matched)
468                 throw ExpException(3);
469         }
470
471         return (rc);
472     }
473 private:
474
475     template <typename T>
476     rc_t handle_derived(const cmd *f_exp, cmd *f_act)
477     {
478         const T *i_exp;
479         T *i_act;
480
481         i_exp = dynamic_cast<const T*>(f_exp);
482         i_act = dynamic_cast<T*>(f_act);
483         if (!(*i_exp == *i_act))
484         {
485             throw ExpException(4);
486         }
487         // pass the data and return code to the agent
488         i_act->item() = i_exp->item();
489
490         return (i_act->item().rc());
491     }
492
493     // The Q to push the expectations on
494     std::deque<cmd*> m_exp_queue;
495
496     // the queue to push the actual events on
497     std::deque<cmd*> m_act_queue;
498
499     // control whether the expected queue is strictly ordered.
500     bool m_strict_order;
501 };
502
503 class VppInit {
504 public:
505     std::string name;
506     MockCmdQ *f;
507
508     VppInit()
509         : name("vpp-ut"),
510           f(new MockCmdQ())
511     {
512         HW::init(f);
513         OM::init();
514         logger().set(log_level_t::DEBUG);
515     }
516
517     ~VppInit() {
518         delete f;
519     }
520 };
521
522 BOOST_AUTO_TEST_SUITE(vom)
523
524 #define TRY_CHECK_RC(stmt)                    \
525 {                                             \
526     try {                                     \
527         BOOST_CHECK(rc_t::OK == stmt);        \
528     }                                         \
529     catch (ExpException &e)                   \
530     {                                         \
531         BOOST_CHECK(false);                   \
532     }                                         \
533     BOOST_CHECK(vi.f->is_empty());            \
534 }
535
536 #define TRY_CHECK(stmt)                       \
537 {                                             \
538     try {                                     \
539         stmt;                                 \
540     }                                         \
541     catch (ExpException &e)                   \
542     {                                         \
543         BOOST_CHECK(false);                   \
544     }                                         \
545     BOOST_CHECK(vi.f->is_empty());            \
546 }
547
548 #define ADD_EXPECT(stmt)                      \
549     vi.f->expect(new stmt)
550
551 #define STRICT_ORDER_OFF()                        \
552     vi.f->strict_order(false)
553
554 BOOST_AUTO_TEST_CASE(test_interface) {
555     VppInit vi;
556     const std::string go = "GeorgeOrwell";
557     const std::string js = "JohnSteinbeck";
558     rc_t rc = rc_t::OK;
559
560     /*
561      * George creates and deletes the interface
562      */
563     std::string itf1_name = "afpacket1";
564     interface itf1(itf1_name,
565                    interface::type_t::AFPACKET,
566                    interface::admin_state_t::UP);
567
568     /*
569      * set the expectation for a afpacket interface create.
570      *  2 is the interface handle VPP [mock] assigns
571      */
572     HW::item<handle_t> hw_ifh(2, rc_t::OK);
573     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
574
575     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
576     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
577
578     TRY_CHECK_RC(OM::write(go, itf1));
579
580     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
581     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
582     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
583
584     TRY_CHECK(OM::remove(go));
585
586     /*
587      * George creates the interface, then John brings it down.
588      * George's remove is a no-op, sice John also owns the interface
589      */
590     interface itf1b(itf1_name,
591                     interface::type_t::AFPACKET,
592                     interface::admin_state_t::DOWN);
593
594     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
595     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
596     TRY_CHECK_RC(OM::write(go, itf1));
597
598     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
599     TRY_CHECK_RC(OM::write(js, itf1b));
600
601     TRY_CHECK(OM::remove(go));
602
603     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
604     TRY_CHECK(OM::remove(js));
605
606     /*
607      * George adds an interface, then we flush all of Geroge's state
608      */
609     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
610     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
611     TRY_CHECK_RC(OM::write(go, itf1));
612
613     TRY_CHECK(OM::mark(go));
614
615     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
616     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
617     TRY_CHECK(OM::sweep(go));
618
619     /*
620      * George adds an interface. mark stale. update the same interface. sweep
621      * and expect no delete
622      */
623     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
624     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
625     TRY_CHECK_RC(OM::write(go, itf1b));
626
627     TRY_CHECK(OM::mark(go));
628
629     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
630     TRY_CHECK_RC(OM::write(go, itf1));
631
632     TRY_CHECK(OM::sweep(go));
633
634     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
635     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
636     TRY_CHECK(OM::remove(go));
637
638     /*
639      * George adds an insterface, then we mark that state. Add a second interface
640      * an flush the first that is now stale.
641      */
642     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
643     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
644     TRY_CHECK_RC(OM::write(go, itf1));
645
646     TRY_CHECK(OM::mark(go));
647
648     std::string itf2_name = "afpacket2";
649     std::string itf2_tag = "uuid-of-afpacket2-interface";
650     interface itf2(itf2_name,
651                    interface::type_t::AFPACKET,
652                    interface::admin_state_t::UP,
653                    itf2_tag);
654     HW::item<handle_t> hw_ifh2(3, rc_t::OK);
655
656     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
657     ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, itf2_tag));
658     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
659     TRY_CHECK_RC(OM::write(go, itf2));
660
661     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
662     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
663     TRY_CHECK(OM::sweep(go));
664
665     TRY_CHECK(OM::mark(go));
666
667     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
668     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
669     TRY_CHECK(OM::sweep(go));
670
671
672     std::string itf3_name = "/PATH/TO/vhost_user1.sock";
673     std::string itf3_tag = "uuid-of-vhost_user1-interface";
674     interface itf3(itf3_name,
675                    interface::type_t::VHOST,
676                    interface::admin_state_t::UP,
677                    itf3_tag);
678     HW::item<handle_t> hw_ifh3(4, rc_t::OK);
679
680     ADD_EXPECT(interface_cmds::vhost_create_cmd(hw_ifh3, itf3_name, itf3_tag));
681     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
682     TRY_CHECK_RC(OM::write(go, itf3));
683
684     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
685     ADD_EXPECT(interface_cmds::vhost_delete_cmd(hw_ifh3, itf3_name));
686     TRY_CHECK(OM::remove(go));
687 }
688
689 BOOST_AUTO_TEST_CASE(test_bvi) {
690     VppInit vi;
691     const std::string ernest = "ErnestHemmingway";
692     const std::string graham = "GrahamGreene";
693     rc_t rc = rc_t::OK;
694     l3_binding *l3;
695
696     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
697                                                 rc_t::OK);
698     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
699                                                   rc_t::OK);
700
701     /*
702      * Enrest creates a BVI with address 10.10.10.10/24
703      */
704     route::prefix_t pfx_10("10.10.10.10", 24);
705
706     const std::string bvi_name = "bvi1";
707     interface itf(bvi_name,
708                   interface::type_t::BVI,
709                   interface::admin_state_t::UP);
710     HW::item<handle_t> hw_ifh(4, rc_t::OK);
711     HW::item<route::prefix_t> hw_pfx_10(pfx_10, rc_t::OK);
712
713     ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh, bvi_name));
714     ADD_EXPECT(interface_cmds::set_tag(hw_ifh, bvi_name));
715     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
716     TRY_CHECK_RC(OM::write(ernest, itf));
717
718     l3 = new l3_binding(itf, pfx_10);
719     HW::item<bool> hw_l3_bind(true, rc_t::OK);
720     HW::item<bool> hw_l3_unbind(false, rc_t::OK);
721     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
722     TRY_CHECK_RC(OM::write(ernest, *l3));
723
724     // change the MAC address on the BVI
725     interface itf_new_mac(bvi_name,
726                           interface::type_t::BVI,
727                           interface::admin_state_t::UP);
728     l2_address_t l2_addr({0,1,2,3,4,5});
729     HW::item<l2_address_t> hw_mac(l2_addr, rc_t::OK);
730     itf_new_mac.set(l2_addr);
731     ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac, hw_ifh));
732     TRY_CHECK_RC(OM::write(ernest, itf_new_mac));
733
734     // create/write the interface to the OM again but with an unset MAC
735     // this should not generate a MAC address update
736     TRY_CHECK_RC(OM::write(ernest, itf));
737
738     // change the MAC address on the BVI - again
739     interface itf_new_mac2(bvi_name,
740                            interface::type_t::BVI,
741                            interface::admin_state_t::UP);
742     l2_address_t l2_addr2({0,1,2,3,4,6});
743     HW::item<l2_address_t> hw_mac2(l2_addr2, rc_t::OK);
744     itf_new_mac2.set(l2_addr2);
745     ADD_EXPECT(interface_cmds::set_mac_cmd(hw_mac2, hw_ifh));
746     TRY_CHECK_RC(OM::write(ernest, itf_new_mac2));
747
748     delete l3;
749     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
750     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
751     ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh));
752     TRY_CHECK(OM::remove(ernest));
753
754     /*
755      * Graham creates a BVI with address 10.10.10.10/24 in Routing Domain
756      */
757     route_domain rd(1);
758     HW::item<bool> hw_rd4_create(true, rc_t::OK);
759     HW::item<bool> hw_rd4_delete(false, rc_t::OK);
760     HW::item<bool> hw_rd6_create(true, rc_t::OK);
761     HW::item<bool> hw_rd6_delete(false, rc_t::OK);
762     HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
763     HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
764     HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
765     HW::item<route::table_id_t> hw_rd6_unbind(route::DEFAULT_TABLE, rc_t::OK);
766     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
767     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
768     TRY_CHECK_RC(OM::write(graham, rd));
769
770     const std::string bvi2_name = "bvi2";
771     interface *itf2 = new interface(bvi2_name,
772                                     interface::type_t::BVI,
773                                     interface::admin_state_t::UP,
774                                     rd);
775     HW::item<handle_t> hw_ifh2(5, rc_t::OK);
776
777     ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh2, bvi2_name));
778     ADD_EXPECT(interface_cmds::set_tag(hw_ifh2, bvi2_name));
779     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
780     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
781     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
782
783     TRY_CHECK_RC(OM::write(graham, *itf2));
784
785     l3 = new l3_binding(*itf2, pfx_10);
786     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh2.data(), pfx_10));
787     TRY_CHECK_RC(OM::write(graham, *l3));
788
789     delete l3;
790     delete itf2;
791
792     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh2.data(), pfx_10));
793     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
794     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_unbind, l3_proto_t::IPV6, hw_ifh2));
795     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
796     ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh2));
797     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
798     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
799     TRY_CHECK(OM::remove(graham));
800 }
801
802 BOOST_AUTO_TEST_CASE(test_bond) {
803     VppInit vi;
804     const std::string cb = "CarolBerg";
805     rc_t rc = rc_t::OK;
806
807     /*
808      * creates the interfaces
809      */
810     std::string itf1_name = "afpacket1";
811     interface itf1(itf1_name,
812                    interface::type_t::AFPACKET,
813                    interface::admin_state_t::UP);
814
815     HW::item<handle_t> hw_ifh(2, rc_t::OK);
816     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
817
818     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
819     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
820
821     TRY_CHECK_RC(OM::write(cb, itf1));
822
823     std::string itf2_name = "afpacket2";
824     interface itf2(itf2_name,
825                    interface::type_t::AFPACKET,
826                    interface::admin_state_t::UP);
827
828
829     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
830     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
831     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
832
833     TRY_CHECK_RC(OM::write(cb, itf2));
834
835     std::string bond_name = "bond";
836     bond_interface bond_itf(bond_name, interface::admin_state_t::UP,
837                                  bond_interface::mode_t::LACP);
838
839     HW::item<handle_t> hw_ifh3(6, rc_t::OK);
840     ADD_EXPECT(bond_interface_cmds::create_cmd(hw_ifh3, bond_name,
841       bond_interface::mode_t::LACP, bond_interface::lb_t::L2, l2_address_t::ZERO));
842     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
843
844     TRY_CHECK_RC(OM::write(cb, bond_itf));
845
846     bond_member *bm1 = new bond_member(itf1, bond_member::mode_t::ACTIVE,
847                                          bond_member::rate_t::SLOW);
848     bond_member *bm2 = new bond_member(itf2, bond_member::mode_t::ACTIVE,
849                                          bond_member::rate_t::SLOW);
850     bond_group_binding *bgb = new bond_group_binding(bond_itf, {*bm1, *bm2});
851
852     HW::item<bool> bond_hw_bind(true, rc_t::OK);
853     ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm1));
854     ADD_EXPECT(bond_group_binding_cmds::bind_cmd(bond_hw_bind, hw_ifh3.data(), *bm2));
855
856     TRY_CHECK_RC(OM::write(cb, *bgb));
857
858     delete bgb;
859     delete bm2;
860     delete bm1;
861
862     STRICT_ORDER_OFF();
863     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
864     ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh.data()));
865     ADD_EXPECT(bond_group_binding_cmds::unbind_cmd(bond_hw_bind, hw_ifh2.data()));
866     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
867     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
868     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
869     ADD_EXPECT(bond_interface_cmds::delete_cmd(hw_ifh3));
870     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
871     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
872
873     TRY_CHECK(OM::remove(cb));
874 }
875
876 BOOST_AUTO_TEST_CASE(test_bridge) {
877     VppInit vi;
878     const std::string franz = "FranzKafka";
879     const std::string dante = "Dante";
880     const std::string jkr = "jkrowling";
881     rc_t rc = rc_t::OK;
882
883     /*
884      * Franz creates an interface, Bridge-domain, then binds the two
885      */
886
887     // interface create
888     std::string itf1_name = "afpacket1";
889     interface itf1(itf1_name,
890                    interface::type_t::AFPACKET,
891                    interface::admin_state_t::UP);
892
893     HW::item<handle_t> hw_ifh(3, rc_t::OK);
894     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
895                                                 rc_t::OK);
896     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
897     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
898
899     TRY_CHECK_RC(OM::write(franz, itf1));
900
901     // bridge-domain create
902     bridge_domain bd1(33);
903
904     HW::item<uint32_t> hw_bd(33, rc_t::OK);
905     ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
906                                               bridge_domain::learning_mode_t::ON,
907                                               bridge_domain::arp_term_mode_t::ON,
908                                               bridge_domain::flood_mode_t::ON,
909                                               bridge_domain::mac_age_mode_t::OFF));
910
911     TRY_CHECK_RC(OM::write(franz, bd1));
912
913     // L2-interface create and bind
914     // this needs to be delete'd before the flush below, since it too maintains
915     // references to the BD and Interface
916     l2_binding *l2itf = new l2_binding(itf1, bd1);
917     HW::item<bool> hw_l2_bind(true, rc_t::OK);
918
919     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
920     TRY_CHECK_RC(OM::write(franz, *l2itf));
921
922     /*
923      * Dante adds an interface to the same BD
924      */
925     std::string itf2_name = "afpacket2";
926     interface itf2(itf2_name,
927                    interface::type_t::AFPACKET,
928                    interface::admin_state_t::UP);
929
930     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
931     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
932     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
933     TRY_CHECK_RC(OM::write(dante, itf2));
934
935     // BD add is a no-op since it exists
936     TRY_CHECK_RC(OM::write(dante, bd1));
937
938     l2_binding *l2itf2 = new l2_binding(itf2, bd1);
939     HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
940     l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
941
942     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
943     ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
944     TRY_CHECK_RC(OM::write(dante, *l2itf2));
945
946     // Add some static entries to the bridge-domain
947     HW::item<bool> hw_be1(true, rc_t::OK);
948     mac_address_t mac1({0,1,2,3,4,5});
949     bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
950     ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
951                                                     false));
952     TRY_CHECK_RC(OM::write(dante, *be1));
953
954     // Add some entries to the bridge-domain ARP termination table
955     HW::item<bool> hw_bea1(true, rc_t::OK);
956     boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
957
958     bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
959     ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
960     TRY_CHECK_RC(OM::write(dante, *bea1));
961
962     // flush Franz's state
963     delete l2itf;
964     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
965                                                   rc_t::OK);
966     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh.data(), hw_bd.data(), false));
967     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
968     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
969     TRY_CHECK(OM::remove(franz));
970
971     // flush Dante's state - the order the interface and BD are deleted
972     // is an uncontrollable artifact of the C++ object destruction.
973     delete l2itf2;
974     delete be1;
975     delete bea1;
976     STRICT_ORDER_OFF();
977     ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
978     ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
979     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh2.data(), hw_bd.data(), false));
980
981     ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
982     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
983     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
984     TRY_CHECK(OM::remove(dante));
985
986     // test the BVI entry in l2fib
987     bridge_domain bd2(99);
988
989     HW::item<uint32_t> hw_bd2(99, rc_t::OK);
990     ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
991                                               bridge_domain::learning_mode_t::ON,
992                                               bridge_domain::arp_term_mode_t::ON,
993                                               bridge_domain::flood_mode_t::ON,
994                                               bridge_domain::mac_age_mode_t::OFF));
995
996     TRY_CHECK_RC(OM::write(jkr, bd2));
997
998     std::string itf3_name = "bvi";
999     interface itf3(itf3_name,
1000                    interface::type_t::BVI,
1001                    interface::admin_state_t::UP);
1002
1003     HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1004     ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1005     ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1006     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1007     TRY_CHECK_RC(OM::write(jkr, itf3));
1008
1009     l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1010     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1011     TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1012
1013     HW::item<bool> hw_be2(true, rc_t::OK);
1014     mac_address_t mac2({0,1,2,3,4,5});
1015     bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1016     ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1017     TRY_CHECK_RC(OM::write(jkr, *be2));
1018
1019     delete l2itf3;
1020     delete be2;
1021     STRICT_ORDER_OFF();
1022     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_ifh3.data(), hw_bd2.data(), true));
1023     ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1024     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1025     ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1026     ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1027     TRY_CHECK(OM::remove(jkr));
1028 }
1029
1030 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1031     VppInit vi;
1032     const std::string nicholas = "NicholasAbercrombie";
1033     rc_t rc = rc_t::OK;
1034
1035     /*
1036      * Interface 1
1037      */
1038     std::string itf1_name = "host1";
1039     interface itf1(itf1_name,
1040                    interface::type_t::AFPACKET,
1041                    interface::admin_state_t::UP);
1042     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1043     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1044     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1045     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1046     TRY_CHECK_RC(OM::write(nicholas, itf1));
1047
1048     /*
1049      * Interface 2
1050      */
1051     std::string itf2_name = "host2";
1052     interface itf2(itf2_name,
1053                    interface::type_t::AFPACKET,
1054                    interface::admin_state_t::UP);
1055
1056     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1057     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1058     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1059     TRY_CHECK_RC(OM::write(nicholas, itf2));
1060
1061     l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1062     HW::item<bool> xconnect_east(true, rc_t::OK);
1063     HW::item<bool> xconnect_west(true, rc_t::OK);
1064     HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1065     HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1066     ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1067     ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1068     TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1069
1070     delete l2_xconn;
1071
1072     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1073     STRICT_ORDER_OFF();
1074     ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1075     ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1076     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1077     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1078     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1079     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1080
1081     TRY_CHECK(OM::remove(nicholas));
1082 }
1083
1084 BOOST_AUTO_TEST_CASE(test_vxlan) {
1085     VppInit vi;
1086     const std::string franz = "FranzKafka";
1087     rc_t rc = rc_t::OK;
1088
1089     /*
1090      * Franz creates an interface, Bridge-domain, then binds the two
1091      */
1092
1093     // VXLAN create
1094     vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1095                                 boost::asio::ip::address::from_string("10.10.10.11"),
1096                                 322);
1097
1098     vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1099
1100     HW::item<handle_t> hw_vxt(3, rc_t::OK);
1101     ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
1102
1103     TRY_CHECK_RC(OM::write(franz, vxt));
1104
1105     // bridge-domain create
1106     bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1107                       bridge_domain::arp_term_mode_t::OFF,
1108                       bridge_domain::flood_mode_t::OFF,
1109                       bridge_domain::mac_age_mode_t::ON);
1110
1111     HW::item<uint32_t> hw_bd(33, rc_t::OK);
1112     ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1113                                               bridge_domain::learning_mode_t::OFF,
1114                                               bridge_domain::arp_term_mode_t::OFF,
1115                                               bridge_domain::flood_mode_t::OFF,
1116                                               bridge_domain::mac_age_mode_t::ON));
1117
1118     TRY_CHECK_RC(OM::write(franz, bd1));
1119
1120     // L2-interface create and bind
1121     // this needs to be delete'd before the flush below, since it too maintains
1122     // references to the BD and Interface
1123     l2_binding *l2itf = new l2_binding(vxt, bd1);
1124     HW::item<bool> hw_l2_bind(true, rc_t::OK);
1125
1126     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1127     TRY_CHECK_RC(OM::write(franz, *l2itf));
1128
1129     // flush Franz's state
1130     delete l2itf;
1131     HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1132     STRICT_ORDER_OFF();
1133     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind, hw_vxt.data(), hw_bd.data(), false));
1134     ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1135     ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1136     TRY_CHECK(OM::remove(franz));
1137 }
1138
1139 BOOST_AUTO_TEST_CASE(test_vlan) {
1140     VppInit vi;
1141     const std::string noam = "NoamChomsky";
1142     rc_t rc = rc_t::OK;
1143
1144     std::string itf1_name = "host1";
1145     interface itf1(itf1_name,
1146                    interface::type_t::AFPACKET,
1147                    interface::admin_state_t::UP);
1148
1149     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1150     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1151
1152     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1153     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1154
1155     TRY_CHECK_RC(OM::write(noam, itf1));
1156
1157     sub_interface *vl33 = new sub_interface(itf1,
1158                                             interface::admin_state_t::UP,
1159                                             33);
1160
1161     HW::item<handle_t> hw_vl33(3, rc_t::OK);
1162     ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1163     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1164
1165     TRY_CHECK_RC(OM::write(noam, *vl33));
1166
1167     delete vl33;
1168     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1169     HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1170     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1171     ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1172     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1173     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1174
1175     TRY_CHECK(OM::remove(noam));
1176 }
1177
1178 BOOST_AUTO_TEST_CASE(test_acl) {
1179     VppInit vi;
1180     const std::string fyodor = "FyodorDostoyevsky";
1181     const std::string leo = "LeoTolstoy";
1182     rc_t rc = rc_t::OK;
1183
1184     /*
1185      * Fyodor adds an ACL in the input direction
1186      */
1187     std::string itf1_name = "host1";
1188     interface itf1(itf1_name,
1189                    interface::type_t::AFPACKET,
1190                    interface::admin_state_t::UP);
1191     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1192     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1193     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1194     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1195     TRY_CHECK_RC(OM::write(fyodor, itf1));
1196
1197     ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1198     ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1199     ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1200     ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1201     ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1202     HW::item<bool> ae_binding(true, rc_t::OK);
1203     ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1204     TRY_CHECK_RC(OM::write(fyodor, *a_e));
1205
1206     route::prefix_t src("10.10.10.10", 32);
1207     ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1208     ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1209
1210     std::string acl_name = "acl1";
1211     ACL::l3_list acl1(acl_name);
1212     acl1.insert(r2);
1213     acl1.insert(r1);
1214     ACL::l3_list::rules_t rules = {r1, r2};
1215
1216     HW::item<handle_t> hw_acl(2, rc_t::OK);
1217     ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1218     TRY_CHECK_RC(OM::write(fyodor, acl1));
1219
1220     ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1221     ACL::l3_list acl2(acl_name);
1222     acl2.insert(r3);
1223     ACL::l3_list::rules_t rules2 = {r3};
1224     ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1225     TRY_CHECK_RC(OM::write(fyodor, acl2));
1226
1227     ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1228     HW::item<bool> hw_binding(true, rc_t::OK);
1229     ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1230                                          hw_ifh.data(), hw_acl.data()));
1231     TRY_CHECK_RC(OM::write(fyodor, *l3b));
1232
1233     /**
1234      * Leo adds an L2 ACL in the output direction
1235      */
1236     TRY_CHECK_RC(OM::write(leo, itf1));
1237
1238     std::string l2_acl_name = "l2_acl1";
1239     mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1240     mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1241     ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1242     ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1243
1244     ACL::l2_list l2_acl(l2_acl_name);
1245     l2_acl.insert(l2_r2);
1246     l2_acl.insert(l2_r1);
1247
1248     ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1249
1250     HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1251     ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1252     TRY_CHECK_RC(OM::write(leo, l2_acl));
1253
1254     ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1255     HW::item<bool> l2_hw_binding(true, rc_t::OK);
1256     ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1257                                        hw_ifh.data(), l2_hw_acl.data()));
1258     TRY_CHECK_RC(OM::write(leo, *l2b));
1259
1260     delete l2b;
1261     ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1262                                                 hw_ifh.data(), l2_hw_acl.data()));
1263     ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1264     TRY_CHECK(OM::remove(leo));
1265
1266     delete l3b;
1267     delete a_e;
1268     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1269                                                   rc_t::OK);
1270     STRICT_ORDER_OFF();
1271     ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1272                                          hw_ifh.data(), hw_acl.data()));
1273     ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1274     ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1275     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1276     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1277
1278     TRY_CHECK(OM::remove(fyodor));
1279 }
1280
1281 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1282     VppInit vi;
1283     const std::string kurt = "KurtVonnegut";
1284     rc_t rc = rc_t::OK;
1285
1286     asio::ip::address_v4 low  = asio::ip::address_v4::from_string("10.0.0.0");
1287     asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1288
1289     arp_proxy_config ap(low, high);
1290     HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1291     ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1292     TRY_CHECK_RC(OM::write(kurt, ap));
1293
1294     std::string itf3_name = "host3";
1295     interface itf3(itf3_name,
1296                    interface::type_t::AFPACKET,
1297                    interface::admin_state_t::UP);
1298     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1299     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1300     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1301     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1302     TRY_CHECK_RC(OM::write(kurt, itf3));
1303
1304     arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1305     HW::item<bool> hw_binding(true, rc_t::OK);
1306     ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1307     TRY_CHECK_RC(OM::write(kurt, *apb));
1308
1309     delete apb;
1310
1311     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1312                                                   rc_t::OK);
1313     STRICT_ORDER_OFF();
1314     ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1315     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1316     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1317     ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1318
1319     TRY_CHECK(OM::remove(kurt));
1320 }
1321
1322 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1323     VppInit vi;
1324     const std::string eric = "EricAmbler";
1325     rc_t rc = rc_t::OK;
1326
1327     /*
1328      * Interface 1 has the L3 address
1329      */
1330     std::string itf1_name = "host1";
1331     interface itf1(itf1_name,
1332                    interface::type_t::AFPACKET,
1333                    interface::admin_state_t::UP);
1334     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1335     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1336     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1337     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1338     TRY_CHECK_RC(OM::write(eric, itf1));
1339
1340     route::prefix_t pfx_10("10.10.10.10", 24);
1341     l3_binding *l3 = new l3_binding(itf1, pfx_10);
1342     HW::item<bool> hw_l3_bind(true, rc_t::OK);
1343     HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1344     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1345     TRY_CHECK_RC(OM::write(eric, *l3));
1346
1347     /*
1348      * Interface 2 is unnumbered
1349      */
1350     std::string itf2_name = "host2";
1351     interface itf2(itf2_name,
1352                    interface::type_t::AFPACKET,
1353                    interface::admin_state_t::UP);
1354
1355     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1356     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1357     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1358     TRY_CHECK_RC(OM::write(eric, itf2));
1359
1360     ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1361     HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1362     HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1363     ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1364     TRY_CHECK_RC(OM::write(eric, *ipun));
1365
1366     delete l3;
1367     delete ipun;
1368
1369     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1370     STRICT_ORDER_OFF();
1371     ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1372     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1373     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1374     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1375     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1376     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1377
1378     TRY_CHECK(OM::remove(eric));
1379 }
1380
1381 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1382     VppInit vi;
1383     const std::string paulo = "PauloCoelho";
1384     rc_t rc = rc_t::OK;
1385
1386     /*
1387      * ra config
1388      */
1389     std::string itf_name = "host_ip6nd";
1390     interface itf(itf_name,
1391                    interface::type_t::AFPACKET,
1392                    interface::admin_state_t::UP);
1393     HW::item<handle_t> hw_ifh(3, rc_t::OK);
1394     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1395     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1396     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1397     TRY_CHECK_RC(OM::write(paulo, itf));
1398
1399     route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1400     l3_binding *l3 = new l3_binding(itf, pfx_10);
1401     HW::item<bool> hw_l3_bind(true, rc_t::OK);
1402     HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1403     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1404     TRY_CHECK_RC(OM::write(paulo, *l3));
1405
1406     ra_config ra(0, 1, 0, 4);
1407     ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1408     HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1409     HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1410     ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1411     TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1412
1413     /*
1414      * ra prefix
1415      */
1416     ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1417     ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1418     HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1419     HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1420     ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1421     TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1422
1423     delete ip6pfx;
1424
1425     ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1426
1427     delete ip6ra;
1428     delete l3;
1429
1430     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1431
1432     STRICT_ORDER_OFF();
1433     ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1434     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1435     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1436     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1437
1438     TRY_CHECK(OM::remove(paulo));
1439 }
1440
1441 BOOST_AUTO_TEST_CASE(test_interface_span) {
1442     VppInit vi;
1443     const std::string elif = "ElifShafak";
1444     rc_t rc = rc_t::OK;
1445
1446     /*
1447      * Interface 1 to be mirrored
1448      */
1449     std::string itf1_name = "port-from";
1450     interface itf1(itf1_name,
1451                    interface::type_t::AFPACKET,
1452                    interface::admin_state_t::UP);
1453     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1454     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1455     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1456     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1457     TRY_CHECK_RC(OM::write(elif, itf1));
1458
1459     /*
1460      * Interface 2 where traffic is mirrored
1461      */
1462     std::string itf2_name = "port-to";
1463     interface itf2(itf2_name,
1464                    interface::type_t::AFPACKET,
1465                    interface::admin_state_t::UP);
1466
1467     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1468     HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1469
1470     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1471     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1472     TRY_CHECK_RC(OM::write(elif, itf2));
1473
1474     interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1475     HW::item<bool> hw_is_cfg(true, rc_t::OK);
1476     HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1477     ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1478     TRY_CHECK_RC(OM::write(elif, *itf_span));
1479
1480     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1481     HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1482
1483     delete itf_span;
1484     STRICT_ORDER_OFF();
1485     ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1486     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1487     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1488     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1489     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1490
1491     TRY_CHECK(OM::remove(elif));
1492 }
1493
1494 BOOST_AUTO_TEST_CASE(test_routing) {
1495     VppInit vi;
1496     const std::string ian = "IanFleming";
1497     rc_t rc = rc_t::OK;
1498
1499     /*
1500      * non-default route domain
1501      */
1502     route_domain rd4(1);
1503     HW::item<bool> hw_rd4_create(true, rc_t::OK);
1504     HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1505     HW::item<bool> hw_rd6_create(true, rc_t::OK);
1506     HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1507     HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1508     HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1509     HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1510     HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1511     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1512     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1513     TRY_CHECK_RC(OM::write(ian, rd4));
1514
1515     /*
1516      * a couple of interfaces
1517      */
1518     std::string itf1_name = "af1";
1519     interface itf1(itf1_name,
1520                    interface::type_t::AFPACKET,
1521                    interface::admin_state_t::UP);
1522     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1523     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1524     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1525     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1526     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1527     TRY_CHECK_RC(OM::write(ian, itf1));
1528
1529     std::string itf2_name = "af2";
1530     interface *itf2 = new interface(itf2_name,
1531                                     interface::type_t::AFPACKET,
1532                                     interface::admin_state_t::UP,
1533                                     rd4);
1534
1535     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1536     HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1537     HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1538     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1539     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1540     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1541     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1542     TRY_CHECK_RC(OM::write(ian, *itf2));
1543
1544     /*
1545      * prefix on each interface
1546      */
1547     route::prefix_t pfx_10("10.10.10.10", 24);
1548     l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1549     HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1550     HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1551     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1552     TRY_CHECK_RC(OM::write(ian, *l3_10));
1553     route::prefix_t pfx_11("11.11.11.11", 24);
1554     l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1555     HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1556     HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1557     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1558     TRY_CHECK_RC(OM::write(ian, *l3_11));
1559
1560     /*
1561      * A route via interface 1 in the default table
1562      */
1563     route::prefix_t pfx_5("5.5.5.5", 32);
1564     boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1565     route::path *path_10 = new route::path(nh_10, itf1);
1566     route::ip_route *route_5 = new route::ip_route(pfx_5);
1567     route_5->add(*path_10);
1568     HW::item<bool> hw_route_5(true, rc_t::OK);
1569     ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
1570     TRY_CHECK_RC(OM::write(ian, *route_5));
1571
1572     /*
1573      * A route via interface 2 in the non-default table
1574      */
1575     boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1576     route::path *path_11 = new route::path(nh_11, *itf2);
1577     route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1578     route_5_2->add(*path_11);
1579     HW::item<bool> hw_route_5_2(true, rc_t::OK);
1580     ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
1581     TRY_CHECK_RC(OM::write(ian, *route_5_2));
1582
1583     /*
1584      * An ARP entry for the neighbour on itf1
1585      */
1586     HW::item<bool> hw_neighbour(true, rc_t::OK);
1587     mac_address_t mac_n({0,1,2,4,5,6});
1588     neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1589     ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1590     TRY_CHECK_RC(OM::write(ian, *ne));
1591
1592     /*
1593      * A DVR route
1594      */
1595     route::prefix_t pfx_6("6.6.6.6", 32);
1596     route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1597     route::ip_route *route_dvr = new route::ip_route(pfx_6);
1598     route_dvr->add(*path_l2);
1599     HW::item<bool> hw_route_dvr(true, rc_t::OK);
1600     ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
1601     TRY_CHECK_RC(OM::write(ian, *route_dvr));
1602
1603     STRICT_ORDER_OFF();
1604     // delete the stack objects that hold references to others
1605     // so the OM::remove is the call that removes the last reference
1606     delete l3_11;
1607     delete l3_10;
1608     delete itf2;
1609     delete route_5;
1610     delete path_10;
1611     delete route_5_2;
1612     delete path_11;
1613     delete route_dvr;
1614     delete path_l2;
1615     delete ne;
1616     ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1617     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1618     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1619     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1620     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1621     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1622     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1623     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1624     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1625     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1626     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1627     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1628     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1629     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1630
1631     TRY_CHECK(OM::remove(ian));
1632 }
1633
1634 BOOST_AUTO_TEST_CASE(test_nat) {
1635     VppInit vi;
1636     const std::string gs = "GeorgeSimenon";
1637     rc_t rc = rc_t::OK;
1638
1639     /*
1640      * Inside Interface
1641      */
1642     std::string itf_in_name = "inside";
1643     interface itf_in(itf_in_name,
1644                      interface::type_t::AFPACKET,
1645                      interface::admin_state_t::UP);
1646     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1647     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1648     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1649     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1650     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1651     TRY_CHECK_RC(OM::write(gs, itf_in));
1652
1653     /*
1654      * outside
1655      */
1656     std::string itf_out_name = "port-to";
1657     interface itf_out(itf_out_name,
1658                    interface::type_t::AFPACKET,
1659                    interface::admin_state_t::UP);
1660
1661     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1662     HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1663     HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1664
1665     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1666     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1667     TRY_CHECK_RC(OM::write(gs, itf_out));
1668
1669     /*
1670      * A NAT static mapping
1671      */
1672     boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1673     boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1674
1675     nat_static ns(in_addr, out_addr);
1676     HW::item<bool> hw_ns(true, rc_t::OK);
1677
1678     ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1679     TRY_CHECK_RC(OM::write(gs, ns));
1680
1681     /*
1682      * bind nat inside and out
1683      */
1684     nat_binding *nb_in = new nat_binding(itf_in,
1685                                          direction_t::INPUT,
1686                                          l3_proto_t::IPV4,
1687                                          nat_binding::zone_t::INSIDE);
1688     HW::item<bool> hw_nb_in(true, rc_t::OK);
1689
1690     ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1691                                                    hw_ifh.data().value(),
1692                                                    nat_binding::zone_t::INSIDE));
1693     TRY_CHECK_RC(OM::write(gs, *nb_in));
1694
1695     nat_binding *nb_out = new nat_binding(itf_out,
1696                                           direction_t::INPUT,
1697                                           l3_proto_t::IPV4,
1698                                           nat_binding::zone_t::OUTSIDE);
1699     HW::item<bool> hw_nb_out(true, rc_t::OK);
1700
1701     ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1702                                                    hw_ifh2.data().value(),
1703                                                    nat_binding::zone_t::OUTSIDE));
1704     TRY_CHECK_RC(OM::write(gs, *nb_out));
1705
1706
1707     STRICT_ORDER_OFF();
1708     delete nb_in;
1709     delete nb_out;
1710     ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1711                                                      hw_ifh.data().value(),
1712                                                      nat_binding::zone_t::INSIDE));
1713     ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1714                                                      hw_ifh2.data().value(),
1715                                                      nat_binding::zone_t::OUTSIDE));
1716     ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1717     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1718     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1719     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1720     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1721
1722     TRY_CHECK(OM::remove(gs));
1723 }
1724
1725 BOOST_AUTO_TEST_CASE(test_interface_events) {
1726     VppInit vi;
1727     MockListener ml;
1728
1729     HW::item<bool> hw_want(true, rc_t::OK);
1730
1731     ADD_EXPECT(interface_cmds::events_cmd(ml));
1732     cmd* itf = new interface_cmds::events_cmd(ml);
1733
1734     HW::enqueue(itf);
1735     HW::write();
1736 }
1737
1738 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1739     VppInit vi;
1740     const std::string rene = "ReneGoscinny";
1741     rc_t rc = rc_t::OK;
1742
1743     /*
1744      * Create an interface with two IP addresses
1745      */
1746     std::string itf1_name = "host1";
1747     interface itf1(itf1_name,
1748                    interface::type_t::AFPACKET,
1749                    interface::admin_state_t::UP);
1750     HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1751     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1752     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1753     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1754     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1755     TRY_CHECK_RC(OM::write(rene, itf1));
1756
1757     route::prefix_t pfx_10("10.10.10.10", 24);
1758     l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1759     HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1760     HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1761     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1762     TRY_CHECK_RC(OM::write(rene, *l3_1));
1763
1764     route::prefix_t pfx_11("10.10.11.11", 24);
1765     l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1766     HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1767     HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1768     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1769     TRY_CHECK_RC(OM::write(rene, *l3_2));
1770
1771     route_domain rd(1);
1772     HW::item<bool> hw_rd_create(true, rc_t::OK);
1773     HW::item<bool> hw_rd_delete(false, rc_t::OK);
1774     HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1775     HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1776     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1777     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1778     TRY_CHECK_RC(OM::write(rene, rd));
1779
1780     /*
1781      * update the interface to change to a new route-domain
1782      * expect that the l3-bindings are removed and readded.
1783      */
1784     interface *itf2 = new interface(itf1_name,
1785                                     interface::type_t::AFPACKET,
1786                                     interface::admin_state_t::UP,
1787                                     rd);
1788     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1789     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1790     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1791     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1792     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1793     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1794     TRY_CHECK_RC(OM::write(rene, *itf2));
1795
1796     /*
1797      * mve the interface back to the default route-domain
1798      */
1799     interface itf3(itf1_name,
1800                    interface::type_t::AFPACKET,
1801                    interface::admin_state_t::UP);
1802     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1803     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1804     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1805     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1806     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1807     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1808     TRY_CHECK_RC(OM::write(rene, itf3));
1809
1810     delete l3_1;
1811     delete l3_2;
1812     delete itf2;
1813
1814     STRICT_ORDER_OFF();
1815     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1816     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1817     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1818     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1819     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1820     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1821
1822     TRY_CHECK(OM::remove(rene));
1823 }
1824
1825 BOOST_AUTO_TEST_CASE(test_prefixes) {
1826     route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1827
1828     BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1829
1830     route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1831
1832     BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1833     BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1834
1835     route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1836     BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1837     BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1838
1839     route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1840
1841     BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1842
1843     route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1844
1845     BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1846     BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1847     BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1848
1849     route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1850
1851     BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1852     BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1853     BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1854
1855     route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1856
1857     BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1858     BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1859     BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1860
1861 }
1862
1863 BOOST_AUTO_TEST_SUITE_END()