Skip to content

Commit bab474c

Browse files
committed
Add external stp library in service bridge
This C library will manage all the configurations of each STP instance. Each instance of class Stp will have an instance of struct stp as a counterpart, and the same will be for PortsStp class. Therefore, these classes will interact with the library in order to get the correct configuration of each parameter (state of the ports and so on). Signed-off-by: Gianluca Scopelliti <gianlu.1033@gmail.com>
1 parent 10e21c8 commit bab474c

12 files changed

Lines changed: 2413 additions & 1 deletion

File tree

src/services/pcn-bridge/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ cmake_minimum_required (VERSION 3.2)
22

33
set (CMAKE_CXX_STANDARD 11)
44

5+
include_directories(external)
56
add_subdirectory(src)
7+
add_subdirectory(external/stp)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include_directories(${CMAKE_SOURCE_DIR}/external/stp)
2+
add_library(stp STATIC stp.c dependencies.c log.cpp)
3+
target_link_libraries(stp pthread)
4+
set_property(TARGET stp PROPERTY POSITION_INDEPENDENT_CODE ON)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2008, 2010, 2011, 2013 Nicira, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#ifndef BYTE_ORDER_H
17+
#define BYTE_ORDER_H 1
18+
19+
#include <arpa/inet.h>
20+
#include <inttypes.h>
21+
#include <sys/types.h>
22+
#include "types.h"
23+
24+
#ifndef __CHECKER__
25+
#ifndef _WIN32
26+
static inline ovs_be64 htonll(uint64_t n) {
27+
return htonl(1) == 1 ? n : ((uint64_t)htonl(n) << 32) | htonl(n >> 32);
28+
}
29+
30+
static inline uint64_t ntohll(ovs_be64 n) {
31+
return htonl(1) == 1 ? n : ((uint64_t)ntohl(n) << 32) | ntohl(n >> 32);
32+
}
33+
#endif /* _WIN32 */
34+
#else
35+
/* Making sparse happy with these functions also makes them unreadable, so
36+
* don't bother to show it their implementations. */
37+
ovs_be64 htonll(uint64_t);
38+
uint64_t ntohll(ovs_be64);
39+
#endif
40+
41+
static inline uint32_t uint32_byteswap(uint32_t crc) {
42+
return (((crc & 0x000000ff) << 24) | ((crc & 0x0000ff00) << 8) |
43+
((crc & 0x00ff0000) >> 8) | ((crc & 0xff000000) >> 24));
44+
}
45+
46+
/* These macros may substitute for htons(), htonl(), and htonll() in contexts
47+
* where function calls are not allowed, such as case labels. They should not
48+
* be used elsewhere because all of them evaluate their argument many times. */
49+
#if defined(WORDS_BIGENDIAN) || __CHECKER__
50+
#define CONSTANT_HTONS(VALUE) ((OVS_FORCE ovs_be16)((VALUE)&0xffff))
51+
#define CONSTANT_HTONL(VALUE) ((OVS_FORCE ovs_be32)((VALUE)&0xffffffff))
52+
#define CONSTANT_HTONLL(VALUE) \
53+
((OVS_FORCE ovs_be64)((VALUE)&UINT64_C(0xffffffffffffffff)))
54+
#else
55+
#define CONSTANT_HTONS(VALUE) \
56+
(((((ovs_be16)(VALUE)) & 0xff00) >> 8) | \
57+
((((ovs_be16)(VALUE)) & 0x00ff) << 8))
58+
#define CONSTANT_HTONL(VALUE) \
59+
(((((ovs_be32)(VALUE)) & 0x000000ff) << 24) | \
60+
((((ovs_be32)(VALUE)) & 0x0000ff00) << 8) | \
61+
((((ovs_be32)(VALUE)) & 0x00ff0000) >> 8) | \
62+
((((ovs_be32)(VALUE)) & 0xff000000) >> 24))
63+
#define CONSTANT_HTONLL(VALUE) \
64+
(((((ovs_be64)(VALUE)) & UINT64_C(0x00000000000000ff)) << 56) | \
65+
((((ovs_be64)(VALUE)) & UINT64_C(0x000000000000ff00)) << 40) | \
66+
((((ovs_be64)(VALUE)) & UINT64_C(0x0000000000ff0000)) << 24) | \
67+
((((ovs_be64)(VALUE)) & UINT64_C(0x00000000ff000000)) << 8) | \
68+
((((ovs_be64)(VALUE)) & UINT64_C(0x000000ff00000000)) >> 8) | \
69+
((((ovs_be64)(VALUE)) & UINT64_C(0x0000ff0000000000)) >> 24) | \
70+
((((ovs_be64)(VALUE)) & UINT64_C(0x00ff000000000000)) >> 40) | \
71+
((((ovs_be64)(VALUE)) & UINT64_C(0xff00000000000000)) >> 56))
72+
#endif
73+
74+
#if WORDS_BIGENDIAN
75+
#define BYTES_TO_BE32(B1, B2, B3, B4) \
76+
(OVS_FORCE ovs_be32)((uint32_t)(B1) << 24 | (B2) << 16 | (B3) << 8 | (B4))
77+
#define BE16S_TO_BE32(B1, B2) (OVS_FORCE ovs_be32)((uint32_t)(B1) << 16 | (B2))
78+
#else
79+
#define BYTES_TO_BE32(B1, B2, B3, B4) \
80+
(OVS_FORCE ovs_be32)((uint32_t)(B1) | (B2) << 8 | (B3) << 16 | (B4) << 24)
81+
#define BE16S_TO_BE32(B1, B2) (OVS_FORCE ovs_be32)((uint32_t)(B1) | (B2) << 16)
82+
#endif
83+
84+
#endif /* byte-order.h */
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*
2+
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef COMPILER_H
18+
#define COMPILER_H 1
19+
20+
#ifndef __has_feature
21+
#define __has_feature(x) 0
22+
#endif
23+
#ifndef __has_extension
24+
#define __has_extension(x) 0
25+
#endif
26+
27+
#if __GNUC__ && !__CHECKER__
28+
#define NO_RETURN __attribute__((__noreturn__))
29+
#define OVS_UNUSED __attribute__((__unused__))
30+
#define PRINTF_FORMAT(FMT, ARG1) __attribute__((__format__(printf, FMT, ARG1)))
31+
#define SCANF_FORMAT(FMT, ARG1) __attribute__((__format__(scanf, FMT, ARG1)))
32+
#define STRFTIME_FORMAT(FMT) __attribute__((__format__(__strftime__, FMT, 0)))
33+
#define MALLOC_LIKE __attribute__((__malloc__))
34+
#define ALWAYS_INLINE __attribute__((always_inline))
35+
#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
36+
#define SENTINEL(N) __attribute__((sentinel(N)))
37+
#define OVS_LIKELY(CONDITION) __builtin_expect(!!(CONDITION), 1)
38+
#define OVS_UNLIKELY(CONDITION) __builtin_expect(!!(CONDITION), 0)
39+
#else
40+
#define NO_RETURN
41+
#define OVS_UNUSED
42+
#define PRINTF_FORMAT(FMT, ARG1)
43+
#define SCANF_FORMAT(FMT, ARG1)
44+
#define STRFTIME_FORMAT(FMT)
45+
#define MALLOC_LIKE
46+
#define ALWAYS_INLINE
47+
#define WARN_UNUSED_RESULT
48+
#define SENTINEL(N)
49+
#define OVS_LIKELY(CONDITION) (!!(CONDITION))
50+
#define OVS_UNLIKELY(CONDITION) (!!(CONDITION))
51+
#endif
52+
53+
#if __has_feature(c_thread_safety_attributes)
54+
/* "clang" annotations for thread safety check.
55+
*
56+
* OVS_LOCKABLE indicates that the struct contains mutex element
57+
* which can be locked by functions like ovs_mutex_lock().
58+
*
59+
* Below, the word MUTEX stands for the name of an object with an OVS_LOCKABLE
60+
* struct type. It can also be a comma-separated list of multiple structs,
61+
* e.g. to require a function to hold multiple locks while invoked.
62+
*
63+
*
64+
* On a variable:
65+
*
66+
* - OVS_GUARDED indicates that the variable may only be accessed some mutex
67+
* is held.
68+
*
69+
* - OVS_GUARDED_BY(MUTEX) indicates that the variable may only be accessed
70+
* while the specific MUTEX is held.
71+
*
72+
*
73+
* On a variable A of mutex type:
74+
*
75+
* - OVS_ACQ_BEFORE(B), where B is a mutex or a comma-separated list of
76+
* mutexes, declare that if both A and B are acquired at the same time,
77+
* then A must be acquired before B. That is, B nests inside A.
78+
*
79+
* - OVS_ACQ_AFTER(B) is the opposite of OVS_ACQ_BEFORE(B), that is, it
80+
* declares that A nests inside B.
81+
*
82+
*
83+
* On a function, the following attributes apply to mutexes:
84+
*
85+
* - OVS_ACQUIRES(MUTEX) indicate that the function must be called without
86+
* holding MUTEX and that it returns holding MUTEX.
87+
*
88+
* - OVS_RELEASES(MUTEX) indicates that the function may only be called with
89+
* MUTEX held and that it returns with MUTEX released. It can be used for
90+
* all types of MUTEX.
91+
*
92+
* - OVS_TRY_LOCK(RETVAL, MUTEX) indicate that the function will try to
93+
* acquire MUTEX. RETVAL is an integer or boolean value specifying the
94+
* return value of a successful lock acquisition.
95+
*
96+
* - OVS_REQUIRES(MUTEX) indicate that the function may only be called with
97+
* MUTEX held and that the function does not release MUTEX.
98+
*
99+
* - OVS_EXCLUDED(MUTEX) indicates that the function may only be called when
100+
* MUTEX is not held.
101+
*
102+
*
103+
* The following variants, with the same syntax, apply to reader-writer locks:
104+
*
105+
* mutex rwlock, for reading rwlock, for writing
106+
* ------------------- ------------------- -------------------
107+
* OVS_ACQUIRES OVS_ACQ_RDLOCK OVS_ACQ_WRLOCK
108+
* OVS_RELEASES OVS_RELEASES OVS_RELEASES
109+
* OVS_TRY_LOCK OVS_TRY_RDLOCK OVS_TRY_WRLOCK
110+
* OVS_REQUIRES OVS_REQ_RDLOCK OVS_REQ_WRLOCK
111+
* OVS_EXCLUDED OVS_EXCLUDED OVS_EXCLUDED
112+
*/
113+
#define OVS_LOCKABLE __attribute__((lockable))
114+
#define OVS_REQ_RDLOCK(...) __attribute__((shared_locks_required(__VA_ARGS__)))
115+
#define OVS_ACQ_RDLOCK(...) __attribute__((shared_lock_function(__VA_ARGS__)))
116+
#define OVS_REQ_WRLOCK(...) \
117+
__attribute__((exclusive_locks_required(__VA_ARGS__)))
118+
#define OVS_ACQ_WRLOCK(...) \
119+
__attribute__((exclusive_lock_function(__VA_ARGS__)))
120+
#define OVS_REQUIRES(...) __attribute__((exclusive_locks_required(__VA_ARGS__)))
121+
#define OVS_ACQUIRES(...) __attribute__((exclusive_lock_function(__VA_ARGS__)))
122+
#define OVS_TRY_WRLOCK(RETVAL, ...) \
123+
__attribute__((exclusive_trylock_function(RETVAL, __VA_ARGS__)))
124+
#define OVS_TRY_RDLOCK(RETVAL, ...) \
125+
__attribute__((shared_trylock_function(RETVAL, __VA_ARGS__)))
126+
#define OVS_TRY_LOCK(RETVAL, ...) \
127+
__attribute__((exclusive_trylock_function(RETVAL, __VA_ARGS__)))
128+
#define OVS_GUARDED __attribute__((guarded_var))
129+
#define OVS_GUARDED_BY(...) __attribute__((guarded_by(__VA_ARGS__)))
130+
#define OVS_RELEASES(...) __attribute__((unlock_function(__VA_ARGS__)))
131+
#define OVS_EXCLUDED(...) __attribute__((locks_excluded(__VA_ARGS__)))
132+
#define OVS_ACQ_BEFORE(...) __attribute__((acquired_before(__VA_ARGS__)))
133+
#define OVS_ACQ_AFTER(...) __attribute__((acquired_after(__VA_ARGS__)))
134+
#define OVS_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
135+
#else /* not Clang */
136+
#define OVS_LOCKABLE
137+
#define OVS_REQ_RDLOCK(...)
138+
#define OVS_ACQ_RDLOCK(...)
139+
#define OVS_REQ_WRLOCK(...)
140+
#define OVS_ACQ_WRLOCK(...)
141+
#define OVS_REQUIRES(...)
142+
#define OVS_ACQUIRES(...)
143+
#define OVS_TRY_WRLOCK(...)
144+
#define OVS_TRY_RDLOCK(...)
145+
#define OVS_TRY_LOCK(...)
146+
#define OVS_GUARDED
147+
#define OVS_GUARDED_BY(...)
148+
#define OVS_EXCLUDED(...)
149+
#define OVS_RELEASES(...)
150+
#define OVS_ACQ_BEFORE(...)
151+
#define OVS_ACQ_AFTER(...)
152+
#define OVS_NO_THREAD_SAFETY_ANALYSIS
153+
#endif
154+
155+
/* ISO C says that a C implementation may choose any integer type for an enum
156+
* that is sufficient to hold all of its values. Common ABIs (such as the
157+
* System V ABI used on i386 GNU/Linux) always use a full-sized "int", even
158+
* when a smaller type would suffice.
159+
*
160+
* In GNU C, "enum __attribute__((packed)) name { ... }" defines 'name' as an
161+
* enum compatible with a type that is no bigger than necessary. This is the
162+
* intended use of OVS_PACKED_ENUM.
163+
*
164+
* OVS_PACKED_ENUM is intended for use only as a space optimization, since it
165+
* only works with GCC. That means that it must not be used in wire protocols
166+
* or otherwise exposed outside of a single process. */
167+
#if __GNUC__ && !__CHECKER__
168+
#define OVS_PACKED_ENUM __attribute__((__packed__))
169+
#define HAVE_PACKED_ENUM
170+
#else
171+
#define OVS_PACKED_ENUM
172+
#endif
173+
174+
#ifndef _MSC_VER
175+
#define OVS_PACKED(DECL) DECL __attribute__((__packed__))
176+
#else
177+
#define OVS_PACKED(DECL) __pragma(pack(push, 1)) DECL __pragma(pack(pop))
178+
#endif
179+
180+
/* For defining a structure whose instances should aligned on an N-byte
181+
* boundary.
182+
*
183+
* e.g. The following:
184+
* OVS_ALIGNED_STRUCT(64, mystruct) { ... };
185+
* is equivalent to the following except that it specifies 64-byte alignment:
186+
* struct mystruct { ... };
187+
*/
188+
#ifndef _MSC_VER
189+
#define OVS_ALIGNED_STRUCT(N, TAG) struct __attribute__((aligned(N))) TAG
190+
#else
191+
#define OVS_ALIGNED_STRUCT(N, TAG) __declspec(align(N)) struct TAG
192+
#endif
193+
194+
#ifdef _MSC_VER
195+
#define CCALL __cdecl
196+
#pragma section(".CRT$XCU", read)
197+
#define OVS_CONSTRUCTOR(f) \
198+
static void __cdecl f(void); \
199+
__declspec(allocate(".CRT$XCU")) void(__cdecl * f##_)(void) = f; \
200+
static void __cdecl f(void)
201+
#else
202+
#define OVS_CONSTRUCTOR(f) \
203+
static void f(void) __attribute__((constructor)); \
204+
static void f(void)
205+
#endif
206+
207+
/* OVS_PREFETCH() can be used to instruct the CPU to fetch the cache
208+
* line containing the given address to a CPU cache.
209+
* OVS_PREFETCH_WRITE() should be used when the memory is going to be
210+
* written to. Depending on the target CPU, this can generate the same
211+
* instruction as OVS_PREFETCH(), or bring the data into the cache in an
212+
* exclusive state. */
213+
#if __GNUC__
214+
#define OVS_PREFETCH(addr) __builtin_prefetch((addr))
215+
#define OVS_PREFETCH_WRITE(addr) __builtin_prefetch((addr), 1)
216+
#else
217+
#define OVS_PREFETCH(addr)
218+
#define OVS_PREFETCH_WRITE(addr)
219+
#endif
220+
221+
/* Output a message (not an error) while compiling without failing the
222+
* compilation process */
223+
#if HAVE_PRAGMA_MESSAGE
224+
#define DO_PRAGMA(x) _Pragma(#x)
225+
#define BUILD_MESSAGE(x) DO_PRAGMA(message(x))
226+
#else
227+
#define BUILD_MESSAGE(x)
228+
#endif
229+
230+
#endif /* compiler.h */

0 commit comments

Comments
 (0)