SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
inject_ethernet_common.h
Go to the documentation of this file.
1/*
2 © 2017 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_INJECTION_EXTENSION_INJECT_ETHERNET_COMMON_H
15#define SIMICS_SYSTEMC_INJECTION_EXTENSION_INJECT_ETHERNET_COMMON_H
16
17
18
22#include <simics/types/frags.h>
23
24#include <map>
25#include <set>
26#include <string>
27#include <vector>
28#include <utility>
29
30namespace simics {
31namespace systemc {
32namespace injection {
33namespace extension {
34
36template <typename TPAYLOAD>
37class InjectEthernetCommon : public InjectBase<TPAYLOAD> {
38 public:
39 ATTR_DICT_PARSER_NAMESPACE("ethernet_common.")
40
41 bool extractFragsFrag(AttrDictParser *parser, const attr_value_t *attr,
42 simics::types::frags_frag_t *frag) {
43 if (!SIM_attr_is_data(*attr)) {
44 parser->reportError("fragslist must be data");
45 return false;
46 }
47 frag->start = SIM_attr_data(*attr);
48 frag->len = SIM_attr_data_size(*attr);
49 return true;
50 }
51 bool extractFrags(AttrDictParser *parser, const attr_value_t *attr,
53 AttrDictParser p = parser->init(attr);
54
55 if (!p.lookUp("len", &frags->len))
56 return false;
57
58 std::vector<attr_value_t> fraglist;
59 if (!p.lookUp("fraglist", &fraglist))
60 return false;
61
62 if (fraglist.size() > MAX_FRAGS_FRAGS) {
63 parser->reportError("fraglist must not exceed %i elements",
65 return false;
66 }
67 frags->nfrags = fraglist.size();
68
69 int cnt = 0;
70 for (auto &frag_attr : fraglist) {
71 simics::types::frags_frag_t *frag = &frags->fraglist[cnt++];
72 if (!extractFragsFrag(parser, &frag_attr, frag))
73 return false;
74 }
75
76 return true;
77 }
78 bool setValue(AttrDictParser *parser, const std::string &key,
79 attr_value_t *attr, TPAYLOAD *gp) override {
80 if (key == "frame") {
81 AttrDictParser p = parser->init(attr);
82
83 attr_value_t frame_attr;
84 if (!p.lookUp("frame", &frame_attr))
85 return false;
86
87 auto res = frames_.emplace(gp, new simics::types::frags_t);
88 simics::types::frags_t *frame = res.first->second;
89 if (!extractFrags(parser, &frame_attr, frame))
90 return false;
91
92 int32_t crc_ok = 0;
93 if (!p.lookUp("crc_ok", &crc_ok))
94 return false;
95
97 ->frame(frame, crc_ok);
98 return true;
99 }
100
101 return false;
102 }
103 void released(TPAYLOAD *gp) override {
104 if (frames_.find(gp) != frames_.end()) {
105 delete frames_[gp];
106 frames_.erase(gp);
107 }
108 }
109
110 private:
111 std::map<TPAYLOAD *, simics::types::frags_t *> frames_;
112};
113
114} // namespace extension
115} // namespace injection
116} // namespace systemc
117} // namespace simics
118
119#endif
#define ATTR_DICT_PARSER_NAMESPACE(ns)
Definition: attr_dict_parser.h:32
Definition: attr_dict_parser.h:38
void reportError(const char *str,...)
AttrDictParser init(const attr_value_t *attr)
bool lookUp(const std::string &key, T *v)
Definition: attr_dict_parser.h:53
Definition: inject_base.h:43
bool extractFrags(AttrDictParser *parser, const attr_value_t *attr, simics::types::frags_t *frags)
Definition: inject_ethernet_common.h:51
void released(TPAYLOAD *gp) override
Definition: inject_ethernet_common.h:103
bool setValue(AttrDictParser *parser, const std::string &key, attr_value_t *attr, TPAYLOAD *gp) override
Definition: inject_ethernet_common.h:78
bool extractFragsFrag(AttrDictParser *parser, const attr_value_t *attr, simics::types::frags_frag_t *frag)
Definition: inject_ethernet_common.h:41
#define MAX_FRAGS_FRAGS
Definition: frags.h:23
Definition: adapter.h:79
Definition: frags.h:31
Definition: frags.h:36
size_t len
Definition: frags.h:37
frags_frag_t fraglist[MAX_FRAGS_FRAGS]
Definition: frags.h:39
unsigned nfrags
Definition: frags.h:38