xtoxll: Rename "byte-order" since it now include more than xtoxll.
authorBen Pfaff <blp@nicira.com>
Fri, 29 Oct 2010 00:13:18 +0000 (17:13 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 Oct 2010 16:48:47 +0000 (09:48 -0700)
Suggested-by: Justin Pettit <jpettit@nicira.com>
18 files changed:
lib/automake.mk
lib/byte-order.h [new file with mode: 0644]
lib/flow.c
lib/learning-switch.c
lib/ofp-parse.c
lib/ofp-print.c
lib/ofp-util.c
lib/unaligned.h
lib/xtoxll.h [deleted file]
ofproto/netflow.c
ofproto/ofproto.c
tests/automake.mk
tests/library.at
tests/test-byte-order.c [new file with mode: 0644]
tests/test-classifier.c
tests/test-xtoxll.c [deleted file]
utilities/ovs-ofctl.c
vswitchd/bridge.c

index c502a3b..5cfac24 100644 (file)
@@ -14,6 +14,7 @@ lib_libopenvswitch_a_SOURCES = \
        lib/backtrace.h \
        lib/bitmap.c \
        lib/bitmap.h \
+       lib/byte-order.h \
        lib/byteq.c \
        lib/byteq.h \
        lib/classifier.c \
@@ -149,8 +150,7 @@ lib_libopenvswitch_a_SOURCES = \
        lib/vconn.h \
        lib/vlog-modules.def \
        lib/vlog.c \
-       lib/vlog.h \
-       lib/xtoxll.h
+       lib/vlog.h
 nodist_lib_libopenvswitch_a_SOURCES = \
        lib/coverage-counters.c \
        lib/dirs.c
diff --git a/lib/byte-order.h b/lib/byte-order.h
new file mode 100644 (file)
index 0000000..e05a71f
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008, 2010 Nicira Networks.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef BYTE_ORDER_H
+#define BYTE_ORDER_H 1
+
+#include <arpa/inet.h>
+#include <sys/types.h>
+#include <inttypes.h>
+
+static inline uint64_t
+htonll(uint64_t n)
+{
+    return htonl(1) == 1 ? n : ((uint64_t) htonl(n) << 32) | htonl(n >> 32);
+}
+
+static inline uint64_t
+ntohll(uint64_t n)
+{
+    return htonl(1) == 1 ? n : ((uint64_t) ntohl(n) << 32) | ntohl(n >> 32);
+}
+
+/* These macros may substitute for htons(), htonl(), and htonll() in contexts
+ * where function calls are not allowed, such as case labels.  They should not
+ * be used elsewhere because all of them evaluate their argument many times. */
+#ifdef WORDS_BIGENDIAN
+#define CONSTANT_HTONS(VALUE) ((uint16_t) (VALUE))
+#define CONSTANT_HTONL(VALUE) ((uint32_t) (VALUE))
+#define CONSTANT_HTONLL(VALUE) ((uint64_t) (VALUE))
+#else
+#define CONSTANT_HTONS(VALUE)                       \
+        (((((uint16_t) (VALUE)) & 0xff00) >> 8) |   \
+         ((((uint16_t) (VALUE)) & 0x00ff) << 8))
+#define CONSTANT_HTONL(VALUE)                           \
+        (((((uint32_t) (VALUE)) & 0x000000ff) << 24) |  \
+         ((((uint32_t) (VALUE)) & 0x0000ff00) <<  8) |  \
+         ((((uint32_t) (VALUE)) & 0x00ff0000) >>  8) |  \
+         ((((uint32_t) (VALUE)) & 0xff000000) >> 24))
+#define CONSTANT_HTONLL(VALUE)                                           \
+        (((((uint64_t) (VALUE)) & UINT64_C(0x00000000000000ff)) << 56) | \
+         ((((uint64_t) (VALUE)) & UINT64_C(0x000000000000ff00)) << 40) | \
+         ((((uint64_t) (VALUE)) & UINT64_C(0x0000000000ff0000)) << 24) | \
+         ((((uint64_t) (VALUE)) & UINT64_C(0x00000000ff000000)) <<  8) | \
+         ((((uint64_t) (VALUE)) & UINT64_C(0x000000ff00000000)) >>  8) | \
+         ((((uint64_t) (VALUE)) & UINT64_C(0x0000ff0000000000)) >> 24) | \
+         ((((uint64_t) (VALUE)) & UINT64_C(0x00ff000000000000)) >> 40) | \
+         ((((uint64_t) (VALUE)) & UINT64_C(0xff00000000000000)) >> 56))
+#endif
+
+#endif /* byte-order.h */
index 78c45ad..e930a6a 100644 (file)
@@ -20,6 +20,7 @@
 #include <netinet/in.h>
 #include <stdlib.h>
 #include <string.h>
+#include "byte-order.h"
 #include "coverage.h"
 #include "dynamic-string.h"
 #include "hash.h"
@@ -29,7 +30,6 @@
 #include "packets.h"
 #include "unaligned.h"
 #include "vlog.h"
-#include "xtoxll.h"
 
 VLOG_DEFINE_THIS_MODULE(flow)
 
index 741e0d0..9ed725a 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <time.h>
 
+#include "byte-order.h"
 #include "flow.h"
 #include "hmap.h"
 #include "mac-learning.h"
@@ -38,7 +39,6 @@
 #include "timeval.h"
 #include "vconn.h"
 #include "vlog.h"
-#include "xtoxll.h"
 
 VLOG_DEFINE_THIS_MODULE(learning_switch)
 
index e6af036..1f198e9 100644 (file)
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <stdlib.h>
 
+#include "byte-order.h"
 #include "dynamic-string.h"
 #include "netdev.h"
 #include "ofp-util.h"
@@ -30,7 +31,6 @@
 #include "socket-util.h"
 #include "vconn.h"
 #include "vlog.h"
-#include "xtoxll.h"
 
 VLOG_DEFINE_THIS_MODULE(ofp_parse)
 
index 2591484..7337f68 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 
+#include "byte-order.h"
 #include "compiler.h"
 #include "dynamic-string.h"
 #include "flow.h"
@@ -35,7 +36,6 @@
 #include "packets.h"
 #include "pcap.h"
 #include "util.h"
-#include "xtoxll.h"
 
 static void ofp_print_port_name(struct ds *string, uint16_t port);
 static void ofp_print_queue_name(struct ds *string, uint32_t port);
index 05c6f54..db8a49d 100644 (file)
 #include "ofp-print.h"
 #include <inttypes.h>
 #include <stdlib.h>
+#include "byte-order.h"
 #include "ofp-util.h"
 #include "ofpbuf.h"
 #include "packets.h"
 #include "random.h"
 #include "vlog.h"
-#include "xtoxll.h"
 
 VLOG_DEFINE_THIS_MODULE(ofp_util)
 
index fb167a4..4540c31 100644 (file)
@@ -18,7 +18,7 @@
 #define UNALIGNED_H 1
 
 #include <stdint.h>
-#include "xtoxll.h"
+#include "byte-order.h"
 
 /* Public API. */
 static inline uint16_t get_unaligned_u16(const uint16_t *);
diff --git a/lib/xtoxll.h b/lib/xtoxll.h
deleted file mode 100644 (file)
index a3734f1..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2008, 2010 Nicira Networks.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef XTOXLL_H
-#define XTOXLL_H 1
-
-#include <arpa/inet.h>
-#include <sys/types.h>
-#include <inttypes.h>
-
-static inline uint64_t
-htonll(uint64_t n)
-{
-    return htonl(1) == 1 ? n : ((uint64_t) htonl(n) << 32) | htonl(n >> 32);
-}
-
-static inline uint64_t
-ntohll(uint64_t n)
-{
-    return htonl(1) == 1 ? n : ((uint64_t) ntohl(n) << 32) | ntohl(n >> 32);
-}
-
-/* These macros may substitute for htons(), htonl(), and htonll() in contexts
- * where function calls are not allowed, such as case labels.  They should not
- * be used elsewhere because all of them evaluate their argument many times. */
-#ifdef WORDS_BIGENDIAN
-#define CONSTANT_HTONS(VALUE) ((uint16_t) (VALUE))
-#define CONSTANT_HTONL(VALUE) ((uint32_t) (VALUE))
-#define CONSTANT_HTONLL(VALUE) ((uint64_t) (VALUE))
-#else
-#define CONSTANT_HTONS(VALUE)                       \
-        (((((uint16_t) (VALUE)) & 0xff00) >> 8) |   \
-         ((((uint16_t) (VALUE)) & 0x00ff) << 8))
-#define CONSTANT_HTONL(VALUE)                           \
-        (((((uint32_t) (VALUE)) & 0x000000ff) << 24) |  \
-         ((((uint32_t) (VALUE)) & 0x0000ff00) <<  8) |  \
-         ((((uint32_t) (VALUE)) & 0x00ff0000) >>  8) |  \
-         ((((uint32_t) (VALUE)) & 0xff000000) >> 24))
-#define CONSTANT_HTONLL(VALUE)                                           \
-        (((((uint64_t) (VALUE)) & UINT64_C(0x00000000000000ff)) << 56) | \
-         ((((uint64_t) (VALUE)) & UINT64_C(0x000000000000ff00)) << 40) | \
-         ((((uint64_t) (VALUE)) & UINT64_C(0x0000000000ff0000)) << 24) | \
-         ((((uint64_t) (VALUE)) & UINT64_C(0x00000000ff000000)) <<  8) | \
-         ((((uint64_t) (VALUE)) & UINT64_C(0x000000ff00000000)) >>  8) | \
-         ((((uint64_t) (VALUE)) & UINT64_C(0x0000ff0000000000)) >> 24) | \
-         ((((uint64_t) (VALUE)) & UINT64_C(0x00ff000000000000)) >> 40) | \
-         ((((uint64_t) (VALUE)) & UINT64_C(0xff00000000000000)) >> 56))
-#endif
-
-#endif /* xtoxll.h */
index d9f52ba..83f71a4 100644 (file)
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include "byte-order.h"
 #include "collectors.h"
 #include "flow.h"
 #include "netflow.h"
@@ -31,7 +32,6 @@
 #include "timeval.h"
 #include "util.h"
 #include "vlog.h"
-#include "xtoxll.h"
 
 VLOG_DEFINE_THIS_MODULE(netflow)
 
index 1f2c22d..147c7f2 100644 (file)
@@ -24,6 +24,7 @@
 #include <netinet/in.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include "byte-order.h"
 #include "classifier.h"
 #include "coverage.h"
 #include "discovery.h"
@@ -58,7 +59,6 @@
 #include "unixctl.h"
 #include "vconn.h"
 #include "vlog.h"
-#include "xtoxll.h"
 
 VLOG_DEFINE_THIS_MODULE(ofproto)
 
index 34b0a80..f9c0de0 100644 (file)
@@ -61,6 +61,7 @@ lcov_wrappers = \
        tests/lcov/ovsdb-server \
        tests/lcov/ovsdb-tool \
        tests/lcov/test-aes128 \
+       tests/lcov/test-byte-order \
        tests/lcov/test-classifier \
        tests/lcov/test-csum \
        tests/lcov/test-dhcp-client \
@@ -78,8 +79,7 @@ lcov_wrappers = \
        tests/lcov/test-timeval \
        tests/lcov/test-type-props \
        tests/lcov/test-uuid \
-       tests/lcov/test-vconn \
-       tests/lcov/test-xtoxll
+       tests/lcov/test-vconn
 
 $(lcov_wrappers): tests/lcov-wrapper.in
        @test -d tests/lcov || mkdir tests/lcov
@@ -110,6 +110,7 @@ valgrind_wrappers = \
        tests/valgrind/ovsdb-server \
        tests/valgrind/ovsdb-tool \
        tests/valgrind/test-aes128 \
+       tests/valgrind/test-byte-order \
        tests/valgrind/test-classifier \
        tests/valgrind/test-csum \
        tests/valgrind/test-dhcp-client \
@@ -127,8 +128,7 @@ valgrind_wrappers = \
        tests/valgrind/test-timeval \
        tests/valgrind/test-type-props \
        tests/valgrind/test-uuid \
-       tests/valgrind/test-vconn \
-       tests/valgrind/test-xtoxll
+       tests/valgrind/test-vconn
 
 $(valgrind_wrappers): tests/valgrind-wrapper.in
        @test -d tests/valgrind || mkdir tests/valgrind
@@ -270,9 +270,9 @@ EXTRA_DIST += \
        tests/testpki-req.pem \
        tests/testpki-req2.pem
 
-noinst_PROGRAMS += tests/test-xtoxll
-tests_test_xtoxll_SOURCES = tests/test-xtoxll.c
-tests_test_xtoxll_LDADD = lib/libopenvswitch.a
+noinst_PROGRAMS += tests/test-byte-order
+tests_test_byte_order_SOURCES = tests/test-byte-order.c
+tests_test_byte_order_LDADD = lib/libopenvswitch.a
 
 # Python tests.
 EXTRA_DIST += \
index cf7505c..1dca2b8 100644 (file)
@@ -35,6 +35,6 @@ AT_CHECK([test-strtok_r], [0], [ignore])
 AT_CLEANUP
 
 AT_SETUP([test byte order conversion])
-AT_KEYWORDS([xtoxll])
-AT_CHECK([test-xtoxll], [0], [ignore])
+AT_KEYWORDS([byte order])
+AT_CHECK([test-byte-order], [0], [ignore])
 AT_CLEANUP
diff --git a/tests/test-byte-order.c b/tests/test-byte-order.c
new file mode 100644 (file)
index 0000000..1870754
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010 Nicira Networks.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <config.h>
+#include "byte-order.h"
+#include <assert.h>
+#include <inttypes.h>
+
+int
+main(void)
+{
+    /* I picked some random numbers. */
+    const uint16_t s = 0xc9bd;
+    const uint32_t l = 0xffe56ae8;
+    const uint64_t ll = UINT64_C(0xb6fe878a9117ecdb);
+
+    assert(htons(ntohs(s)) == s);
+    assert(ntohs(htons(s)) == s);
+    assert(CONSTANT_HTONS(ntohs(s)) == s);
+    assert(ntohs(CONSTANT_HTONS(s)) == s);
+    assert(ntohs(CONSTANT_HTONS(l)) == (uint16_t) l);
+    assert(ntohs(CONSTANT_HTONS(ll)) == (uint16_t) ll);
+
+    assert(htonl(ntohl(l)) == l);
+    assert(ntohl(htonl(l)) == l);
+    assert(CONSTANT_HTONL(ntohl(l)) == l);
+    assert(ntohl(CONSTANT_HTONL(l)) == l);
+    assert(ntohl(CONSTANT_HTONL(ll)) == (uint32_t) ll);
+
+    assert(htonll(ntohll(ll)) == ll);
+    assert(ntohll(htonll(ll)) == ll);
+    assert(CONSTANT_HTONLL(ntohll(ll)) == ll);
+    assert(ntohll(CONSTANT_HTONLL(ll)));
+
+    return 0;
+}
index 73229c2..fe7155b 100644 (file)
 #include "classifier.h"
 #include <errno.h>
 #include <limits.h>
+#include "byte-order.h"
 #include "command-line.h"
 #include "flow.h"
 #include "packets.h"
-#include "xtoxll.h"
 
 #undef NDEBUG
 #include <assert.h>
diff --git a/tests/test-xtoxll.c b/tests/test-xtoxll.c
deleted file mode 100644 (file)
index b658b86..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2010 Nicira Networks.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <config.h>
-#include "xtoxll.h"
-#include <assert.h>
-#include <inttypes.h>
-
-int
-main(void)
-{
-    /* I picked some random numbers. */
-    const uint16_t s = 0xc9bd;
-    const uint32_t l = 0xffe56ae8;
-    const uint64_t ll = UINT64_C(0xb6fe878a9117ecdb);
-
-    assert(htons(ntohs(s)) == s);
-    assert(ntohs(htons(s)) == s);
-    assert(CONSTANT_HTONS(ntohs(s)) == s);
-    assert(ntohs(CONSTANT_HTONS(s)) == s);
-    assert(ntohs(CONSTANT_HTONS(l)) == (uint16_t) l);
-    assert(ntohs(CONSTANT_HTONS(ll)) == (uint16_t) ll);
-
-    assert(htonl(ntohl(l)) == l);
-    assert(ntohl(htonl(l)) == l);
-    assert(CONSTANT_HTONL(ntohl(l)) == l);
-    assert(ntohl(CONSTANT_HTONL(l)) == l);
-    assert(ntohl(CONSTANT_HTONL(ll)) == (uint32_t) ll);
-
-    assert(htonll(ntohll(ll)) == ll);
-    assert(ntohll(htonll(ll)) == ll);
-    assert(CONSTANT_HTONLL(ntohll(ll)) == ll);
-    assert(ntohll(CONSTANT_HTONLL(ll)));
-
-    return 0;
-}
index 13f583e..cf6a8a3 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
+#include "byte-order.h"
 #include "command-line.h"
 #include "compiler.h"
 #include "dirs.h"
@@ -44,7 +45,6 @@
 #include "util.h"
 #include "vconn.h"
 #include "vlog.h"
-#include "xtoxll.h"
 
 VLOG_DEFINE_THIS_MODULE(ofctl)
 
index 41fcba5..20cfef7 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <config.h>
 #include "bridge.h"
+#include "byte-order.h"
 #include <assert.h>
 #include <errno.h>
 #include <arpa/inet.h>
@@ -65,7 +66,6 @@
 #include "vswitchd/vswitch-idl.h"
 #include "xenserver.h"
 #include "vlog.h"
-#include "xtoxll.h"
 #include "sflow_api.h"
 
 VLOG_DEFINE_THIS_MODULE(bridge)