use zu/zd in printf to avoid warnings on 32bit
[sliver-openvswitch.git] / lib / netdev-tunnel.c
index 6fe6d68..095306f 100644 (file)
@@ -73,7 +73,7 @@ is_tunnel_class(const struct netdev_class *class)
 static struct netdev_dev_tunnel *
 netdev_dev_tunnel_cast(const struct netdev_dev *netdev_dev)
 {
-    assert(is_tunnel_class(netdev_dev_get_class(netdev_dev)));
+    ovs_assert(is_tunnel_class(netdev_dev_get_class(netdev_dev)));
     return CONTAINER_OF(netdev_dev, struct netdev_dev_tunnel, netdev_dev);
 }
 
@@ -81,7 +81,7 @@ static struct netdev_tunnel *
 netdev_tunnel_cast(const struct netdev *netdev)
 {
     struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
-    assert(is_tunnel_class(netdev_dev_get_class(netdev_dev)));
+    ovs_assert(is_tunnel_class(netdev_dev_get_class(netdev_dev)));
     return CONTAINER_OF(netdev, struct netdev_tunnel, netdev);
 }
 
@@ -89,15 +89,15 @@ static int
 netdev_tunnel_create(const struct netdev_class *class, const char *name,
                     struct netdev_dev **netdev_devp)
 {
-    static unsigned int n = 0xaa550000;
+    static unsigned int n = 0;
     struct netdev_dev_tunnel *netdev_dev;
     int error;
 
     netdev_dev = xzalloc(sizeof *netdev_dev);
     netdev_dev_init(&netdev_dev->netdev_dev, name, class);
-    netdev_dev->hwaddr[0] = 0x55;
-    netdev_dev->hwaddr[1] = 0xaa;
-    netdev_dev->hwaddr[2] = n >> 24;
+    netdev_dev->hwaddr[0] = 0xfe;
+    netdev_dev->hwaddr[1] = 0xff;
+    netdev_dev->hwaddr[2] = 0xff;
     netdev_dev->hwaddr[3] = n >> 16;
     netdev_dev->hwaddr[4] = n >> 8;
     netdev_dev->hwaddr[5] = n;
@@ -164,16 +164,16 @@ netdev_tunnel_close(struct netdev *netdev_)
 }
 
 static int
-netdev_tunnel_get_config(struct netdev_dev *dev_, struct shash *args)
+netdev_tunnel_get_config(struct netdev_dev *dev_, struct smap *args)
 {
     struct netdev_dev_tunnel *netdev_dev = netdev_dev_tunnel_cast(dev_);
 
     if (netdev_dev->valid_remote_ip)
-       shash_add(args, "remote_ip",
-           xasprintf(IP_FMT, IP_ARGS(&netdev_dev->remote_addr.sin_addr)));
+       smap_add_format(args, "remote_ip", IP_FMT,
+               IP_ARGS(netdev_dev->remote_addr.sin_addr.s_addr));
     if (netdev_dev->valid_remote_port)
-        shash_add(args, "remote_port",
-           xasprintf("%"PRIu16, ntohs(netdev_dev->remote_addr.sin_port)));
+        smap_add_format(args, "remote_port", "%"PRIu16,
+               ntohs(netdev_dev->remote_addr.sin_port));
     return 0;
 }
 
@@ -196,13 +196,13 @@ netdev_tunnel_connect(struct netdev_dev_tunnel *dev)
 }
 
 static int
