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