@@ 253-278 (lines=26) @@ | ||
250 | return cls(value) |
|
251 | ||
252 | ||
253 | class MatchNwDst(MatchField): |
|
254 | """Match for IPV4 destination.""" |
|
255 | ||
256 | name = 'nw_dst' |
|
257 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_DST |
|
258 | ||
259 | def as_of_tlv(self): |
|
260 | """Return a pyof OXM TLV instance.""" |
|
261 | ip_addr = IPAddress(self.value) |
|
262 | value_bytes = ip_addr.pack() |
|
263 | if ip_addr.netmask < 32: |
|
264 | value_bytes += mask_to_bytes(ip_addr.netmask, 32) |
|
265 | return OxmTLV(oxm_field=self.oxm_field, |
|
266 | oxm_hasmask=ip_addr.netmask < 32, |
|
267 | oxm_value=value_bytes) |
|
268 | ||
269 | @classmethod |
|
270 | def from_of_tlv(cls, tlv): |
|
271 | """Return an instance from a pyof OXM TLV.""" |
|
272 | ip_address = IPAddress() |
|
273 | ip_address.unpack(tlv.oxm_value) |
|
274 | addr_str = str(ip_address) |
|
275 | value = addr_str |
|
276 | if tlv.oxm_hasmask: |
|
277 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}' |
|
278 | return cls(value) |
|
279 | ||
280 | ||
281 | class MatchNwProto(MatchField): |
|
@@ 225-250 (lines=26) @@ | ||
222 | return cls(port) |
|
223 | ||
224 | ||
225 | class MatchNwSrc(MatchField): |
|
226 | """Match for IPV4 source.""" |
|
227 | ||
228 | name = 'nw_src' |
|
229 | oxm_field = OxmOfbMatchField.OFPXMT_OFB_IPV4_SRC |
|
230 | ||
231 | def as_of_tlv(self): |
|
232 | """Return a pyof OXM TLV instance.""" |
|
233 | ip_addr = IPAddress(self.value) |
|
234 | value_bytes = ip_addr.pack() |
|
235 | if ip_addr.netmask < 32: |
|
236 | value_bytes += mask_to_bytes(ip_addr.netmask, 32) |
|
237 | return OxmTLV(oxm_field=self.oxm_field, |
|
238 | oxm_hasmask=ip_addr.netmask < 32, |
|
239 | oxm_value=value_bytes) |
|
240 | ||
241 | @classmethod |
|
242 | def from_of_tlv(cls, tlv): |
|
243 | """Return an instance from a pyof OXM TLV.""" |
|
244 | ip_address = IPAddress() |
|
245 | ip_address.unpack(tlv.oxm_value) |
|
246 | addr_str = str(ip_address) |
|
247 | value = addr_str |
|
248 | if tlv.oxm_hasmask: |
|
249 | value = f'{addr_str}/{bytes_to_mask(tlv.oxm_value[4:], 32)}' |
|
250 | return cls(value) |
|
251 | ||
252 | ||
253 | class MatchNwDst(MatchField): |