nat: 1:1 policy NAT
[vpp.git] / src / plugins / nat / CMakeLists.txt
1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 set(CMAKE_VERBOSE_MAKEFILE ON)
15
16 add_vpp_library(nat
17   SOURCES
18   lib/ipfix_logging.c
19   lib/nat_syslog.c
20   lib/alloc.c
21
22   INSTALL_HEADERS
23   lib/ipfix_logging.h
24   lib/nat_syslog.h
25   lib/alloc.h
26 )
27
28 add_vpp_plugin(nat
29   SOURCES
30   nat.c
31   nat44_api.c
32   in2out_ed.c
33   out2in_ed.c
34   nat_dpo.c
35   nat44_cli.c
36   nat44_handoff.c
37   nat44_hairpinning.c
38   nat44_classify.c
39   nat_affinity.c
40   nat_format.c
41   nat44-ei/nat44_ei.c
42   nat44-ei/nat44_ei_ha.c
43   nat44-ei/nat44_ei_in2out.c
44   nat44-ei/nat44_ei_out2in.c
45
46   MULTIARCH_SOURCES
47   in2out_ed.c
48   out2in_ed.c
49   nat44_classify.c
50   nat44_hairpinning.c
51   nat44_handoff.c
52   nat44-ei/nat44_ei_in2out.c
53   nat44-ei/nat44_ei_out2in.c
54
55   API_FILES
56   nat44.api
57   nat_types.api
58
59   LINK_LIBRARIES nat
60 )
61
62 add_vpp_plugin(dslite
63   SOURCES
64   dslite/dslite_api.c
65   dslite/dslite_dpo.c
66   dslite/dslite.c
67   dslite/dslite_in2out.c
68   dslite/dslite_out2in.c
69   dslite/dslite_cli.c
70   dslite/dslite_ce_encap.c
71   dslite/dslite_ce_decap.c
72
73   MULTIARCH_SOURCES
74   dslite/dslite_ce_decap.c
75   dslite/dslite_ce_encap.c
76   dslite/dslite_in2out.c
77   dslite/dslite_out2in.c
78
79   API_FILES
80   dslite/dslite.api
81
82   LINK_LIBRARIES nat
83 )
84
85 add_vpp_plugin(nat66
86   SOURCES
87   nat66/nat66.c
88   nat66/nat66_cli.c
89   nat66/nat66_api.c
90   nat66/nat66_in2out.c
91   nat66/nat66_out2in.c
92
93   MULTIARCH_SOURCES
94   nat66/nat66_in2out.c
95   nat66/nat66_out2in.c
96
97   API_FILES
98   nat66/nat66.api
99   nat_types.api
100
101   LINK_LIBRARIES nat
102 )
103
104 add_vpp_plugin(det44
105   SOURCES
106   det44/det44.c
107   det44/det44_cli.c
108   det44/det44_api.c
109   det44/det44_in2out.c
110   det44/det44_out2in.c
111
112   MULTIARCH_SOURCES
113   det44/det44_in2out.c
114   det44/det44_out2in.c
115
116   API_FILES
117   det44/det44.api
118   nat_types.api
119
120   LINK_LIBRARIES nat
121 )
122
123 add_vpp_plugin(nat64
124   SOURCES
125   nat64/nat64.c
126   nat64/nat64_db.c
127   nat64/nat64_cli.c
128   nat64/nat64_api.c
129   nat64/nat64_in2out.c
130   nat64/nat64_out2in.c
131
132   MULTIARCH_SOURCES
133   nat64/nat64_in2out.c
134   nat64/nat64_out2in.c
135
136   API_FILES
137   nat64/nat64.api
138   nat_types.api
139
140   LINK_LIBRARIES nat
141 )
142
143 add_vpp_plugin(pnat
144   SOURCES
145   pnat/pnat.c
146   pnat/pnat_cli.c
147   pnat/pnat_api.c
148   pnat/pnat_node.c
149
150   API_FILES
151   pnat/pnat.api
152 )
153
154 # Unit tests
155 add_vpp_executable(test_pnat
156   SOURCES
157   pnat/pnat_test.c
158   pnat/pnat_node.c
159   pnat/pnat.c
160   ../../vnet/ip/ip_checksum.c
161   LINK_LIBRARIES vppinfra vlib
162   NO_INSTALL
163 )
164
165 if("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.13" AND "${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
166   set(TARGET_NAME test_pnat)
167   set(COV_SOURCES ${CMAKE_SOURCE_DIR}/plugins/nat/pnat/pnat.c ${CMAKE_SOURCE_DIR}/plugins/nat/pnat/pnat_node.h ${CMAKE_SOURCE_DIR}/plugins/nat/pnat/pnat_node.c)
168
169   message("Building with llvm Code Coverage Tools ${TARGET_NAME}")
170   target_compile_options(${TARGET_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
171   target_link_options(${TARGET_NAME} PRIVATE -fprofile-instr-generate -fcoverage-mapping)
172   target_compile_options(${TARGET_NAME} PRIVATE -fsanitize=address)
173   target_link_options(${TARGET_NAME} PRIVATE -fsanitize=address)
174
175   # llvm-cov
176   add_custom_target(${TARGET_NAME}-ccov-preprocessing
177     COMMAND LLVM_PROFILE_FILE=${TARGET_NAME}.profraw $<TARGET_FILE:${TARGET_NAME}>
178     COMMAND llvm-profdata merge -sparse ${TARGET_NAME}.profraw -o ${TARGET_NAME}.profdata
179     DEPENDS ${TARGET_NAME})
180
181   add_custom_target(${TARGET_NAME}-ccov-show
182     COMMAND llvm-cov show $<TARGET_FILE:${TARGET_NAME}> -instr-profile=${TARGET_NAME}.profdata -show-line-counts-or-regions ${COV_SOURCES}
183     DEPENDS ${TARGET_NAME}-ccov-preprocessing)
184
185   add_custom_target(${TARGET_NAME}-ccov-report
186     COMMAND llvm-cov report -show-functions $<TARGET_FILE:${TARGET_NAME}> -instr-profile=${TARGET_NAME}.profdata ${COV_SOURCES}
187     DEPENDS ${TARGET_NAME}-ccov-preprocessing)
188
189   add_custom_target(${TARGET_NAME}-ccov
190     COMMAND llvm-cov show $<TARGET_FILE:${TARGET_NAME}> -instr-profile=${TARGET_NAME}.profdata -show-line-counts-or-regions -output-dir=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}-llvm-cov -format="html" ${COV_SOURCES}
191     DEPENDS ${TARGET_NAME}-ccov-preprocessing)
192
193   add_custom_command(TARGET ${TARGET_NAME}-ccov POST_BUILD
194     COMMAND ;
195     COMMENT "Open ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}-llvm-cov/index.html in your browser to view the coverage report."
196 )
197 endif()