193cc3ee3SNeale Ranns/*
293cc3ee3SNeale Ranns * Copyright (c) 2017 Cisco and/or its affiliates.
393cc3ee3SNeale Ranns * Licensed under the Apache License, Version 2.0 (the "License");
493cc3ee3SNeale Ranns * you may not use this file except in compliance with the License.
593cc3ee3SNeale Ranns * You may obtain a copy of the License at:
693cc3ee3SNeale Ranns *
793cc3ee3SNeale Ranns *     http://www.apache.org/licenses/LICENSE-2.0
893cc3ee3SNeale Ranns *
993cc3ee3SNeale Ranns * Unless required by applicable law or agreed to in writing, software
1093cc3ee3SNeale Ranns * distributed under the License is distributed on an "AS IS" BASIS,
1193cc3ee3SNeale Ranns * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1293cc3ee3SNeale Ranns * See the License for the specific language governing permissions and
1393cc3ee3SNeale Ranns * limitations under the License.
1493cc3ee3SNeale Ranns */
1593cc3ee3SNeale Ranns
1693cc3ee3SNeale Ranns#include "vom/gbp_vxlan_cmds.hpp"
178da9fc65SNeale Ranns#include "vom/api_types.hpp"
1893cc3ee3SNeale Ranns
1993cc3ee3SNeale Rannsnamespace VOM {
2093cc3ee3SNeale Rannsnamespace gbp_vxlan_cmds {
2193cc3ee3SNeale Rannscreate_cmd::create_cmd(HW::item<handle_t>& item,
2293cc3ee3SNeale Ranns                       const std::string& name,
238da9fc65SNeale Ranns                       const boost::asio::ip::address_v4& src,
2493cc3ee3SNeale Ranns                       uint32_t vni,
2593cc3ee3SNeale Ranns                       bool is_l2,
2693cc3ee3SNeale Ranns                       uint32_t bd_rd)
2793cc3ee3SNeale Ranns  : interface::create_cmd<vapi::Gbp_vxlan_tunnel_add>(item, name)
288da9fc65SNeale Ranns  , m_src(src)
2993cc3ee3SNeale Ranns  , m_vni(vni)
3093cc3ee3SNeale Ranns  , m_is_l2(is_l2)
3193cc3ee3SNeale Ranns  , m_bd_rd(bd_rd)
3293cc3ee3SNeale Ranns{
3393cc3ee3SNeale Ranns}
3493cc3ee3SNeale Ranns
3593cc3ee3SNeale Rannsrc_t
3693cc3ee3SNeale Rannscreate_cmd::issue(connection& con)
3793cc3ee3SNeale Ranns{
3893cc3ee3SNeale Ranns  msg_t req(con.ctx(), std::ref(*this));
3993cc3ee3SNeale Ranns
4093cc3ee3SNeale Ranns  auto& payload = req.get_request().get_payload();
4193cc3ee3SNeale Ranns
4293cc3ee3SNeale Ranns  payload.tunnel.vni = m_vni;
4393cc3ee3SNeale Ranns  payload.tunnel.bd_rd_id = m_bd_rd;
4493cc3ee3SNeale Ranns  if (m_is_l2)
4593cc3ee3SNeale Ranns    payload.tunnel.mode = GBP_VXLAN_TUNNEL_MODE_L2;
4693cc3ee3SNeale Ranns  else
4793cc3ee3SNeale Ranns    payload.tunnel.mode = GBP_VXLAN_TUNNEL_MODE_L3;
488da9fc65SNeale Ranns  to_api(m_src, payload.tunnel.src);
4993cc3ee3SNeale Ranns
5093cc3ee3SNeale Ranns  VAPI_CALL(req.execute());
5193cc3ee3SNeale Ranns
5293cc3ee3SNeale Ranns  wait();
5393cc3ee3SNeale Ranns  if (m_hw_item.rc() == rc_t::OK) {
5493cc3ee3SNeale Ranns    insert_interface();
5593cc3ee3SNeale Ranns  }
5693cc3ee3SNeale Ranns
5793cc3ee3SNeale Ranns  return (m_hw_item.rc());
5893cc3ee3SNeale Ranns}
5993cc3ee3SNeale Ranns
6093cc3ee3SNeale Rannsstd::string
6193cc3ee3SNeale Rannscreate_cmd::to_string() const
6293cc3ee3SNeale Ranns{
6393cc3ee3SNeale Ranns  std::ostringstream s;
6493cc3ee3SNeale Ranns  s << "gbp-vxlan-create: " << m_hw_item.to_string() << " vni:" << m_vni
6593cc3ee3SNeale Ranns    << " bd/rd:" << m_bd_rd;
6693cc3ee3SNeale Ranns
6793cc3ee3SNeale Ranns  return (s.str());
6893cc3ee3SNeale Ranns}
6993cc3ee3SNeale Ranns
7093cc3ee3SNeale Rannsdelete_cmd::delete_cmd(HW::item<handle_t>& item, uint32_t vni)
7193cc3ee3SNeale Ranns  : interface::delete_cmd<vapi::Gbp_vxlan_tunnel_del>(item)
7293cc3ee3SNeale Ranns  , m_vni(vni)
7393cc3ee3SNeale Ranns{
7493cc3ee3SNeale Ranns}
7593cc3ee3SNeale Ranns
7693cc3ee3SNeale Rannsrc_t
7793cc3ee3SNeale Rannsdelete_cmd::issue(connection& con)
7893cc3ee3SNeale Ranns{
7993cc3ee3SNeale Ranns  msg_t req(con.ctx(), std::ref(*this));
8093cc3ee3SNeale Ranns
8193cc3ee3SNeale Ranns  auto& payload = req.get_request().get_payload();
8293cc3ee3SNeale Ranns  payload.vni = m_vni;
8393cc3ee3SNeale Ranns
8493cc3ee3SNeale Ranns  VAPI_CALL(req.execute());
8593cc3ee3SNeale Ranns
8693cc3ee3SNeale Ranns  wait();
8793cc3ee3SNeale Ranns  m_hw_item.set(rc_t::NOOP);
8893cc3ee3SNeale Ranns
8993cc3ee3SNeale Ranns  remove_interface();
9093cc3ee3SNeale Ranns  return rc_t::OK;
9193cc3ee3SNeale Ranns}
9293cc3ee3SNeale Ranns
9393cc3ee3SNeale Rannsstd::string
9493cc3ee3SNeale Rannsdelete_cmd::to_string() const
9593cc3ee3SNeale Ranns{
9693cc3ee3SNeale Ranns  std::ostringstream s;
9793cc3ee3SNeale Ranns  s << "gbp-vxlan-delete: " << m_hw_item.to_string() << " vni:" << m_vni;
9893cc3ee3SNeale Ranns
9993cc3ee3SNeale Ranns  return (s.str());
10093cc3ee3SNeale Ranns}
10193cc3ee3SNeale Ranns
10293cc3ee3SNeale Rannsdump_cmd::dump_cmd()
10393cc3ee3SNeale Ranns{
10493cc3ee3SNeale Ranns}
10593cc3ee3SNeale Ranns
10693cc3ee3SNeale Rannsbool
10793cc3ee3SNeale Rannsdump_cmd::operator==(const dump_cmd& other) const
10893cc3ee3SNeale Ranns{
10993cc3ee3SNeale Ranns  return (true);
11093cc3ee3SNeale Ranns}
11193cc3ee3SNeale Ranns
11293cc3ee3SNeale Rannsrc_t
11393cc3ee3SNeale Rannsdump_cmd::issue(connection& con)
11493cc3ee3SNeale Ranns{
11593cc3ee3SNeale Ranns  m_dump.reset(new msg_t(con.ctx(), std::ref(*this)));
11693cc3ee3SNeale Ranns
11793cc3ee3SNeale Ranns  VAPI_CALL(m_dump->execute());
11893cc3ee3SNeale Ranns
11993cc3ee3SNeale Ranns  wait();
12093cc3ee3SNeale Ranns
12193cc3ee3SNeale Ranns  return rc_t::OK;
12293cc3ee3SNeale Ranns}
12393cc3ee3SNeale Ranns
12493cc3ee3SNeale Rannsstd::string
12593cc3ee3SNeale Rannsdump_cmd::to_string() const
12693cc3ee3SNeale Ranns{
12793cc3ee3SNeale Ranns  return ("gbp-vxlan-dump");
12893cc3ee3SNeale Ranns}
12993cc3ee3SNeale Ranns
13093cc3ee3SNeale Ranns} // namespace gbp_vxlan_cmds
13193cc3ee3SNeale Ranns} // namespace VOM
13293cc3ee3SNeale Ranns
13393cc3ee3SNeale Ranns/*
13493cc3ee3SNeale Ranns * fd.io coding-style-patch-verification: ON
13593cc3ee3SNeale Ranns *
13693cc3ee3SNeale Ranns * Local Variables:
13793cc3ee3SNeale Ranns * eval: (c-set-style "mozilla")
13893cc3ee3SNeale Ranns * End:
13993cc3ee3SNeale Ranns */
140