lisp: Move to plugin
[vpp.git] / src / plugins / lisp / lisp-cp / lisp_types_api.c
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
19 #include <lisp/lisp-cp/lisp_types_api.h>
20 #include <vnet/ip/ip_types_api.h>
21 #include <vnet/ethernet/ethernet_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 */
29       gid_address_type (dst) = GID_ADDR_IP_PREFIX;
30       ip_address_decode2 (&eid->address.prefix.address, &dst->ippref.addr);
31       gid_address_ippref_len (dst) = eid->address.prefix.len;
32       ip_prefix_normalize (&gid_address_ippref (dst));
33       break;
34     case EID_TYPE_API_MAC:                      /* l2 mac */
35       gid_address_type (dst) = GID_ADDR_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 }