1/*
2 * Copyright (c) 2019 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#ifndef __PW_CW_DPO_H__
17#define __PW_CW_DPO_H__
18
19#include <vnet/vnet.h>
20#include <vnet/mpls/packet.h>
21#include <vnet/dpo/dpo.h>
22
23/**
24 * A Psuedo Wire Control Word is 4 bytes
25 */
26typedef u32 pw_cw_t;
27
28/**
29 * A representation of a Psuedo Wire Control Word pop DPO
30 */
31typedef struct pw_cw_dpo_t
32{
33    /**
34     * Next DPO in the graph
35     */
36    dpo_id_t pwcw_parent;
37
38    /**
39     * Number of locks/users of the label
40     */
41    u16 pwcw_locks;
42} pw_cw_dpo_t;
43
44/**
45 * @brief Assert that the MPLS label object is less than a cache line in size.
46 * Should this get any bigger then we will need to reconsider how many labels
47 * can be pushed in one object.
48 */
49STATIC_ASSERT_SIZEOF(pw_cw_dpo_t, 2 * sizeof(u64));
50
51/* #define STATIC_ASSERT_ALIGNOF(d, s)                                      \ */
52/*     STATIC_ASSERT (alignof (d) == sizeof(s), "Align of " #d " must be " # s " bytes") */
53
54/* STATIC_ASSERT_AIGNOF(pw_cw_dpo_t, u64); */
55
56/**
57 * @brief Create an PW CW pop
58 *
59 * @param parent The parent of the created MPLS label object
60 * @param dpo The PW CW DPO created
61 */
62extern void pw_cw_dpo_create(const dpo_id_t *paremt,
63                             dpo_id_t *dpo);
64
65extern u8* format_pw_cw_dpo(u8 *s, va_list *args);
66
67/*
68 * Encapsulation violation for fast data-path access
69 */
70extern pw_cw_dpo_t *pw_cw_dpo_pool;
71
72static inline pw_cw_dpo_t *
73pw_cw_dpo_get (index_t index)
74{
75    return (pool_elt_at_index(pw_cw_dpo_pool, index));
76}
77
78extern void pw_cw_dpo_module_init(void);
79
80#endif
81