From: Ben Pfaff Date: Fri, 29 Oct 2010 00:13:18 +0000 (-0700) Subject: xtoxll: Rename "byte-order" since it now include more than xtoxll. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10a24935c9d382e4d85b05d9616843f3d3bb4983;p=openvswitch xtoxll: Rename "byte-order" since it now include more than xtoxll. Suggested-by: Justin Pettit --- diff --git a/lib/automake.mk b/lib/automake.mk index c502a3bd..5cfac240 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -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 index 00000000..e05a71fb --- /dev/null +++ b/lib/byte-order.h @@ -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 +#include +#include + +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 */ diff --git a/lib/flow.c b/lib/flow.c index 78c45ade..e930a6a4 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -20,6 +20,7 @@ #include #include #include +#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) diff --git a/lib/learning-switch.c b/lib/learning-switch.c index 741e0d0e..9ed725a7 100644 --- a/lib/learning-switch.c +++ b/lib/learning-switch.c @@ -23,6 +23,7 @@ #include #include +#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) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index e6af0362..1f198e9c 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -21,6 +21,7 @@ #include #include +#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) diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 2591484a..7337f681 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -26,6 +26,7 @@ #include #include +#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); diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 05c6f546..db8a49d0 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -18,12 +18,12 @@ #include "ofp-print.h" #include #include +#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) diff --git a/lib/unaligned.h b/lib/unaligned.h index fb167a4e..4540c31b 100644 --- a/lib/unaligned.h +++ b/lib/unaligned.h @@ -18,7 +18,7 @@ #define UNALIGNED_H 1 #include -#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 index a3734f10..00000000 --- a/lib/xtoxll.h +++ /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 -#include -#include - -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 */ diff --git a/ofproto/netflow.c b/ofproto/netflow.c index d9f52ba5..83f71a4e 100644 --- a/ofproto/netflow.c +++ b/ofproto/netflow.c @@ -20,6 +20,7 @@ #include #include #include +#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) diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 1f2c22d1..147c7f22 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -24,6 +24,7 @@ #include #include #include +#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) diff --git a/tests/automake.mk b/tests/automake.mk index 34b0a801..f9c0de0e 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -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 += \ diff --git a/tests/library.at b/tests/library.at index cf7505c9..1dca2b85 100644 --- a/tests/library.at +++ b/tests/library.at @@ -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 index 00000000..18707545 --- /dev/null +++ b/tests/test-byte-order.c @@ -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 +#include "byte-order.h" +#include +#include + +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; +} diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 73229c2e..fe7155bb 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -29,10 +29,10 @@ #include "classifier.h" #include #include +#include "byte-order.h" #include "command-line.h" #include "flow.h" #include "packets.h" -#include "xtoxll.h" #undef NDEBUG #include diff --git a/tests/test-xtoxll.c b/tests/test-xtoxll.c deleted file mode 100644 index b658b869..00000000 --- a/tests/test-xtoxll.c +++ /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 -#include "xtoxll.h" -#include -#include - -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; -} diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 13f583e7..cf6a8a30 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -26,6 +26,7 @@ #include #include +#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) diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 41fcba52..20cfef7d 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -15,6 +15,7 @@ #include #include "bridge.h" +#include "byte-order.h" #include #include #include @@ -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)