52 size_t actions_len = 0;
66 key.flow.in_port = htons(0);
68 key.flow.dl_vlan = htons(OFP_VLAN_NONE);
69 key.flow.dl_type = htons(ETH_TYPE_IP);
70 key.flow.nw_proto = htons(IP_TYPE_UDP);
72 key.flow.reserved = 0;
73 key.flow.mpls_label1 = htonl(MPLS_INVALID_LABEL);
74 key.flow.mpls_label2 = htonl(MPLS_INVALID_LABEL);
77 dl_src.
CopyTo(key.flow.dl_src);
78 dl_dst.
CopyTo(key.flow.dl_dst);
81 key.flow.nw_src = htonl(nw_src.
Get());
82 key.flow.nw_dst = htonl(nw_dst.
Get());
85 key.flow.tp_src = htonl(tp_src);
86 key.flow.tp_dst = htonl(tp_dst);
90 ofm.header.version = OFP_VERSION;
91 ofm.header.type = OFPT_FLOW_MOD;
92 ofm.header.length = htons(
sizeof(ofp_flow_mod) + actions_len);
93 ofm.command = htons(OFPFC_ADD);
94 ofm.idle_timeout = htons(OFP_FLOW_PERMANENT);
95 ofm.hard_timeout = htons(OFP_FLOW_PERMANENT);
96 ofm.buffer_id = htonl(-1);
97 ofm.priority = OFP_DEFAULT_PRIORITY;
99 ofm.match.wildcards = key.wildcards;
100 ofm.match.in_port = key.flow.in_port;
101 memcpy(ofm.match.dl_src, key.flow.dl_src,
sizeof ofm.match.dl_src);
102 memcpy(ofm.match.dl_dst,
104 sizeof ofm.match.dl_dst);
105 ofm.match.dl_vlan = key.flow.dl_vlan;
106 ofm.match.dl_type = key.flow.dl_type;
107 ofm.match.nw_proto = key.flow.nw_proto;
108 ofm.match.nw_src = key.flow.nw_src;
109 ofm.match.nw_dst = key.flow.nw_dst;
110 ofm.match.tp_src = key.flow.tp_src;
111 ofm.match.tp_dst = key.flow.tp_dst;
112 ofm.match.mpls_label1 = key.flow.mpls_label1;
113 ofm.match.mpls_label2 = key.flow.mpls_label1;
116 sw_flow* flow = flow_alloc(actions_len);
119 flow_extract_match(&flow->key, &ofm.match);
122 flow->priority = flow->key.wildcards ? ntohs(ofm.priority) : -1;
123 flow->idle_timeout = ntohs(ofm.idle_timeout);
124 flow->hard_timeout = ntohs(ofm.hard_timeout);
125 flow->used = flow->created = time_now();
126 flow->sf_acts->actions_len = actions_len;
127 flow->byte_count = 0;
128 flow->packet_count = 0;
129 memcpy(flow->sf_acts->actions, ofm.actions, actions_len);
137 "Key provided doesn't match to the flow that was created from it.");
140 dl_dst.
CopyTo(key.flow.dl_src);
141 dl_src.
CopyTo(key.flow.dl_dst);
142 key.flow.nw_src = htonl(nw_dst.
Get());
143 key.flow.nw_dst = htonl(nw_src.
Get());
144 key.flow.tp_src = htonl(tp_dst);
145 key.flow.tp_dst = htonl(tp_src);
149 "Key provided shouldn't match the flow but it does.");
152 dl_dst.
CopyTo(key.flow.dl_dst);
153 dl_src.
CopyTo(key.flow.dl_src);
154 key.flow.nw_src = htonl(nw_src.
Get());
155 key.flow.nw_dst = htonl(nw_dst.
Get());
156 key.flow.tp_src = htonl(tp_src);
157 key.flow.tp_dst = htonl(tp_dst);
161 ofp_action_output acts[1];
162 acts[0].type = htons(OFPAT_OUTPUT);
163 acts[0].len = htons(
sizeof(ofp_action_output));
164 acts[0].port = output_port;
166 uint16_t priority = key.wildcards ? ntohs(ofm.priority) : -1;
168 chain_modify(
m_chain, &key, priority,
false, (
const ofp_action_header*)acts,
sizeof(acts)),
170 "Flow table failed to modify Flow.");
178 "Flow table failed to delete Flow.");
181 "Key provided shouldn't match the flow but it does.");