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