FD.io VPP  v20.05-21-gb1500e9ff
Vector Packet Processing
lisp_types_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  *
4  * Copyright (c) 2020 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *------------------------------------------------------------------
17  */
18 
20 #include <vnet/ip/ip_types_api.h>
22 
23 int
24 unformat_lisp_eid_api (gid_address_t * dst, u32 vni, const vl_api_eid_t * eid)
25 {
26  switch (eid->type)
27  {
28  case EID_TYPE_API_PREFIX: /* ip prefix */
30  ip_address_decode2 (&eid->address.prefix.address, &dst->ippref.addr);
31  gid_address_ippref_len (dst) = eid->address.prefix.len;
33  break;
34  case EID_TYPE_API_MAC: /* l2 mac */
36  mac_address_decode (eid->address.mac, (mac_address_t *) gid_address_mac (dst));
37  break;
38  default:
39  /* unknown type */
40  return VNET_API_ERROR_INVALID_VALUE;
41  }
42 
43  gid_address_vni (dst) = clib_net_to_host_u32 (vni);
44 
45  return 0;
46 }
47 
48 void
49 lisp_fid_put_api (vl_api_eid_t * eid, const fid_address_t * fid)
50 {
51  switch (fid_addr_type (fid))
52  {
53  case FID_ADDR_IP_PREF:
54  ip_prefix_encode2 (&fid_addr_ippref (fid), &eid->address.prefix);
55  eid->type = EID_TYPE_API_PREFIX;
56  break;
57 
58  case FID_ADDR_MAC:
59  mac_address_encode ((mac_address_t *) fid_addr_mac (fid), eid->address.mac);
60  eid->type = EID_TYPE_API_MAC;
61  break;
62 
63  default:
64  clib_warning ("Unknown FID type %d!", fid_addr_type (fid));
65  break;
66  }
67 }
68 
69 void
70 lisp_gid_put_api (vl_api_eid_t * eid, const gid_address_t * gid)
71 {
72  switch (gid_address_type (gid))
73  {
74  case GID_ADDR_IP_PREFIX:
75  ip_prefix_encode2 (&gid_address_ippref (gid), &eid->address.prefix);
76  eid->type = EID_TYPE_API_PREFIX;
77  break;
78 
79  case GID_ADDR_MAC:
80  mac_address_encode ((mac_address_t *) gid_address_mac (gid), eid->address.mac);
81  eid->type = EID_TYPE_API_MAC;
82  break;
83 
84  default:
85  clib_warning ("Unknown GID type %d!", gid_address_type (gid));
86  break;
87  }
88 }
void lisp_gid_put_api(vl_api_eid_t *eid, const gid_address_t *gid)
#define gid_address_type(_a)
Definition: lisp_types.h:203
void mac_address_encode(const mac_address_t *in, u8 *out)
void ip_prefix_encode2(const ip_prefix_t *in, vl_api_prefix_t *out)
Definition: ip_types_api.c:285
#define fid_addr_mac(_a)
Definition: lisp_types.h:85
void ip_prefix_normalize(ip_prefix_t *a)
Definition: ip_types.c:318
typedef eid
Definition: lisp_types.api:59
unsigned int u32
Definition: types.h:88
#define gid_address_mac(_a)
Definition: lisp_types.h:209
u32 vni
Definition: lisp_gpe.api:119
vl_api_address_t dst
Definition: gre.api:55
#define gid_address_ippref(_a)
Definition: lisp_types.h:204
void ip_address_decode2(const vl_api_address_t *in, ip_address_t *out)
Definition: ip_types_api.c:166
#define gid_address_ippref_len(_a)
Definition: lisp_types.h:205
#define clib_warning(format, args...)
Definition: error.h:59
#define fid_addr_ippref(_a)
Definition: lisp_types.h:82
struct _gid_address_t gid_address_t
#define fid_addr_type(_a)
Definition: lisp_types.h:87
void lisp_fid_put_api(vl_api_eid_t *eid, const fid_address_t *fid)
#define gid_address_vni(_a)
Definition: lisp_types.h:213
void mac_address_decode(const u8 *in, mac_address_t *out)
Conversion functions to/from (decode/encode) API types to VPP internal types.
int unformat_lisp_eid_api(gid_address_t *dst, u32 vni, const vl_api_eid_t *eid)