OpenSDN source code
esi_label.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
7 
8 #include <stdio.h>
9 
10 #include <algorithm>
11 #include <string>
12 
13 #include "base/parse_object.h"
14 
15 using std::copy;
16 using std::fill;
17 using std::string;
18 
20  copy(data.begin(), data.end(), data_.begin());
21 }
22 
23 EsiLabel::EsiLabel(bool single_active) {
24  fill(data_.begin(), data_.end(), 0);
27  if (single_active) {
28  data_[2] |= 0x01;
29  }
30 }
31 
32 string EsiLabel::flags() const {
33  return (data_[2] & 0x01) ? string("sa") : string("aa");
34 }
35 
36 int EsiLabel::label() const {
39  int value = get_value(&data_[5], 3);
40  return value >> 4;
41  }
42  return 0;
43 }
44 
45 string EsiLabel::ToString() const {
46  char temp[50];
47  snprintf(temp, sizeof(temp), "esilabel:%s:%d", flags().c_str(), label());
48  return string(temp);
49 }
boost::array< uint8_t, kSize > bytes_type
Definition: esi_label.h:20
std::string ToString() const
Definition: esi_label.cc:45
std::string flags() const
Definition: esi_label.cc:32
bytes_type data_
Definition: esi_label.h:38
int label() const
Definition: esi_label.cc:36
bool single_active() const
Definition: esi_label.h:25
EsiLabel(const bytes_type &data)
Definition: esi_label.cc:19
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:40