-netdev_tunnel_set_config(struct netdev_dev *dev_, const struct shash *args)
+netdev_tunnel_set_config(struct netdev_dev *dev_, const struct smap *args)
 {
     struct netdev_dev_tunnel *netdev_dev = netdev_dev_tunnel_cast(dev_);
     struct shash_node *node;
 
     VLOG_DBG("tunnel_set_config(%s)", netdev_dev_get_name(dev_));
-    SHASH_FOR_EACH(node, args) {
+    SMAP_FOR_EACH(node, args) {
         VLOG_DBG("arg: %s->%s", node->name, (char*)node->data);
        if (!strcmp(node->name, "remote_ip")) {
            struct in_addr addr;
@@ -239,7 +239,7 @@ netdev_tunnel_recv(struct netdev *netdev_, void *buffer, size_t size)
     for (;;) {
         ssize_t retval;
         retval = recv(dev->sockfd, buffer, size, MSG_TRUNC);
-       VLOG_DBG("%s: recv(%"PRIxPTR", %"PRIu64", MSG_TRUNC) = %"PRId64,
+       VLOG_DBG("%s: recv(%"PRIxPTR", %zu, MSG_TRUNC) = %zd",
                 netdev_get_name(netdev_), (uintptr_t)buffer, size, retval);
         if (retval >= 0) {
            dev->stats.rx_packets++;
@@ -282,14 +282,14 @@ netdev_tunnel_send(struct netdev *netdev_, const void *buffer, size_t size)
     for (;;) {
         ssize_t retval;
         retval = send(dev->sockfd, buffer, size, 0);
-       VLOG_DBG("%s: send(%"PRIxPTR", %"PRIu64") = %"PRId64,
+       VLOG_DBG("%s: send(%"PRIxPTR", %zu) = %zd",
                 netdev_get_name(netdev_), (uintptr_t)buffer, size, retval);
         if (retval >= 0) {
            dev->stats.tx_packets++;
-           dev->stats.tx_bytes++;
+           dev->stats.tx_bytes += retval;
            if (retval != size) {
-               VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%"PRId64" bytes of "
-                            "%"PRIu64") on %s", retval, size, netdev_get_name(netdev_));
+               VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%zd bytes of "
+                            "%zu) on %s", retval, size, netdev_get_name(netdev_));
                dev->stats.tx_errors++;
            }
             return 0;
@@ -439,12 +439,50 @@ netdev_tunnel_get_port(struct unixctl_conn *conn,
     unixctl_command_reply(conn, buf);
 }
 
+static void
+netdev_tunnel_get_tx_bytes(struct unixctl_conn *conn,
+                     int argc OVS_UNUSED, const char *argv[], void *aux OVS_UNUSED)
+{
+    struct netdev_dev_tunnel *tunnel_dev;
+    char buf[128];
+
+    tunnel_dev = shash_find_data(&tunnel_netdev_devs, argv[1]);
+    if (!tunnel_dev) {
+        unixctl_command_reply_error(conn, "no such tunnel netdev");
+        return;
+    }
+
+    sprintf(buf, "%"PRIu64, tunnel_dev->stats.tx_bytes);
+    unixctl_command_reply(conn, buf);
+}
+
+static void
+netdev_tunnel_get_rx_bytes(struct unixctl_conn *conn,
+                     int argc OVS_UNUSED, const char *argv[], void *aux OVS_UNUSED)
+{
+    struct netdev_dev_tunnel *tunnel_dev;
+    char buf[128];
+
+    tunnel_dev = shash_find_data(&tunnel_netdev_devs, argv[1]);
+    if (!tunnel_dev) {
+        unixctl_command_reply_error(conn, "no such tunnel netdev");
+        return;
+    }
+
+    sprintf(buf, "%"PRIu64, tunnel_dev->stats.rx_bytes);
+    unixctl_command_reply(conn, buf);
+}
+
 
 static int
 netdev_tunnel_init(void)
 {
     unixctl_command_register("netdev-tunnel/get-port", "NAME",
                              1, 1, netdev_tunnel_get_port, NULL);
+    unixctl_command_register("netdev-tunnel/get-tx-bytes", "NAME",
+                             1, 1, netdev_tunnel_get_tx_bytes, NULL);
+    unixctl_command_register("netdev-tunnel/get-rx-bytes", "NAME",
+                             1, 1, netdev_tunnel_get_rx_bytes, NULL);
     return 0;
 }
 
@@ -458,6 +496,7 @@ const struct netdev_class netdev_tunnel_class = {
     netdev_tunnel_destroy,
     netdev_tunnel_get_config,
     netdev_tunnel_set_config, 
+    NULL,                      /* get_tunnel_config */
 
     netdev_tunnel_open,
     netdev_tunnel_close,