22 #include "ns3/openflow-interface.h"
23 #include "ns3/openflow-switch-net-device.h"
41 m_chain = chain_create();
46 chain_destroy(m_chain);
50 void DoRun()
override;
64 size_t actions_len = 0;
78 key.flow.in_port = htons(0);
80 key.flow.dl_vlan = htons(OFP_VLAN_NONE);
81 key.flow.dl_type = htons(ETH_TYPE_IP);
82 key.flow.nw_proto = htons(IP_TYPE_UDP);
84 key.flow.reserved = 0;
85 key.flow.mpls_label1 = htonl(MPLS_INVALID_LABEL);
86 key.flow.mpls_label2 = htonl(MPLS_INVALID_LABEL);
89 dl_src.
CopyTo(key.flow.dl_src);
90 dl_dst.
CopyTo(key.flow.dl_dst);
93 key.flow.nw_src = htonl(nw_src.
Get());
94 key.flow.nw_dst = htonl(nw_dst.
Get());
97 key.flow.tp_src = htonl(tp_src);
98 key.flow.tp_dst = htonl(tp_dst);
102 ofm.header.version = OFP_VERSION;
103 ofm.header.type = OFPT_FLOW_MOD;
104 ofm.header.length = htons(
sizeof(ofp_flow_mod) + actions_len);
105 ofm.command = htons(OFPFC_ADD);
106 ofm.idle_timeout = htons(OFP_FLOW_PERMANENT);
107 ofm.hard_timeout = htons(OFP_FLOW_PERMANENT);
108 ofm.buffer_id = htonl(-1);
109 ofm.priority = OFP_DEFAULT_PRIORITY;
111 ofm.match.wildcards = key.wildcards;
112 ofm.match.in_port = key.flow.in_port;
113 memcpy(ofm.match.dl_src, key.flow.dl_src,
sizeof ofm.match.dl_src);
114 memcpy(ofm.match.dl_dst,
116 sizeof ofm.match.dl_dst);
117 ofm.match.dl_vlan = key.flow.dl_vlan;
118 ofm.match.dl_type = key.flow.dl_type;
119 ofm.match.nw_proto = key.flow.nw_proto;
120 ofm.match.nw_src = key.flow.nw_src;
121 ofm.match.nw_dst = key.flow.nw_dst;
122 ofm.match.tp_src = key.flow.tp_src;
123 ofm.match.tp_dst = key.flow.tp_dst;
124 ofm.match.mpls_label1 = key.flow.mpls_label1;
125 ofm.match.mpls_label2 = key.flow.mpls_label1;
128 sw_flow* flow = flow_alloc(actions_len);
131 flow_extract_match(&flow->key, &ofm.match);
134 flow->priority = flow->key.wildcards ? ntohs(ofm.priority) : -1;
135 flow->idle_timeout = ntohs(ofm.idle_timeout);
136 flow->hard_timeout = ntohs(ofm.hard_timeout);
137 flow->used = flow->created = time_now();
138 flow->sf_acts->actions_len = actions_len;
139 flow->byte_count = 0;
140 flow->packet_count = 0;
141 memcpy(flow->sf_acts->actions, ofm.actions, actions_len);
149 "Key provided doesn't match to the flow that was created from it.");
152 dl_dst.
CopyTo(key.flow.dl_src);
153 dl_src.
CopyTo(key.flow.dl_dst);
154 key.flow.nw_src = htonl(nw_dst.
Get());
155 key.flow.nw_dst = htonl(nw_src.
Get());
156 key.flow.tp_src = htonl(tp_dst);
157 key.flow.tp_dst = htonl(tp_src);
161 "Key provided shouldn't match the flow but it does.");
164 dl_dst.
CopyTo(key.flow.dl_dst);
165 dl_src.
CopyTo(key.flow.dl_src);
166 key.flow.nw_src = htonl(nw_src.
Get());
167 key.flow.nw_dst = htonl(nw_dst.
Get());
168 key.flow.tp_src = htonl(tp_src);
169 key.flow.tp_dst = htonl(tp_dst);
173 ofp_action_output acts[1];
174 acts[0].type = htons(OFPAT_OUTPUT);
175 acts[0].len = htons(
sizeof(ofp_action_output));
176 acts[0].port = output_port;
178 uint16_t priority = key.wildcards ? ntohs(ofm.priority) : -1;
180 chain_modify(m_chain, &key, priority,
false, (
const ofp_action_header*)acts,
sizeof(acts)),
182 "Flow table failed to modify Flow.");
190 "Flow table failed to delete Flow.");
193 "Key provided shouldn't match the flow but it does.");
SwitchFlowTableTestCase()
~SwitchFlowTableTestCase() override
sw_chain * m_chain
OpenFlow service function chain.
void DoRun() override
Implementation to actually run this TestCase.
Ipv4 addresses are stored in host order in this class.
uint32_t Get() const
Get the host-order 32-bit IP address.
void CopyTo(uint8_t buffer[6]) const
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static SwitchTestSuite switchTestSuite
Do not forget to allocate an instance of this TestSuite.