This commit removes the '#include' of Open Vswitch specific library
in 'bfd.c'.  Instead, an auxiliary header 'bfd-aux.h' is created to
allow user of generic BFD state machine to define those platform
dependent functions.

Signed-off-by: Alex Wang <al...@nicira.com>
---
 lib/automake.mk |    1 +
 lib/bfd-aux.h   |   37 +++++++++++++++++++++++++++++++++++++
 lib/bfd.c       |    8 +++++---
 3 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 lib/bfd-aux.h

diff --git a/lib/automake.mk b/lib/automake.mk
index 2b3077e..9b315ee 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -23,6 +23,7 @@ lib_libopenvswitch_la_SOURCES = \
        lib/backtrace.h \
        lib/bfd.c \
        lib/bfd.h \
+       lib/bfd-aux.h \
        lib/bfd-ovs.c \
        lib/bfd-ovs.h \
        lib/bitmap.c \
diff --git a/lib/bfd-aux.h b/lib/bfd-aux.h
new file mode 100644
index 0000000..9f9db71
--- /dev/null
+++ b/lib/bfd-aux.h
@@ -0,0 +1,37 @@
+/* Copyright (c) 2014, 2013 Nicira, Inc.
+ *
+ * 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 BFD_AUX_H
+#define BFD_AUX_H 1
+
+/* The following functions and macros are used in bfd.c, but due to platform
+ * differences, not implemented.  Users are responsible for bridging the gap
+ * with the correct implementation.
+ *
+ *
+ * Random Number Generation
+ * ------------------------
+ *
+ *     bfd_get_random()
+ *
+ *         This should be a thread-safe function and returns a random unsigned
+ *         integer, which will be used as the jitter in bfd_set_next_ts().
+ *
+ * */
+
+#include "random.h"
+
+#define bfd_get_random() random_uint32()
+
+#endif /* bfd-aux.h */
diff --git a/lib/bfd.c b/lib/bfd.c
index ceb9b39..4ba2093 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -14,13 +14,15 @@
 
 #include <config.h>
 #include "bfd.h"
+#include "bfd-aux.h"
 
 #include <arpa/inet.h>
 #include <inttypes.h>
+#include <limits.h>
 #include <string.h>
 
-#include "random.h"
-#include "util.h"
+#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
 
 
 static long long int
@@ -53,7 +55,7 @@ static void
 bfd_set_next_tx(struct bfd *bfd)
 {
     long long int interval = bfd_tx_interval(bfd);
-    interval -= interval * (random_uint32() % 26) / 100;
+    interval -= interval * (bfd_get_random() % 26) / 100;
     bfd->next_tx = bfd->last_tx + interval;
 }
 
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to