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