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