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