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