vom: Fix the l2 port type in bridge domain
[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,
940                                          hw_ifh.data(),
941                                          hw_bd.data(),
942                                          l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
943     TRY_CHECK_RC(OM::write(franz, *l2itf));
944
945     /*
946      * Dante adds an interface to the same BD
947      */
948     std::string itf2_name = "afpacket2";
949     interface itf2(itf2_name,
950                    interface::type_t::AFPACKET,
951                    interface::admin_state_t::UP);
952
953     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
954     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
955     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
956     TRY_CHECK_RC(OM::write(dante, itf2));
957
958     // BD add is a no-op since it exists
959     TRY_CHECK_RC(OM::write(dante, bd1));
960
961     l2_binding *l2itf2 = new l2_binding(itf2, bd1);
962     HW::item<l2_binding::l2_vtr_op_t> hw_set_vtr(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, rc_t::OK);
963     l2itf2->set(l2_binding::l2_vtr_op_t::L2_VTR_POP_1, 68);
964
965     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
966                                          hw_ifh2.data(),
967                                          hw_bd.data(),
968                                          l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
969     ADD_EXPECT(l2_binding_cmds::set_vtr_op_cmd(hw_set_vtr, hw_ifh2.data(), 68));
970     TRY_CHECK_RC(OM::write(dante, *l2itf2));
971
972     // Add some static entries to the bridge-domain
973     HW::item<bool> hw_be1(true, rc_t::OK);
974     mac_address_t mac1({0,1,2,3,4,5});
975     bridge_domain_entry *be1 = new bridge_domain_entry(bd1, mac1, itf2);
976     ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be1, mac1, bd1.id(), hw_ifh2.data(),
977                                                     false));
978     TRY_CHECK_RC(OM::write(dante, *be1));
979
980     // Add some entries to the bridge-domain ARP termination table
981     HW::item<bool> hw_bea1(true, rc_t::OK);
982     boost::asio::ip::address ip1 = boost::asio::ip::address::from_string("10.10.10.10");
983
984     bridge_domain_arp_entry *bea1 = new bridge_domain_arp_entry(bd1, ip1, mac1);
985     ADD_EXPECT(bridge_domain_arp_entry_cmds::create_cmd(hw_be1, bd1.id(), mac1, ip1));
986     TRY_CHECK_RC(OM::write(dante, *bea1));
987
988     // flush Franz's state
989     delete l2itf;
990     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
991                                                   rc_t::OK);
992     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
993                                            hw_ifh.data(),
994                                            hw_bd.data(),
995                                            l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
996     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
997     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
998     TRY_CHECK(OM::remove(franz));
999
1000     // flush Dante's state - the order the interface and BD are deleted
1001     // is an uncontrollable artifact of the C++ object destruction.
1002     delete l2itf2;
1003     delete be1;
1004     delete bea1;
1005     STRICT_ORDER_OFF();
1006     ADD_EXPECT(bridge_domain_arp_entry_cmds::delete_cmd(hw_be1, bd1.id(), mac1, ip1));
1007     ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be1, mac1, bd1.id(), false));
1008     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1009                                            hw_ifh2.data(),
1010                                            hw_bd.data(),
1011                                            l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1012
1013     ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1014     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1015     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1016     TRY_CHECK(OM::remove(dante));
1017
1018     // test the BVI entry in l2fib
1019     bridge_domain bd2(99);
1020
1021     HW::item<uint32_t> hw_bd2(99, rc_t::OK);
1022     ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd2,
1023                                               bridge_domain::learning_mode_t::ON,
1024                                               bridge_domain::arp_term_mode_t::ON,
1025                                               bridge_domain::flood_mode_t::ON,
1026                                               bridge_domain::mac_age_mode_t::OFF));
1027
1028     TRY_CHECK_RC(OM::write(jkr, bd2));
1029
1030     std::string itf3_name = "bvi";
1031     interface itf3(itf3_name,
1032                    interface::type_t::BVI,
1033                    interface::admin_state_t::UP);
1034
1035     HW::item<handle_t> hw_ifh3(5, rc_t::OK);
1036     ADD_EXPECT(interface_cmds::loopback_create_cmd(hw_ifh3, itf3_name));
1037     ADD_EXPECT(interface_cmds::set_tag(hw_ifh3, itf3_name));
1038     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh3));
1039     TRY_CHECK_RC(OM::write(jkr, itf3));
1040
1041     l2_binding *l2itf3 = new l2_binding(itf3, bd2);
1042     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1043                                          hw_ifh3.data(),
1044                                          hw_bd2.data(),
1045                                          l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1046     TRY_CHECK_RC(OM::write(jkr, *l2itf3));
1047
1048     HW::item<bool> hw_be2(true, rc_t::OK);
1049     mac_address_t mac2({0,1,2,3,4,5});
1050     bridge_domain_entry *be2 = new bridge_domain_entry(bd2, mac2, itf3);
1051     ADD_EXPECT(bridge_domain_entry_cmds::create_cmd(hw_be2, mac2, bd2.id(), hw_ifh3.data(), true));
1052     TRY_CHECK_RC(OM::write(jkr, *be2));
1053
1054     delete l2itf3;
1055     delete be2;
1056     STRICT_ORDER_OFF();
1057     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1058                                            hw_ifh3.data(),
1059                                            hw_bd2.data(),
1060                                            l2_binding::l2_port_type_t::L2_PORT_TYPE_BVI));
1061     ADD_EXPECT(bridge_domain_entry_cmds::delete_cmd(hw_be2, mac2, bd2.id(), true));
1062     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh3));
1063     ADD_EXPECT(interface_cmds::loopback_delete_cmd(hw_ifh3));
1064     ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd2));
1065     TRY_CHECK(OM::remove(jkr));
1066 }
1067
1068 BOOST_AUTO_TEST_CASE(test_l2_xconnect) {
1069     VppInit vi;
1070     const std::string nicholas = "NicholasAbercrombie";
1071     rc_t rc = rc_t::OK;
1072
1073     /*
1074      * Interface 1
1075      */
1076     std::string itf1_name = "host1";
1077     interface itf1(itf1_name,
1078                    interface::type_t::AFPACKET,
1079                    interface::admin_state_t::UP);
1080     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1081     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1082     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1083     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1084     TRY_CHECK_RC(OM::write(nicholas, itf1));
1085
1086     /*
1087      * Interface 2
1088      */
1089     std::string itf2_name = "host2";
1090     interface itf2(itf2_name,
1091                    interface::type_t::AFPACKET,
1092                    interface::admin_state_t::UP);
1093
1094     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1095     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1096     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1097     TRY_CHECK_RC(OM::write(nicholas, itf2));
1098
1099     l2_xconnect *l2_xconn = new l2_xconnect(itf1, itf2);
1100     HW::item<bool> xconnect_east(true, rc_t::OK);
1101     HW::item<bool> xconnect_west(true, rc_t::OK);
1102     HW::item<bool> xconnect_east_unbind(false, rc_t::OK);
1103     HW::item<bool> xconnect_west_unbind(false, rc_t::OK);
1104     ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_east, hw_ifh.data(), hw_ifh2.data()));
1105     ADD_EXPECT(l2_xconnect_cmds::bind_cmd(xconnect_west, hw_ifh2.data(), hw_ifh.data()));
1106     TRY_CHECK_RC(OM::write(nicholas, *l2_xconn));
1107
1108     delete l2_xconn;
1109
1110     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1111     STRICT_ORDER_OFF();
1112     ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_east_unbind, hw_ifh.data(), hw_ifh2.data()));
1113     ADD_EXPECT(l2_xconnect_cmds::unbind_cmd(xconnect_west_unbind, hw_ifh2.data(), hw_ifh.data()));
1114     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1115     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1116     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1117     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1118
1119     TRY_CHECK(OM::remove(nicholas));
1120 }
1121
1122 BOOST_AUTO_TEST_CASE(test_vxlan) {
1123     VppInit vi;
1124     const std::string franz = "FranzKafka";
1125     rc_t rc = rc_t::OK;
1126
1127     /*
1128      * Franz creates an interface, Bridge-domain, then binds the two
1129      */
1130
1131     // VXLAN create
1132     vxlan_tunnel::endpoint_t ep(boost::asio::ip::address::from_string("10.10.10.10"),
1133                                 boost::asio::ip::address::from_string("10.10.10.11"),
1134                                 322);
1135
1136     vxlan_tunnel vxt(ep.src, ep.dst, ep.vni);
1137
1138     HW::item<handle_t> hw_vxt(3, rc_t::OK);
1139     ADD_EXPECT(vxlan_tunnel_cmds::create_cmd(hw_vxt, "don't-care", ep));
1140
1141     TRY_CHECK_RC(OM::write(franz, vxt));
1142
1143     // bridge-domain create
1144     bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1145                       bridge_domain::arp_term_mode_t::OFF,
1146                       bridge_domain::flood_mode_t::OFF,
1147                       bridge_domain::mac_age_mode_t::ON);
1148
1149     HW::item<uint32_t> hw_bd(33, rc_t::OK);
1150     ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1151                                               bridge_domain::learning_mode_t::OFF,
1152                                               bridge_domain::arp_term_mode_t::OFF,
1153                                               bridge_domain::flood_mode_t::OFF,
1154                                               bridge_domain::mac_age_mode_t::ON));
1155
1156     TRY_CHECK_RC(OM::write(franz, bd1));
1157
1158     // L2-interface create and bind
1159     // this needs to be delete'd before the flush below, since it too maintains
1160     // references to the BD and Interface
1161     l2_binding *l2itf = new l2_binding(vxt, bd1);
1162     HW::item<bool> hw_l2_bind(true, rc_t::OK);
1163
1164     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_bind,
1165                                          hw_vxt.data(),
1166                                          hw_bd.data(),
1167                                          l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1168     TRY_CHECK_RC(OM::write(franz, *l2itf));
1169
1170     // flush Franz's state
1171     delete l2itf;
1172     HW::item<handle_t> hw_vxtdel(3, rc_t::NOOP);
1173     STRICT_ORDER_OFF();
1174     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_bind,
1175                                            hw_vxt.data(),
1176                                            hw_bd.data(),
1177                                            l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
1178     ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
1179     ADD_EXPECT(vxlan_tunnel_cmds::delete_cmd(hw_vxtdel, ep));
1180     TRY_CHECK(OM::remove(franz));
1181 }
1182
1183 BOOST_AUTO_TEST_CASE(test_vlan) {
1184     VppInit vi;
1185     const std::string noam = "NoamChomsky";
1186     rc_t rc = rc_t::OK;
1187
1188     std::string itf1_name = "host1";
1189     interface itf1(itf1_name,
1190                    interface::type_t::AFPACKET,
1191                    interface::admin_state_t::UP);
1192
1193     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1194     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1195
1196     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1197     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1198
1199     TRY_CHECK_RC(OM::write(noam, itf1));
1200
1201     sub_interface *vl33 = new sub_interface(itf1,
1202                                             interface::admin_state_t::UP,
1203                                             33);
1204
1205     HW::item<handle_t> hw_vl33(3, rc_t::OK);
1206     ADD_EXPECT(sub_interface_cmds::create_cmd(hw_vl33, itf1_name+".33", hw_ifh.data(), 33));
1207     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_vl33));
1208
1209     TRY_CHECK_RC(OM::write(noam, *vl33));
1210
1211     delete vl33;
1212     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1213     HW::item<handle_t> hw_vl33_down(3, rc_t::NOOP);
1214     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_vl33));
1215     ADD_EXPECT(sub_interface_cmds::delete_cmd(hw_vl33_down));
1216     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1217     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1218
1219     TRY_CHECK(OM::remove(noam));
1220 }
1221
1222 BOOST_AUTO_TEST_CASE(test_acl) {
1223     VppInit vi;
1224     const std::string fyodor = "FyodorDostoyevsky";
1225     const std::string leo = "LeoTolstoy";
1226     rc_t rc = rc_t::OK;
1227
1228     /*
1229      * Fyodor adds an ACL in the input direction
1230      */
1231     std::string itf1_name = "host1";
1232     interface itf1(itf1_name,
1233                    interface::type_t::AFPACKET,
1234                    interface::admin_state_t::UP);
1235     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1236     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1237     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1238     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1239     TRY_CHECK_RC(OM::write(fyodor, itf1));
1240
1241     ACL::ethertype_rule_t e1(ethertype_t::ARP, direction_t::INPUT);
1242     ACL::ethertype_rule_t e2(ethertype_t::ARP, direction_t::OUTPUT);
1243     ACL::ethertype_rule_t e3(ethertype_t::IPV4, direction_t::INPUT);
1244     ACL::acl_ethertype::ethertype_rules_t l_e = {e1, e2, e3};
1245     ACL::acl_ethertype *a_e = new ACL::acl_ethertype(itf1, l_e);
1246     HW::item<bool> ae_binding(true, rc_t::OK);
1247     ADD_EXPECT(ACL::acl_ethertype_cmds::bind_cmd(ae_binding, hw_ifh.data(), l_e));
1248     TRY_CHECK_RC(OM::write(fyodor, *a_e));
1249
1250     route::prefix_t src("10.10.10.10", 32);
1251     ACL::l3_rule r1(10, ACL::action_t::PERMIT, src, route::prefix_t::ZERO);
1252     ACL::l3_rule r2(20, ACL::action_t::DENY, route::prefix_t::ZERO, route::prefix_t::ZERO);
1253
1254     std::string acl_name = "acl1";
1255     ACL::l3_list acl1(acl_name);
1256     acl1.insert(r2);
1257     acl1.insert(r1);
1258     ACL::l3_list::rules_t rules = {r1, r2};
1259
1260     HW::item<handle_t> hw_acl(2, rc_t::OK);
1261     ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules));
1262     TRY_CHECK_RC(OM::write(fyodor, acl1));
1263
1264     ACL::l3_rule r3(30, ACL::action_t::PERMIT, route::prefix_t::ZERO, route::prefix_t::ZERO);
1265     ACL::l3_list acl2(acl_name);
1266     acl2.insert(r3);
1267     ACL::l3_list::rules_t rules2 = {r3};
1268     ADD_EXPECT(ACL::list_cmds::l3_update_cmd(hw_acl, acl_name, rules2));
1269     TRY_CHECK_RC(OM::write(fyodor, acl2));
1270
1271     ACL::l3_binding *l3b = new ACL::l3_binding(direction_t::INPUT, itf1, acl1);
1272     HW::item<bool> hw_binding(true, rc_t::OK);
1273     ADD_EXPECT(ACL::binding_cmds::l3_bind_cmd(hw_binding, direction_t::INPUT,
1274                                          hw_ifh.data(), hw_acl.data()));
1275     TRY_CHECK_RC(OM::write(fyodor, *l3b));
1276
1277     /**
1278      * Leo adds an L2 ACL in the output direction
1279      */
1280     TRY_CHECK_RC(OM::write(leo, itf1));
1281
1282     std::string l2_acl_name = "l2_acl1";
1283     mac_address_t mac({0x0, 0x0, 0x1, 0x2, 0x3, 0x4});
1284     mac_address_t mac_mask({0xff, 0xff, 0xff, 0x0, 0x0, 0x0});
1285     ACL::l2_rule l2_r1(10, ACL::action_t::PERMIT, src, mac, mac_mask);
1286     ACL::l2_rule l2_r2(20, ACL::action_t::DENY, src, {}, {});
1287
1288     ACL::l2_list l2_acl(l2_acl_name);
1289     l2_acl.insert(l2_r2);
1290     l2_acl.insert(l2_r1);
1291
1292     ACL::l2_list::rules_t l2_rules = {l2_r1, l2_r2};
1293
1294     HW::item<handle_t> l2_hw_acl(3, rc_t::OK);
1295     ADD_EXPECT(ACL::list_cmds::l2_update_cmd(l2_hw_acl, l2_acl_name, l2_rules));
1296     TRY_CHECK_RC(OM::write(leo, l2_acl));
1297
1298     ACL::l2_binding *l2b = new ACL::l2_binding(direction_t::OUTPUT, itf1, l2_acl);
1299     HW::item<bool> l2_hw_binding(true, rc_t::OK);
1300     ADD_EXPECT(ACL::binding_cmds::l2_bind_cmd(l2_hw_binding, direction_t::OUTPUT,
1301                                        hw_ifh.data(), l2_hw_acl.data()));
1302     TRY_CHECK_RC(OM::write(leo, *l2b));
1303
1304     delete l2b;
1305     ADD_EXPECT(ACL::binding_cmds::l2_unbind_cmd(l2_hw_binding, direction_t::OUTPUT,
1306                                                 hw_ifh.data(), l2_hw_acl.data()));
1307     ADD_EXPECT(ACL::list_cmds::l2_delete_cmd(l2_hw_acl));
1308     TRY_CHECK(OM::remove(leo));
1309
1310     delete l3b;
1311     delete a_e;
1312     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1313                                                   rc_t::OK);
1314     STRICT_ORDER_OFF();
1315     ADD_EXPECT(ACL::binding_cmds::l3_unbind_cmd(hw_binding, direction_t::INPUT,
1316                                          hw_ifh.data(), hw_acl.data()));
1317     ADD_EXPECT(ACL::list_cmds::l3_delete_cmd(hw_acl));
1318     ADD_EXPECT(ACL::acl_ethertype_cmds::unbind_cmd(ae_binding, hw_ifh.data()));
1319     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1320     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1321
1322     TRY_CHECK(OM::remove(fyodor));
1323 }
1324
1325 BOOST_AUTO_TEST_CASE(test_arp_proxy) {
1326     VppInit vi;
1327     const std::string kurt = "KurtVonnegut";
1328     rc_t rc = rc_t::OK;
1329
1330     asio::ip::address_v4 low  = asio::ip::address_v4::from_string("10.0.0.0");
1331     asio::ip::address_v4 high = asio::ip::address_v4::from_string("10.0.0.255");
1332
1333     arp_proxy_config ap(low, high);
1334     HW::item<bool> hw_ap_cfg(true, rc_t::OK);
1335     ADD_EXPECT(arp_proxy_config_cmds::config_cmd(hw_ap_cfg, low, high));
1336     TRY_CHECK_RC(OM::write(kurt, ap));
1337
1338     std::string itf3_name = "host3";
1339     interface itf3(itf3_name,
1340                    interface::type_t::AFPACKET,
1341                    interface::admin_state_t::UP);
1342     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1343     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1344     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf3_name));
1345     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1346     TRY_CHECK_RC(OM::write(kurt, itf3));
1347
1348     arp_proxy_binding *apb = new arp_proxy_binding(itf3);
1349     HW::item<bool> hw_binding(true, rc_t::OK);
1350     ADD_EXPECT(arp_proxy_binding_cmds::bind_cmd(hw_binding, hw_ifh.data()));
1351     TRY_CHECK_RC(OM::write(kurt, *apb));
1352
1353     delete apb;
1354
1355     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1356                                                   rc_t::OK);
1357     STRICT_ORDER_OFF();
1358     ADD_EXPECT(arp_proxy_binding_cmds::unbind_cmd(hw_binding, hw_ifh.data()));
1359     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1360     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf3_name));
1361     ADD_EXPECT(arp_proxy_config_cmds::unconfig_cmd(hw_ap_cfg, low, high));
1362
1363     TRY_CHECK(OM::remove(kurt));
1364 }
1365
1366 BOOST_AUTO_TEST_CASE(test_ip_punt_redirect) {
1367     VppInit vi;
1368     const std::string eliot = "EliotReed";
1369     rc_t rc = rc_t::OK;
1370
1371     /*
1372      * Interface 1 is the tx interface
1373      */
1374     std::string itf1_name = "tx-itf";
1375     interface itf1(itf1_name,
1376                    interface::type_t::AFPACKET,
1377                    interface::admin_state_t::UP);
1378     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1379     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1380     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1381     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1382     TRY_CHECK_RC(OM::write(eliot, itf1));
1383
1384     boost::asio::ip::address addr = boost::asio::ip::address::from_string("192.168.0.20");
1385
1386     /*
1387      * Interface 2 is the rx interface
1388      */
1389     std::string itf2_name = "rx-itf";
1390     interface itf2(itf2_name,
1391                    interface::type_t::AFPACKET,
1392                    interface::admin_state_t::UP);
1393
1394     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1395     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1396     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1397     TRY_CHECK_RC(OM::write(eliot, itf2));
1398
1399     ip_punt_redirect *ip_punt = new ip_punt_redirect(itf2, itf1, addr);
1400     HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1401     HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1402     ADD_EXPECT(ip_punt_redirect_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data(), addr));
1403     TRY_CHECK_RC(OM::write(eliot, *ip_punt));
1404
1405     delete ip_punt;
1406
1407     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1408     STRICT_ORDER_OFF();
1409     ADD_EXPECT(ip_punt_redirect_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data(), addr));
1410     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1411     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1412     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1413     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1414
1415     TRY_CHECK(OM::remove(eliot));
1416 }
1417
1418 BOOST_AUTO_TEST_CASE(test_ip_unnumbered) {
1419     VppInit vi;
1420     const std::string eric = "EricAmbler";
1421     rc_t rc = rc_t::OK;
1422
1423     /*
1424      * Interface 1 has the L3 address
1425      */
1426     std::string itf1_name = "host1";
1427     interface itf1(itf1_name,
1428                    interface::type_t::AFPACKET,
1429                    interface::admin_state_t::UP);
1430     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1431     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1432     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1433     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1434     TRY_CHECK_RC(OM::write(eric, itf1));
1435
1436     route::prefix_t pfx_10("10.10.10.10", 24);
1437     l3_binding *l3 = new l3_binding(itf1, pfx_10);
1438     HW::item<bool> hw_l3_bind(true, rc_t::OK);
1439     HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1440     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1441     TRY_CHECK_RC(OM::write(eric, *l3));
1442
1443     /*
1444      * Interface 2 is unnumbered
1445      */
1446     std::string itf2_name = "host2";
1447     interface itf2(itf2_name,
1448                    interface::type_t::AFPACKET,
1449                    interface::admin_state_t::UP);
1450
1451     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1452     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1453     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh2));
1454     TRY_CHECK_RC(OM::write(eric, itf2));
1455
1456     ip_unnumbered *ipun = new ip_unnumbered(itf2, itf1);
1457     HW::item<bool> hw_ip_cfg(true, rc_t::OK);
1458     HW::item<bool> hw_ip_uncfg(false, rc_t::OK);
1459     ADD_EXPECT(ip_unnumbered_cmds::config_cmd(hw_ip_cfg, hw_ifh2.data(), hw_ifh.data()));
1460     TRY_CHECK_RC(OM::write(eric, *ipun));
1461
1462     delete l3;
1463     delete ipun;
1464
1465     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1466     STRICT_ORDER_OFF();
1467     ADD_EXPECT(ip_unnumbered_cmds::unconfig_cmd(hw_ip_uncfg, hw_ifh2.data(), hw_ifh.data()));
1468     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1469     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh2));
1470     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1471     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1472     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1473
1474     TRY_CHECK(OM::remove(eric));
1475 }
1476
1477 BOOST_AUTO_TEST_CASE(test_ip6nd) {
1478     VppInit vi;
1479     const std::string paulo = "PauloCoelho";
1480     rc_t rc = rc_t::OK;
1481
1482     /*
1483      * ra config
1484      */
1485     std::string itf_name = "host_ip6nd";
1486     interface itf(itf_name,
1487                    interface::type_t::AFPACKET,
1488                    interface::admin_state_t::UP);
1489     HW::item<handle_t> hw_ifh(3, rc_t::OK);
1490     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1491     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name));
1492     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1493     TRY_CHECK_RC(OM::write(paulo, itf));
1494
1495     route::prefix_t pfx_10("fd8f:69d8:c12c:ca62::3", 128);
1496     l3_binding *l3 = new l3_binding(itf, pfx_10);
1497     HW::item<bool> hw_l3_bind(true, rc_t::OK);
1498     HW::item<bool> hw_l3_unbind(false, rc_t::OK);
1499     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind, hw_ifh.data(), pfx_10));
1500     TRY_CHECK_RC(OM::write(paulo, *l3));
1501
1502     ra_config ra(0, 1, 0, 4);
1503     ip6nd_ra_config *ip6ra = new ip6nd_ra_config(itf, ra);
1504     HW::item<bool> hw_ip6nd_ra_config_config(true, rc_t::OK);
1505     HW::item<bool> hw_ip6nd_ra_config_unconfig(false, rc_t::OK);
1506     ADD_EXPECT(ip6nd_ra_config::config_cmd(hw_ip6nd_ra_config_config, hw_ifh.data(), ra));
1507     TRY_CHECK_RC(OM::write(paulo, *ip6ra));
1508
1509     /*
1510      * ra prefix
1511      */
1512     ra_prefix ra_pfx(pfx_10, 0, 0, 2592000, 604800);
1513     ip6nd_ra_prefix *ip6pfx = new ip6nd_ra_prefix(itf, ra_pfx);
1514     HW::item<bool> hw_ip6nd_ra_prefix_config(true, rc_t::OK);
1515     HW::item<bool> hw_ip6nd_ra_prefix_unconfig(false, rc_t::OK);
1516     ADD_EXPECT(ip6nd_ra_prefix::config_cmd(hw_ip6nd_ra_prefix_config, hw_ifh.data(), ra_pfx));
1517     TRY_CHECK_RC(OM::write(paulo, *ip6pfx));
1518
1519     delete ip6pfx;
1520
1521     ADD_EXPECT(ip6nd_ra_prefix::unconfig_cmd(hw_ip6nd_ra_prefix_unconfig, hw_ifh.data(), ra_pfx));
1522
1523     delete ip6ra;
1524     delete l3;
1525
1526     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1527
1528     STRICT_ORDER_OFF();
1529     ADD_EXPECT(ip6nd_ra_config::unconfig_cmd(hw_ip6nd_ra_config_unconfig, hw_ifh.data(), ra));
1530     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind, hw_ifh.data(), pfx_10));
1531     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1532     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name));
1533
1534     TRY_CHECK(OM::remove(paulo));
1535 }
1536
1537 BOOST_AUTO_TEST_CASE(test_interface_span) {
1538     VppInit vi;
1539     const std::string elif = "ElifShafak";
1540     rc_t rc = rc_t::OK;
1541
1542     /*
1543      * Interface 1 to be mirrored
1544      */
1545     std::string itf1_name = "port-from";
1546     interface itf1(itf1_name,
1547                    interface::type_t::AFPACKET,
1548                    interface::admin_state_t::UP);
1549     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1550     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1551     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1552     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1553     TRY_CHECK_RC(OM::write(elif, itf1));
1554
1555     /*
1556      * Interface 2 where traffic is mirrored
1557      */
1558     std::string itf2_name = "port-to";
1559     interface itf2(itf2_name,
1560                    interface::type_t::AFPACKET,
1561                    interface::admin_state_t::UP);
1562
1563     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1564     HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1565
1566     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1567     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1568     TRY_CHECK_RC(OM::write(elif, itf2));
1569
1570     interface_span *itf_span = new interface_span(itf1, itf2, interface_span::state_t::TX_RX_ENABLED);
1571     HW::item<bool> hw_is_cfg(true, rc_t::OK);
1572     HW::item<bool> hw_is_uncfg(true, rc_t::OK);
1573     ADD_EXPECT(interface_span_cmds::config_cmd(hw_is_cfg, hw_ifh.data(), hw_ifh2.data(), interface_span::state_t::TX_RX_ENABLED));
1574     TRY_CHECK_RC(OM::write(elif, *itf_span));
1575
1576     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1577     HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1578
1579     delete itf_span;
1580     STRICT_ORDER_OFF();
1581     ADD_EXPECT(interface_span_cmds::unconfig_cmd(hw_is_uncfg, hw_ifh.data(), hw_ifh2.data()));
1582     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1583     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1584     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1585     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1586
1587     TRY_CHECK(OM::remove(elif));
1588 }
1589
1590 BOOST_AUTO_TEST_CASE(test_routing) {
1591     VppInit vi;
1592     const std::string ian = "IanFleming";
1593     rc_t rc = rc_t::OK;
1594
1595     /*
1596      * non-default route domain
1597      */
1598     route_domain rd4(1);
1599     HW::item<bool> hw_rd4_create(true, rc_t::OK);
1600     HW::item<bool> hw_rd4_delete(false, rc_t::OK);
1601     HW::item<bool> hw_rd6_create(true, rc_t::OK);
1602     HW::item<bool> hw_rd6_delete(false, rc_t::OK);
1603     HW::item<route::table_id_t> hw_rd4_bind(1, rc_t::OK);
1604     HW::item<route::table_id_t> hw_rd4_unbind(route::DEFAULT_TABLE, rc_t::OK);
1605     HW::item<route::table_id_t> hw_rd6_bind(1, rc_t::OK);
1606     HW::item<route::table_id_t> hw_rd7_unbind(route::DEFAULT_TABLE, rc_t::OK);
1607     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd4_create, l3_proto_t::IPV4, 1));
1608     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd6_create, l3_proto_t::IPV6, 1));
1609     TRY_CHECK_RC(OM::write(ian, rd4));
1610
1611     /*
1612      * a couple of interfaces
1613      */
1614     std::string itf1_name = "af1";
1615     interface itf1(itf1_name,
1616                    interface::type_t::AFPACKET,
1617                    interface::admin_state_t::UP);
1618     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1619     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1620     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1621     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf1_name));
1622     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1623     TRY_CHECK_RC(OM::write(ian, itf1));
1624
1625     std::string itf2_name = "af2";
1626     interface *itf2 = new interface(itf2_name,
1627                                     interface::type_t::AFPACKET,
1628                                     interface::admin_state_t::UP,
1629                                     rd4);
1630
1631     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1632     HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1633     HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1634     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf2_name));
1635     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1636     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_bind, l3_proto_t::IPV4, hw_ifh2));
1637     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd6_bind, l3_proto_t::IPV6, hw_ifh2));
1638     TRY_CHECK_RC(OM::write(ian, *itf2));
1639
1640     /*
1641      * prefix on each interface
1642      */
1643     route::prefix_t pfx_10("10.10.10.10", 24);
1644     l3_binding *l3_10 = new l3_binding(itf1, pfx_10);
1645     HW::item<bool> hw_l3_10_bind(true, rc_t::OK);
1646     HW::item<bool> hw_l3_10_unbind(false, rc_t::OK);
1647     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_10_bind, hw_ifh.data(), pfx_10));
1648     TRY_CHECK_RC(OM::write(ian, *l3_10));
1649     route::prefix_t pfx_11("11.11.11.11", 24);
1650     l3_binding *l3_11 = new l3_binding(*itf2, pfx_11);
1651     HW::item<bool> hw_l3_11_bind(true, rc_t::OK);
1652     HW::item<bool> hw_l3_11_unbind(false, rc_t::OK);
1653     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_11_bind, hw_ifh2.data(), pfx_11));
1654     TRY_CHECK_RC(OM::write(ian, *l3_11));
1655
1656     /*
1657      * A route via interface 1 in the default table
1658      */
1659     route::prefix_t pfx_5("5.5.5.5", 32);
1660     boost::asio::ip::address nh_10 = boost::asio::ip::address::from_string("10.10.10.11");
1661     route::path *path_10 = new route::path(nh_10, itf1);
1662     route::ip_route *route_5 = new route::ip_route(pfx_5);
1663     route_5->add(*path_10);
1664     HW::item<bool> hw_route_5(true, rc_t::OK);
1665     ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, {*path_10}));
1666     TRY_CHECK_RC(OM::write(ian, *route_5));
1667
1668     /*
1669      * A route via interface 2 in the non-default table
1670      */
1671     boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10");
1672     route::path *path_11 = new route::path(nh_11, *itf2);
1673     route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5);
1674     route_5_2->add(*path_11);
1675     HW::item<bool> hw_route_5_2(true, rc_t::OK);
1676     ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, {*path_11}));
1677     TRY_CHECK_RC(OM::write(ian, *route_5_2));
1678
1679     /*
1680      * An ARP entry for the neighbour on itf1
1681      */
1682     HW::item<bool> hw_neighbour(true, rc_t::OK);
1683     mac_address_t mac_n({0,1,2,4,5,6});
1684     neighbour *ne = new neighbour(itf1, nh_10, mac_n);
1685     ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1686     TRY_CHECK_RC(OM::write(ian, *ne));
1687
1688     /*
1689      * A DVR route
1690      */
1691     route::prefix_t pfx_6("6.6.6.6", 32);
1692     route::path *path_l2 = new route::path(*itf2, nh_proto_t::ETHERNET);
1693     route::ip_route *route_dvr = new route::ip_route(pfx_6);
1694     route_dvr->add(*path_l2);
1695     HW::item<bool> hw_route_dvr(true, rc_t::OK);
1696     ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, {*path_l2}));
1697     TRY_CHECK_RC(OM::write(ian, *route_dvr));
1698
1699     STRICT_ORDER_OFF();
1700     // delete the stack objects that hold references to others
1701     // so the OM::remove is the call that removes the last reference
1702     delete l3_11;
1703     delete l3_10;
1704     delete itf2;
1705     delete route_5;
1706     delete path_10;
1707     delete route_5_2;
1708     delete path_11;
1709     delete route_dvr;
1710     delete path_l2;
1711     delete ne;
1712     ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10));
1713     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6));
1714     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5));
1715     ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5));
1716     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10));
1717     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11));
1718     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1719     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name));
1720     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2));
1721     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2));
1722     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1723     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name));
1724     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1));
1725     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1));
1726
1727     TRY_CHECK(OM::remove(ian));
1728 }
1729
1730 BOOST_AUTO_TEST_CASE(test_nat) {
1731     VppInit vi;
1732     const std::string gs = "GeorgeSimenon";
1733     rc_t rc = rc_t::OK;
1734
1735     /*
1736      * Inside Interface
1737      */
1738     std::string itf_in_name = "inside";
1739     interface itf_in(itf_in_name,
1740                      interface::type_t::AFPACKET,
1741                      interface::admin_state_t::UP);
1742     HW::item<handle_t> hw_ifh(2, rc_t::OK);
1743     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1744     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1745     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name));
1746     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh));
1747     TRY_CHECK_RC(OM::write(gs, itf_in));
1748
1749     /*
1750      * outside
1751      */
1752     std::string itf_out_name = "port-to";
1753     interface itf_out(itf_out_name,
1754                    interface::type_t::AFPACKET,
1755                    interface::admin_state_t::UP);
1756
1757     HW::item<handle_t> hw_ifh2(4, rc_t::OK);
1758     HW::item<interface::admin_state_t> hw_as_up2(interface::admin_state_t::UP, rc_t::OK);
1759     HW::item<interface::admin_state_t> hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK);
1760
1761     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name));
1762     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2));
1763     TRY_CHECK_RC(OM::write(gs, itf_out));
1764
1765     /*
1766      * A NAT static mapping
1767      */
1768     boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1");
1769     boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1");
1770
1771     nat_static ns(in_addr, out_addr);
1772     HW::item<bool> hw_ns(true, rc_t::OK);
1773
1774     ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1775     TRY_CHECK_RC(OM::write(gs, ns));
1776
1777     /*
1778      * bind nat inside and out
1779      */
1780     nat_binding *nb_in = new nat_binding(itf_in,
1781                                          direction_t::INPUT,
1782                                          l3_proto_t::IPV4,
1783                                          nat_binding::zone_t::INSIDE);
1784     HW::item<bool> hw_nb_in(true, rc_t::OK);
1785
1786     ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in,
1787                                                    hw_ifh.data().value(),
1788                                                    nat_binding::zone_t::INSIDE));
1789     TRY_CHECK_RC(OM::write(gs, *nb_in));
1790
1791     nat_binding *nb_out = new nat_binding(itf_out,
1792                                           direction_t::INPUT,
1793                                           l3_proto_t::IPV4,
1794                                           nat_binding::zone_t::OUTSIDE);
1795     HW::item<bool> hw_nb_out(true, rc_t::OK);
1796
1797     ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out,
1798                                                    hw_ifh2.data().value(),
1799                                                    nat_binding::zone_t::OUTSIDE));
1800     TRY_CHECK_RC(OM::write(gs, *nb_out));
1801
1802
1803     STRICT_ORDER_OFF();
1804     delete nb_in;
1805     delete nb_out;
1806     ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in,
1807                                                      hw_ifh.data().value(),
1808                                                      nat_binding::zone_t::INSIDE));
1809     ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out,
1810                                                      hw_ifh2.data().value(),
1811                                                      nat_binding::zone_t::OUTSIDE));
1812     ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr));
1813     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh));
1814     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name));
1815     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2));
1816     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name));
1817
1818     TRY_CHECK(OM::remove(gs));
1819 }
1820
1821 BOOST_AUTO_TEST_CASE(test_interface_events) {
1822     VppInit vi;
1823     MockListener ml;
1824
1825     HW::item<bool> hw_want(true, rc_t::OK);
1826
1827     ADD_EXPECT(interface_cmds::events_cmd(ml));
1828     cmd* itf = new interface_cmds::events_cmd(ml);
1829
1830     HW::enqueue(itf);
1831     HW::write();
1832 }
1833
1834 BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) {
1835     VppInit vi;
1836     const std::string rene = "ReneGoscinny";
1837     rc_t rc = rc_t::OK;
1838
1839     /*
1840      * Create an interface with two IP addresses
1841      */
1842     std::string itf1_name = "host1";
1843     interface itf1(itf1_name,
1844                    interface::type_t::AFPACKET,
1845                    interface::admin_state_t::UP);
1846     HW::item<handle_t> hw_ifh1(2, rc_t::OK);
1847     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP, rc_t::OK);
1848     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN, rc_t::OK);
1849     ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name));
1850     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1));
1851     TRY_CHECK_RC(OM::write(rene, itf1));
1852
1853     route::prefix_t pfx_10("10.10.10.10", 24);
1854     l3_binding *l3_1 = new l3_binding(itf1, pfx_10);
1855     HW::item<bool> hw_l3_bind1(true, rc_t::OK);
1856     HW::item<bool> hw_l3_unbind1(false, rc_t::OK);
1857     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1858     TRY_CHECK_RC(OM::write(rene, *l3_1));
1859
1860     route::prefix_t pfx_11("10.10.11.11", 24);
1861     l3_binding *l3_2 = new l3_binding(itf1, pfx_11);
1862     HW::item<bool> hw_l3_bind2(true, rc_t::OK);
1863     HW::item<bool> hw_l3_unbind2(false, rc_t::OK);
1864     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1865     TRY_CHECK_RC(OM::write(rene, *l3_2));
1866
1867     route_domain rd(1);
1868     HW::item<bool> hw_rd_create(true, rc_t::OK);
1869     HW::item<bool> hw_rd_delete(false, rc_t::OK);
1870     HW::item<route::table_id_t> hw_rd_bind(1, rc_t::OK);
1871     HW::item<route::table_id_t> hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK);
1872     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1));
1873     ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1));
1874     TRY_CHECK_RC(OM::write(rene, rd));
1875
1876     /*
1877      * update the interface to change to a new route-domain
1878      * expect that the l3-bindings are removed and readded.
1879      */
1880     interface *itf2 = new interface(itf1_name,
1881                                     interface::type_t::AFPACKET,
1882                                     interface::admin_state_t::UP,
1883                                     rd);
1884     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1885     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1886     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1));
1887     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1));
1888     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1889     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1890     TRY_CHECK_RC(OM::write(rene, *itf2));
1891
1892     /*
1893      * mve the interface back to the default route-domain
1894      */
1895     interface itf3(itf1_name,
1896                    interface::type_t::AFPACKET,
1897                    interface::admin_state_t::UP);
1898     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1899     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1900     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1));
1901     ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1));
1902     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10));
1903     ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11));
1904     TRY_CHECK_RC(OM::write(rene, itf3));
1905
1906     delete l3_1;
1907     delete l3_2;
1908     delete itf2;
1909
1910     STRICT_ORDER_OFF();
1911     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10));
1912     ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11));
1913     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1));
1914     ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name));
1915     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1));
1916     ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1));
1917
1918     TRY_CHECK(OM::remove(rene));
1919 }
1920
1921 BOOST_AUTO_TEST_CASE(test_prefixes) {
1922     route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16);
1923
1924     BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::"));
1925
1926     route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17);
1927
1928     BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::"));
1929     BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::"));
1930
1931     route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15);
1932     BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::"));
1933     BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::"));
1934
1935     route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16);
1936
1937     BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0"));
1938
1939     route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17);
1940
1941     BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0"));
1942     BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1943     BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255"));
1944
1945     route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15);
1946
1947     BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0"));
1948     BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0"));
1949     BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255"));
1950
1951     route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32);
1952
1953     BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255"));
1954     BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1955     BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1"));
1956
1957 }
1958
1959 BOOST_AUTO_TEST_CASE(test_pipes) {
1960     VppInit vi;
1961     const std::string gk = "GKChesterton";
1962
1963     const std::string pipe_name_1 = "pipe1";
1964     VOM::pipe pipe1(1, interface::admin_state_t::UP);
1965     HW::item<handle_t> hw_hdl(4, rc_t::OK);
1966     HW::item<pipe::handle_pair_t> hw_hdl_pair(std::make_pair(5,6), rc_t::OK);
1967
1968     HW::item<interface::admin_state_t> hw_as_up(interface::admin_state_t::UP,
1969                                                 rc_t::OK);
1970     HW::item<interface::admin_state_t> hw_as_down(interface::admin_state_t::DOWN,
1971                                                   rc_t::OK);
1972     ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair));
1973     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl));
1974     TRY_CHECK_RC(OM::write(gk, pipe1));
1975
1976     pipe1.set_ends(hw_hdl_pair.data());
1977
1978     // put each end of the pipe in a BD
1979     bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF,
1980                       bridge_domain::arp_term_mode_t::OFF,
1981                       bridge_domain::flood_mode_t::OFF,
1982                       bridge_domain::mac_age_mode_t::ON);
1983
1984     HW::item<uint32_t> hw_bd(33, rc_t::OK);
1985     ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd,
1986                                               bridge_domain::learning_mode_t::OFF,
1987                                               bridge_domain::arp_term_mode_t::OFF,
1988                                               bridge_domain::flood_mode_t::OFF,
1989                                               bridge_domain::mac_age_mode_t::ON));
1990
1991     TRY_CHECK_RC(OM::write(gk, bd1));
1992
1993     l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1);
1994     HW::item<bool> hw_l2_1_bind(true, rc_t::OK);
1995
1996     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind,
1997                                          pipe1.east()->handle(),
1998                                          hw_bd.data(),
1999                                          l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2000     TRY_CHECK_RC(OM::write(gk, *l2_1));
2001
2002     l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1);
2003     HW::item<bool> hw_l2_2_bind(true, rc_t::OK);
2004
2005     ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind,
2006                                          pipe1.west()->handle(),
2007                                          hw_bd.data(),
2008                                          l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2009     TRY_CHECK_RC(OM::write(gk, *l2_2));
2010
2011     STRICT_ORDER_OFF();
2012
2013     delete l2_1;
2014     delete l2_2;
2015     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2016                                            pipe1.east()->handle(),
2017                                            hw_bd.data(),
2018                                            l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2019     ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind,
2020                                            pipe1.west()->handle(),
2021                                            hw_bd.data(),
2022                                            l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL));
2023     ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl));
2024     ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair));
2025     ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd));
2026     TRY_CHECK(OM::remove(gk));
2027 }
2028
2029 BOOST_AUTO_TEST_SUITE_END()