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