#include <iostream>
#include <netinet/in.h>
#include <stdint.h>
using namespace std;
using u32=uint32_t;
typedef u32 mpls_label_t;
typedef struct {
/* Label: top 20 bits [in network byte order] */
/* Experimental: 3 bits ... */
/* S (bottom of label stack): 1 bit */
/* TTL: 8 bits */
mpls_label_t label_exp_s_ttl;
} mpls_unicast_header_t;
#define MPLS_ENTRY_LABEL_SHIFT 12
#define MPLS_ENTRY_EOS_SHIFT 8
#define MPLS_ENTRY_EOS_MASK 0x01 /* EOS bit in its byte */
#define MPLS_ENTRY_EOS(mpls) \
(((mpls) >> MPLS_ENTRY_EOS_SHIFT) & MPLS_ENTRY_EOS_MASK)
static inline u32 vnet_mpls_uc_get_s (mpls_label_t label_exp_s_ttl)
{
return (MPLS_ENTRY_EOS(label_exp_s_ttl));
}
static inline u32 vnet_mpls_uc_get_label (mpls_label_t label_exp_s_ttl)
{
return (label_exp_s_ttl>>MPLS_ENTRY_LABEL_SHIFT);
}
int main() {
auto label_exp_s_ttl = 0xFFA10100;
cout << "s_ttl:" << label_exp_s_ttl << endl;
auto label = ntohl(label_exp_s_ttl);
auto part1 = (vnet_mpls_uc_get_label(label) << 1);
cout << "part1:" << part1 << endl;
auto part2 = vnet_mpls_uc_get_s(label);
cout << "part2:" << part2 << endl;
auto key = (vnet_mpls_uc_get_label(label) << 1) | vnet_mpls_uc_get_s(label);
cout << "label:" << label << endl;
cout << "key:" << key << endl;
return 0;
}