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