<% unless p("cf_networking.disable") %>
<%=
  require 'json'

  VXLAN_OVERHEAD = 50

  def compute_mtu
    mtu = p('cf_networking.mtu')
    if mtu > 0
      return mtu - VXLAN_OVERHEAD
    else
      return mtu
    end
  end

  toRender = {
    "name" => "cni-wrapper",
    "type" => "cni-wrapper-plugin",
    "cniVersion" => "0.3.1",
    "datastore" => "/var/vcap/data/container-metadata/store.json",
    "iptables_lock_file" => "/var/vcap/data/garden-cni/iptables.lock",
    "instance_address" => spec.ip,
    "iptables_asg_logging" => p("cf_networking.iptables_logging"),
    "iptables_c2c_logging" => p("cf_networking.iptables_logging"),
    "iptables_denied_logs_per_sec" => p("cf_networking.iptables_denied_logs_per_sec"),
    "iptables_accepted_udp_logs_per_sec" => p("cf_networking.iptables_accepted_udp_logs_per_sec"),
    "ingress_tag" => "ffff0000",
    "vtep_name" => "silk-vtep",
    "dns_servers" => p("cf_networking.dns_servers"),
    "delegate" => {
      "cniVersion" => "0.3.1",
      "name" => "silk",
      "type" => "silk-cni",
      "daemonPort" => p('cf_networking.silk_daemon.listen_port'),
      "dataDir" => "/var/vcap/data/host-local",
      "datastore" => "/var/vcap/data/silk/store.json",
      "mtu" => compute_mtu,
      "bandwidthLimits"=> {
        "rate" => p('cf_networking.rate') * 1024,
        "burst" => p('cf_networking.burst') * 1024,
      },
     }
  }

  JSON.pretty_generate(toRender)
%>
<% end %>
