本文整理匯總了Golang中github.com/hkwi/gopenflow/oxm.Header函數的典型用法代碼示例。如果您正苦於以下問題:Golang Header函數的具體用法?Golang Header怎麽用?Golang Header使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Header函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Bytes
func (self OxmKeyExp) Bytes(payload OxmPayload) []byte {
hdr := oxm.Header(oxm.OFPXMC_EXPERIMENTER<<oxm.OXM_CLASS_SHIFT | uint32(self.Field)<<oxm.OXM_FIELD_SHIFT)
var buf []byte
setCommon := func(payloadLength int) {
buf = make([]byte, 4+payloadLength)
hdr.SetLength(payloadLength)
binary.BigEndian.PutUint32(buf, uint32(hdr))
binary.BigEndian.PutUint32(buf[4:], self.Experimenter)
binary.BigEndian.PutUint16(buf[8:], self.Type)
}
switch p := payload.(type) {
case OxmValueMask:
if len(p.Mask) > 0 {
hdr.SetMask(true)
}
setCommon(6 + len(p.Value) + len(p.Mask))
copy(buf[10:], p.Value)
copy(buf[10+len(p.Value):], p.Mask)
case []byte:
setCommon(6 + len(p))
copy(buf[10:], p)
case nil:
setCommon(6)
}
return buf
}
示例2: Bytes
func (self OxmKeyStratos) Bytes(payload ofp4sw.OxmPayload) []byte {
hdr := oxm.Header(oxm.OFPXMC_EXPERIMENTER<<oxm.OXM_CLASS_SHIFT | uint32(self.Field)<<oxm.OXM_FIELD_SHIFT)
makeCommon := func(payloadLength int) []byte {
buf := make([]byte, 10+payloadLength)
hdr.SetLength(6 + payloadLength)
binary.BigEndian.PutUint32(buf, uint32(hdr))
binary.BigEndian.PutUint32(buf[4:], uint32(oxm.STRATOS_EXPERIMENTER_ID))
binary.BigEndian.PutUint16(buf[8:], self.Type)
return buf
}
switch p := payload.(type) {
case ofp4sw.OxmValueMask:
if len(p.Mask) > 0 {
hdr.SetMask(true)
}
buf := makeCommon(len(p.Value) + len(p.Mask))
copy(buf[10:], p.Value)
copy(buf[10+len(p.Value):], p.Mask)
return buf
case OxmMultiValue:
var ret []byte
for _, v := range p.Values {
buf := makeCommon(len(v))
copy(buf[10:], v)
ret = append(ret, buf...)
}
return ret
}
return nil
}
示例3: Key
func (self matchHash) Key(target matchHash) uint32 {
hasher := fnv.New32()
for k, s := range self {
var value, mask []byte
if bKey, ok := k.(OxmKeyBasic); !ok || oxm.Header(bKey).Class() != ofp4.OFPXMC_OPENFLOW_BASIC {
continue
} else {
length, _ := ofp4.OxmOfDefs(uint32(bKey))
value = make([]byte, length)
mask = make([]byte, length)
}
if t, ok := target[k]; ok {
a := s.(OxmValueMask)
b := t.(OxmValueMask)
for i, _ := range mask {
mask[i] = 0xFF
}
if a.Mask != nil {
for i, _ := range mask {
mask[i] &= a.Mask[i]
}
}
if b.Mask != nil {
for i, _ := range mask {
mask[i] &= b.Mask[i]
}
}
for i, _ := range value {
value[i] = b.Value[i] & mask[i]
}
}
hasher.Write(value)
}
return hasher.Sum32()
}
示例4: Match
func (self match) Match(data Frame) bool {
for oxmKey, oxmPayload := range self {
var handler OxmHandler
switch k := oxmKey.(type) {
case OxmKeyBasic:
switch oxm.Header(k).Class() {
case ofp4.OFPXMC_OPENFLOW_BASIC:
handler = oxmBasicHandler
case ofp4.OFPXMC_NXM_0, OFPXMC_NXM_1:
handler = oxmNxmHandler
}
default:
handler = oxmHandlers[oxmKeys[oxmKey]]
}
if handler == nil {
log.Printf("oxm handler not found for %v", oxmKey)
return false
}
if result, err := handler.Match(data, oxmKey, oxmPayload); err != nil {
log.Print(err)
return false
} else if !result {
return false
}
}
return true
}
示例5: UnmarshalBinary
func (self match) UnmarshalBinary(msg []byte) error {
exps := make(map[uint32]bool)
for _, oxm := range ofp4.Oxm(msg).Iter() {
hdr := oxm.Header()
switch hdr.Class() {
case ofp4.OFPXMC_OPENFLOW_BASIC:
self[OxmKeyBasic(hdr.Type())] = OxmValueMask{
Value: oxm.Value(),
Mask: oxm.Mask(),
}
case ofp4.OFPXMC_EXPERIMENTER:
exps[ofp4.OxmExperimenterHeader(oxm).Experimenter()] = true
default:
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_TYPE,
)
}
}
for exp, _ := range exps {
if handle, ok := oxmHandlers[exp]; ok {
for k, v := range handle.Parse(msg) {
oxmKeys[k] = exp
self[k] = v
}
} else {
return ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBRC_BAD_LEN,
)
}
}
return nil
}
示例6: OxmId
func (self oxmNxm) OxmId(id uint32) uint32 {
length, mask := nxmDefs(id)
hdr := oxm.Header(id)
hdr.SetMask(mask)
if mask {
hdr.SetLength(length * 2)
} else {
hdr.SetLength(length)
}
return uint32(hdr)
}
示例7: Merge
// creates a common match union parameter.
func (self matchHash) Merge(from matchHash) {
var removal []OxmKey
for k, s := range self {
var a, b OxmValueMask
var length int
if bKey, ok := k.(OxmKeyBasic); !ok || oxm.Header(bKey).Class() != ofp4.OFPXMC_OPENFLOW_BASIC {
continue
} else if f, ok := from[k]; !ok {
removal = append(removal, k)
continue
} else {
a = s.(OxmValueMask)
b = f.(OxmValueMask)
length, _ = ofp4.OxmOfDefs(uint32(bKey))
}
fullMask := true
mask := make([]byte, length)
for i, _ := range mask {
mask[i] = 0xFF
}
if a.Mask != nil {
for i, _ := range mask {
mask[i] &= a.Mask[i]
}
}
if b.Mask != nil {
for i, _ := range mask {
mask[i] &= b.Mask[i]
}
}
for i, m := range mask {
mask[i] &^= (a.Value[i] & m) ^ (b.Value[i] & m)
if mask[i] != 0 {
fullMask = false
}
}
if fullMask {
removal = append(removal, k)
continue
}
payload := OxmValueMask{
Value: make([]byte, length),
Mask: mask,
}
for i, m := range mask {
payload.Value[i] = a.Value[i] & m
}
self[k] = payload
}
for _, rem := range removal {
delete(self, rem)
}
}
示例8: makeOxmBasic
func makeOxmBasic(oxmType uint32) []byte {
length, mask := ofp4.OxmOfDefs(oxmType)
if mask {
length = length * 2
}
hdr := oxm.Header(oxmType)
hdr.SetMask(mask)
hdr.SetLength(length)
buf := make([]byte, 4+length)
binary.BigEndian.PutUint32(buf, oxmType)
return buf
}
示例9: Parse
func (self oxmNxm) Parse(buf []byte) map[OxmKey]OxmPayload {
ret := make(map[OxmKey]OxmPayload)
for _, oxm := range ofp4.Oxm(buf).Iter() {
hdr := oxm.Header()
length := hdr.Length()
if hdr.HasMask() {
length = length / 2
}
switch hdr.Class() {
case ofp4.OFPXMC_NXM_0, ofp4.OFPXMC_NXM_1:
ret[OxmKeyBasic(hdr.Type())] = OxmValueMask{
Value: oxm[4 : 4+length],
Mask: oxm[4+length:],
}
}
}
return ret
}
示例10: Bytes
func (self OxmKeyExp) Bytes(payload OxmPayload) []byte {
hdr := oxm.Header(oxm.OFPXMC_EXPERIMENTER<<oxm.OXM_CLASS_SHIFT | uint32(self.Field)<<oxm.OXM_FIELD_SHIFT)
var value, mask []byte
switch p := payload.(type) {
case OxmValueMask:
value = p.Value
mask = p.Mask
case []byte:
value = p
}
if len(mask) > 0 {
hdr.SetMask(true)
}
buf = make([]byte, 8+len(value)+len(mask))
hdr.SetLength(4 + len(value) + len(mask))
binary.BigEndian.PutUint32(buf, uint32(hdr))
binary.BigEndian.PutUint32(buf[4:], self.Experimenter)
copy(buf[8:], value)
copy(buf[8+len(value):], mask)
return buf
}
示例11: Conflict
/*
You should pass expanded match.
*/
func (self match) Conflict(target match) (bool, error) {
uni := make(map[OxmKey]bool)
for k, _ := range self {
uni[k] = true
}
for k, _ := range target {
uni[k] = true
}
for oxmKey, _ := range uni {
if sPayload, ok := self[oxmKey]; !ok {
continue
} else if tPayload, ok := target[oxmKey]; !ok {
continue
} else {
var handle OxmHandler
switch k := oxmKey.(type) {
case OxmKeyBasic:
if oxm.Header(k).Class() == ofp4.OFPXMC_OPENFLOW_BASIC {
handle = oxmBasicHandler
}
default:
handle = oxmHandlers[oxmKeys[oxmKey]]
}
if handle == nil {
return false, ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_TYPE,
)
}
if result, err := handle.Conflict(oxmKey, sPayload, tPayload); err != nil {
return false, err
} else if result {
return true, nil
}
}
}
return false, nil
}
示例12: Expand
func (self match) Expand() (match, error) {
var exps []uint32
ret := make(map[OxmKey]OxmPayload)
for k, v := range self {
oxm := ofp4.Oxm(k.Bytes(v))
if oxm.Header().Class() == ofp4.OFPXMC_EXPERIMENTER {
exps = append(exps, ofp4.OxmExperimenterHeader(oxm).Experimenter())
}
ret[k] = v
}
oxmBasicHandler.Expand(ret)
for _, exp := range exps {
if handle, ok := oxmHandlers[exp]; !ok {
return nil, ofp4.MakeErrorMsg(
ofp4.OFPET_BAD_MATCH,
ofp4.OFPBMC_BAD_TYPE,
)
} else if err := handle.Expand(ret); err != nil {
return nil, err
}
}
return ret, nil
}
示例13: OxmOfDefs
func OxmOfDefs(hdr uint32) (length int, mayMask bool) {
switch oxm.Header(hdr).Type() {
default:
return 0, false
case oxm.OXM_OF_IN_PORT:
return 4, false
case oxm.OXM_OF_IN_PHY_PORT:
return 4, false
case oxm.OXM_OF_METADATA:
return 8, true
case oxm.OXM_OF_ETH_DST:
return 6, true
case oxm.OXM_OF_ETH_SRC:
return 6, true
case oxm.OXM_OF_ETH_TYPE:
return 2, false
case oxm.OXM_OF_VLAN_VID:
return 2, true
case oxm.OXM_OF_VLAN_PCP:
return 1, false
case oxm.OXM_OF_IP_DSCP:
return 1, false
case oxm.OXM_OF_IP_ECN:
return 1, false
case oxm.OXM_OF_IP_PROTO:
return 1, false
case oxm.OXM_OF_IPV4_SRC:
return 4, true
case oxm.OXM_OF_IPV4_DST:
return 4, true
case oxm.OXM_OF_TCP_SRC:
return 2, false
case oxm.OXM_OF_TCP_DST:
return 2, false
case oxm.OXM_OF_UDP_SRC:
return 2, false
case oxm.OXM_OF_UDP_DST:
return 2, false
case oxm.OXM_OF_SCTP_SRC:
return 2, false
case oxm.OXM_OF_SCTP_DST:
return 2, false
case oxm.OXM_OF_ICMPV4_TYPE:
return 1, false
case oxm.OXM_OF_ICMPV4_CODE:
return 1, false
case oxm.OXM_OF_ARP_OP:
return 2, false
case oxm.OXM_OF_ARP_SPA:
return 4, true
case oxm.OXM_OF_ARP_TPA:
return 4, true
case oxm.OXM_OF_ARP_SHA:
return 6, true
case oxm.OXM_OF_ARP_THA:
return 6, true
case oxm.OXM_OF_IPV6_SRC:
return 16, true
case oxm.OXM_OF_IPV6_DST:
return 16, true
case oxm.OXM_OF_IPV6_FLABEL:
return 4, true
case oxm.OXM_OF_ICMPV6_TYPE:
return 1, false
case oxm.OXM_OF_ICMPV6_CODE:
return 1, false
case oxm.OXM_OF_IPV6_ND_TARGET:
return 16, false
case oxm.OXM_OF_IPV6_ND_SLL:
return 6, false
case oxm.OXM_OF_IPV6_ND_TLL:
return 6, false
case oxm.OXM_OF_MPLS_LABEL:
return 4, true
case oxm.OXM_OF_MPLS_TC:
return 1, false
case oxm.OXM_OF_MPLS_BOS:
return 1, false
case oxm.OXM_OF_PBB_ISID:
return 3, true
case oxm.OXM_OF_TUNNEL_ID:
return 8, true
case oxm.OXM_OF_IPV6_EXTHDR:
return 2, true
}
}
示例14: Header
func (self Oxm) Header() oxm.Header {
return oxm.Header(binary.BigEndian.Uint32(self))
}
示例15: getValue
func (self *Frame) getValue(oxmType uint32) ([]byte, error) {
switch oxm.Header(oxmType).Type() {
default:
return nil, fmt.Errorf("unknown oxm field %x", oxmType)
case oxm.OXM_OF_IN_PORT:
return toMatchBytes(self.inPort)
case oxm.OXM_OF_IN_PHY_PORT:
return toMatchBytes(self.inPhyPort)
case oxm.OXM_OF_METADATA:
return toMatchBytes(self.metadata)
case oxm.OXM_OF_ETH_DST:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.Ethernet); ok {
return toMatchBytes(t.DstMAC)
}
}
case oxm.OXM_OF_ETH_SRC:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.Ethernet); ok {
return toMatchBytes(t.SrcMAC)
}
}
case oxm.OXM_OF_ETH_TYPE:
do_break := false
var ret []byte
for _, layer := range self.Layers() {
switch t := layer.(type) {
case *layers.Ethernet:
if buf, err := toMatchBytes(t.EthernetType); err != nil {
return nil, err
} else {
ret = buf
}
case *layers.Dot1Q:
if buf, err := toMatchBytes(t.Type); err != nil {
return nil, err
} else {
ret = buf
}
default:
do_break = true
}
if do_break {
break
}
}
if ret != nil {
return ret, nil
}
case oxm.OXM_OF_VLAN_VID:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.Dot1Q); ok {
return toMatchBytes(t.VLANIdentifier | 0x1000)
}
}
return toMatchBytes(uint16(0x0000))
case oxm.OXM_OF_VLAN_PCP:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.Dot1Q); ok {
return toMatchBytes(t.Priority)
}
}
case oxm.OXM_OF_IP_DSCP:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.IPv4); ok {
return toMatchBytes(t.TOS >> 2)
}
if t, ok := layer.(*layers.IPv6); ok {
return toMatchBytes(t.TrafficClass >> 2)
}
}
case oxm.OXM_OF_IP_ECN:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.IPv4); ok {
return toMatchBytes(t.TOS & 0x03)
}
if t, ok := layer.(*layers.IPv6); ok {
return toMatchBytes(t.TrafficClass & 0x03)
}
}
case oxm.OXM_OF_IP_PROTO:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.IPv4); ok {
return toMatchBytes(t.Protocol)
}
if t, ok := layer.(*layers.IPv6); ok {
return toMatchBytes(t.NextHeader)
}
}
case oxm.OXM_OF_IPV4_SRC:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.IPv4); ok {
return toMatchBytes(t.SrcIP)
}
}
case oxm.OXM_OF_IPV4_DST:
for _, layer := range self.Layers() {
if t, ok := layer.(*layers.IPv4); ok {
return toMatchBytes(t.DstIP)
}
//.........這裏部分代碼省略.........