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