libnl  3.2.21
nlovs-dp-list.c
1 /*
2  * src/nlovs-dp-list.c
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation version 2.1
7  * of the License.
8  *
9  * Copyright (c) 2013 Thomas Graf <tgraf@suug.ch>
10  */
11 
12 #include <netlink/cli/utils.h>
13 #include <netlink/openvswitch/openvswitch.h>
14 
15 static void print_usage(void)
16 {
17  printf(
18 "Usage: nlovs-dp-list [OPTIONS]... \n"
19 "\n"
20 "OPTIONS\n"
21 " --stats Show statistics, implies --details\n"
22 " -h, --help Show this help text.\n"
23 " -v, --version Show versioning information.\n"
24 "\n"
25 " -n, --name=NAME Name of datapath\n"
26  );
27  exit(0);
28 }
29 
30 int main(int argc, char *argv[])
31 {
32  struct nl_sock *sock;
33  struct nl_cache *dp_cache;
34  struct nl_dump_params params = {
36  .dp_fd = stdout,
37  };
38  int err;
39 
40  sock = nl_cli_alloc_socket();
41  nl_cli_connect(sock, NETLINK_GENERIC);
42 
43  //link = nl_cli_link_alloc();
44 
45  for (;;) {
46  int c, optidx = 0;
47  enum {
48  ARG_STATS = 257,
49  };
50  static struct option long_opts[] = {
51  { "stats", 0, 0, ARG_STATS },
52  { "help", 0, 0, 'h' },
53  { "version", 0, 0, 'v' },
54  { "name", 1, 0, 'n' },
55  { 0, 0, 0, 0 }
56  };
57 
58  c = getopt_long(argc, argv, "hvn:", long_opts, &optidx);
59  if (c == -1)
60  break;
61 
62  switch (c) {
63  case ARG_STATS: params.dp_type = NL_DUMP_STATS; break;
64  case 'h': print_usage(); break;
65  case 'v': nl_cli_print_version(); break;
66  //case 'n': nl_cli_link_parse_name(link, optarg); break;
67  }
68  }
69 
70  if ((err = ovs_dp_alloc_cache(sock, &dp_cache)) < 0) {
71  nl_perror(err, "Unable to allocate dp cache");
72  return 1;
73  }
74 
75  nl_cache_dump(dp_cache, &params);
76 
77  nl_cache_free(dp_cache);
78  nl_socket_free(sock);
79 
80  return 0;
81 }