Add basic support for DS-Lite CE (VPP-1059)
[vpp.git] / src / plugins / nat / dslite_dpo.c
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vnet/ip/ip.h>
17 #include <nat/dslite_dpo.h>
18
19 dpo_type_t dslite_dpo_type;
20 dpo_type_t dslite_ce_dpo_type;
21
22 void
23 dslite_dpo_create (dpo_proto_t dproto, u32 aftr_index, dpo_id_t * dpo)
24 {
25   dpo_set (dpo, dslite_dpo_type, dproto, aftr_index);
26 }
27
28 void
29 dslite_ce_dpo_create (dpo_proto_t dproto, u32 b4_index, dpo_id_t * dpo)
30 {
31   dpo_set (dpo, dslite_ce_dpo_type, dproto, b4_index);
32 }
33
34 u8 *
35 format_dslite_dpo (u8 * s, va_list * args)
36 {
37   index_t index = va_arg (*args, index_t);
38   CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
39
40   return (format (s, "DS-Lite: AFTR:%d", index));
41 }
42
43 u8 *
44 format_dslite_ce_dpo (u8 * s, va_list * args)
45 {
46   index_t index = va_arg (*args, index_t);
47   CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
48
49   return (format (s, "DS-Lite: B4:%d", index));
50 }
51
52 static void
53 dslite_dpo_lock (dpo_id_t * dpo)
54 {
55 }
56
57 static void
58 dslite_dpo_unlock (dpo_id_t * dpo)
59 {
60 }
61
62 static void
63 dslite_ce_dpo_lock (dpo_id_t * dpo)
64 {
65 }
66
67 static void
68 dslite_ce_dpo_unlock (dpo_id_t * dpo)
69 {
70 }
71
72 const static dpo_vft_t dslite_dpo_vft = {
73   .dv_lock = dslite_dpo_lock,
74   .dv_unlock = dslite_dpo_unlock,
75   .dv_format = format_dslite_dpo,
76 };
77
78 const static dpo_vft_t dslite_ce_dpo_vft = {
79   .dv_lock = dslite_ce_dpo_lock,
80   .dv_unlock = dslite_ce_dpo_unlock,
81   .dv_format = format_dslite_ce_dpo,
82 };
83
84 const static char *const dslite_ip4_nodes[] = {
85   "dslite-out2in",
86   NULL,
87 };
88
89 const static char *const dslite_ip6_nodes[] = {
90   "dslite-in2out",
91   NULL,
92 };
93
94 const static char *const dslite_ce_ip4_nodes[] = {
95   "dslite-ce-encap",
96   NULL,
97 };
98
99 const static char *const dslite_ce_ip6_nodes[] = {
100   "dslite-ce-decap",
101   NULL,
102 };
103
104 const static char *const *const dslite_nodes[DPO_PROTO_NUM] = {
105   [DPO_PROTO_IP4] = dslite_ip4_nodes,
106   [DPO_PROTO_IP6] = dslite_ip6_nodes,
107   [DPO_PROTO_MPLS] = NULL,
108 };
109
110 const static char *const *const dslite_ce_nodes[DPO_PROTO_NUM] = {
111   [DPO_PROTO_IP4] = dslite_ce_ip4_nodes,
112   [DPO_PROTO_IP6] = dslite_ce_ip6_nodes,
113   [DPO_PROTO_MPLS] = NULL,
114 };
115
116 void
117 dslite_dpo_module_init (void)
118 {
119   dslite_dpo_type = dpo_register_new_type (&dslite_dpo_vft, dslite_nodes);
120   dslite_ce_dpo_type = dpo_register_new_type (&dslite_ce_dpo_vft,
121                                               dslite_ce_nodes);
122 }
123
124 /*
125  * fd.io coding-style-patch-verification: ON
126  *
127  * Local Variables:
128  * eval: (c-set-style "gnu")
129  * End:
130  */