func (d *of10Driver) nomMatch(m of10.Match) (nom.Match, error) { nm := nom.Match{} wc := of10.FlowWildcards(m.Wildcards()) if wc&of10.PFW_IN_PORT == 0 { ofp := m.InPort() nomp, ok := d.ofPorts[ofp] if !ok { return nom.Match{}, fmt.Errorf("of10Driver: cannot find port %v", ofp) } nm.AddField(nom.InPort(nomp.UID())) } if wc&of10.PFW_DL_SRC == 0 { nm.AddField(nom.EthSrc{ Addr: m.DlSrc(), Mask: nom.MaskNoneMAC, }) } if wc&of10.PFW_DL_DST == 0 { nm.AddField(nom.EthDst{ Addr: m.DlDst(), Mask: nom.MaskNoneMAC, }) } if wc&of10.PFW_DL_TYPE == 0 { nm.AddField(nom.EthType(m.DlType())) } if wc&of10.PFW_NW_SRC_MASK != of10.PFW_NW_SRC_ALL && m.NwSrc() != 0 { mask := uint(wc&of10.PFW_NW_SRC_MASK) >> uint(of10.PFW_NW_SRC_SHIFT) nm.AddField(nom.IPv4Src(nom.CIDRToMaskedIPv4(m.NwSrc(), mask))) } if wc&of10.PFW_NW_DST_MASK != of10.PFW_NW_DST_ALL && m.NwDst() != 0 { mask := uint(wc&of10.PFW_NW_DST_MASK) >> uint(of10.PFW_NW_DST_SHIFT) nm.AddField(nom.IPv4Dst(nom.CIDRToMaskedIPv4(m.NwDst(), mask))) } if wc&of10.PFW_TP_SRC == 0 { nm.AddField(nom.TransportPortSrc(m.TpSrc())) } if wc&of10.PFW_TP_DST == 0 { nm.AddField(nom.TransportPortDst(m.TpDst())) } return nm, nil }
func (d *of10Driver) ofMatch(m nom.Match) (of10.Match, error) { ofm := of10.NewMatch() w := of10.PFW_ALL for _, f := range m.Fields { switch f := f.(type) { case nom.InPort: p, ok := d.nomPorts[nom.UID(f)] if !ok { return of10.Match{}, fmt.Errorf("of10Driver: nom port not found %v", f) } ofm.SetInPort(p) w &= ^of10.PFW_IN_PORT case nom.EthDst: if f.Mask != nom.MaskNoneMAC { return of10.Match{}, fmt.Errorf("of10Driver: masked ethernet address is not supported") } ofm.SetDlDst([6]byte(f.Addr)) w &= ^of10.PFW_DL_DST case nom.EthSrc: if f.Mask != nom.MaskNoneMAC { return of10.Match{}, fmt.Errorf("of10Driver: masked ethernet address is not supported") } ofm.SetDlSrc([6]byte(f.Addr)) w &= ^of10.PFW_DL_SRC case nom.EthType: ofm.SetDlType(uint16(f)) w &= ^of10.PFW_DL_TYPE case nom.IPv4Src: w &= ^of10.PFW_NW_SRC_MASK ofm.SetNwSrc(f.Addr.Uint()) mask := f.Mask.PopCount() if mask == 32 { w |= of10.PFW_NW_SRC_MASK } else { w |= of10.FlowWildcards(mask << uint(of10.PFW_NW_SRC_SHIFT)) } case nom.IPv4Dst: w &= ^of10.PFW_NW_DST_MASK ofm.SetNwDst(f.Addr.Uint()) mask := f.Mask.PopCount() if mask == 32 { w |= of10.PFW_NW_DST_MASK } else { w |= of10.FlowWildcards(mask << uint(of10.PFW_NW_DST_SHIFT)) } case nom.TransportPortSrc: ofm.SetTpSrc(uint16(f)) w &= ^of10.PFW_TP_SRC case nom.TransportPortDst: ofm.SetTpDst(uint16(f)) w &= ^of10.PFW_TP_DST case nom.IPv6Src, nom.IPv6Dst: return of10.Match{}, fmt.Errorf("of10Driver: IPv6 not supported") } } ofm.SetWildcards(uint32(w)) return ofm, nil }