当前位置: 首页>>代码示例>>Golang>>正文


Golang TunnelFlowKey.SetIpv4Src方法代码示例

本文整理汇总了Golang中github.com/weaveworks/go-odp/odp.TunnelFlowKey.SetIpv4Src方法的典型用法代码示例。如果您正苦于以下问题:Golang TunnelFlowKey.SetIpv4Src方法的具体用法?Golang TunnelFlowKey.SetIpv4Src怎么用?Golang TunnelFlowKey.SetIpv4Src使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/weaveworks/go-odp/odp.TunnelFlowKey的用法示例。


在下文中一共展示了TunnelFlowKey.SetIpv4Src方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getVxlanVportID

func (fastdp *FastDatapath) getVxlanVportID(udpPort int) (odp.VportID, error) {
	fastdp.lock.Lock()
	defer fastdp.lock.Unlock()

	if vxlanVportID, present := fastdp.vxlanVportIDs[udpPort]; present {
		return vxlanVportID, nil
	}

	vxlanVportID, err := fastdp.dp.CreateVport(
		odp.NewVxlanVportSpec(fmt.Sprintf("vxlan-%d", udpPort), uint16(udpPort)))
	if err != nil {
		return 0, err
	}

	fastdp.vxlanVportIDs[udpPort] = vxlanVportID
	fastdp.missHandlers[vxlanVportID] = func(fks odp.FlowKeys, lock *fastDatapathLock) FlowOp {
		tunnel := fks[odp.OVS_KEY_ATTR_TUNNEL].(odp.TunnelFlowKey)
		tunKey := tunnel.Key()

		lock.relock()
		consumer := fastdp.overlayConsumer
		if consumer == nil {
			return vetoFlowCreationFlowOp{}
		}

		srcPeer, dstPeer := fastdp.extractPeers(tunKey.TunnelId)
		if srcPeer == nil || dstPeer == nil {
			return vetoFlowCreationFlowOp{}
		}

		lock.unlock()
		pk := flowKeysToPacketKey(fks)
		var zeroMAC MAC
		if pk.SrcMAC == zeroMAC && pk.DstMAC == zeroMAC {
			return vxlanSpecialPacketFlowOp{
				fastdp:  fastdp,
				srcPeer: srcPeer,
				sender: &net.UDPAddr{
					IP:   net.IP(tunKey.Ipv4Src[:]),
					Port: udpPort,
				},
			}
		}

		key := ForwardPacketKey{
			SrcPeer:   srcPeer,
			DstPeer:   dstPeer,
			PacketKey: pk,
		}

		var tunnelFlowKey odp.TunnelFlowKey
		tunnelFlowKey.SetTunnelId(tunKey.TunnelId)
		tunnelFlowKey.SetIpv4Src(tunKey.Ipv4Src)
		tunnelFlowKey.SetIpv4Dst(tunKey.Ipv4Dst)

		return NewMultiFlowOp(false, odpFlowKey(tunnelFlowKey), consumer(key))
	}

	return vxlanVportID, nil
}
开发者ID:codingbunch,项目名称:weave,代码行数:60,代码来源:fastdp.go

示例2: printSetTunnelOptions

func printSetTunnelOptions(a odp.SetTunnelAction) {
	var fk odp.TunnelFlowKey
	if a.Present.TunnelId {
		fk.SetTunnelId(a.TunnelId)
	}
	if a.Present.Ipv4Src {
		fk.SetIpv4Src(a.Ipv4Src)
	}
	if a.Present.Ipv4Dst {
		fk.SetIpv4Dst(a.Ipv4Dst)
	}
	if a.Present.Tos {
		fk.SetTos(a.Tos)
	}
	if a.Present.Ttl {
		fk.SetTtl(a.Ttl)
	}
	if a.Present.Df {
		fk.SetDf(a.Df)
	}
	if a.Present.Csum {
		fk.SetCsum(a.Csum)
	}
	if a.Present.TpSrc {
		fk.SetTpSrc(a.TpSrc)
	}
	if a.Present.TpDst {
		fk.SetTpDst(a.TpDst)
	}
	printTunnelOptions(fk, "set-tunnel-")
}
开发者ID:awh,项目名称:go-odp,代码行数:31,代码来源:main.go

示例3: parseTunnelFlags

func parseTunnelFlags(tf *tunnelFlags) (odp.TunnelFlowKey, error) {
	var fk odp.TunnelFlowKey

	if tf.id != "" {
		tunnelId, err := parseTunnelId(tf.id)
		if err != nil {
			return fk, err
		}

		fk.SetTunnelId(tunnelId)
	}

	if tf.ipv4Src != "" {
		addr, err := parseIpv4(tf.ipv4Src)
		if err != nil {
			return fk, err
		}

		fk.SetIpv4Src(addr)
	}

	if tf.ipv4Dst != "" {
		addr, err := parseIpv4(tf.ipv4Dst)
		if err != nil {
			return fk, err
		}

		fk.SetIpv4Dst(addr)
	}

	if tf.tos >= 0 {
		fk.SetTos(uint8(tf.tos))
	}

	if tf.ttl >= 0 {
		fk.SetTtl(uint8(tf.ttl))
	}

	if tf.df != "" {
		df, err := parseBool(tf.df)
		if err != nil {
			return fk, err
		}

		fk.SetDf(df)
	}

	if tf.csum != "" {
		csum, err := parseBool(tf.csum)
		if err != nil {
			return fk, err
		}

		fk.SetCsum(csum)
	}

	return fk, nil
}
开发者ID:bboreham,项目名称:go-odp,代码行数:58,代码来源:main.go

示例4: getVxlanVportID

func (fastdp *FastDatapath) getVxlanVportID(udpPort int) (odp.VportID, error) {
	fastdp.lock.Lock()
	defer fastdp.lock.Unlock()

	if vxlanVportID, present := fastdp.vxlanVportIDs[udpPort]; present {
		return vxlanVportID, nil
	}

	name := fmt.Sprintf("vxlan-%d", udpPort)
	vxlanVportID, err := fastdp.dp.CreateVport(
		odp.NewVxlanVportSpec(name, uint16(udpPort)))
	if err != nil {
		return 0, err
	}

	// If a netdev for the vxlan vport exists, we need to do an extra check
	// to bypass the kernel bug which makes the vxlan creation to complete
	// successfully regardless whether there were any errors when binding
	// to the given UDP port.
	if link, err := netlink.LinkByName(name); err == nil {
		if link.Attrs().Flags&net.FlagUp == 0 {
			// The netdev interface is down, so most likely bringing it up
			// has failed due to the UDP port being in use.
			if err := fastdp.dp.DeleteVport(vxlanVportID); err != nil {
				log.Warning("Unable to remove vxlan vport %d: %s", vxlanVportID, err)
			}
			return 0, odp.NetlinkError(syscall.EADDRINUSE)
		}
	}

	fastdp.vxlanVportIDs[udpPort] = vxlanVportID
	fastdp.missHandlers[vxlanVportID] = func(fks odp.FlowKeys, lock *fastDatapathLock) FlowOp {
		log.Debug("ODP miss: ", fks, " on port ", vxlanVportID)
		tunnel := fks[odp.OVS_KEY_ATTR_TUNNEL].(odp.TunnelFlowKey)
		tunKey := tunnel.Key()

		lock.relock()
		consumer := fastdp.overlayConsumer
		if consumer == nil {
			return vetoFlowCreationFlowOp{}
		}

		srcPeer, dstPeer := fastdp.extractPeers(tunKey.TunnelId)
		if srcPeer == nil || dstPeer == nil {
			return vetoFlowCreationFlowOp{}
		}

		lock.unlock()
		pk := flowKeysToPacketKey(fks)
		var zeroMAC MAC
		if pk.SrcMAC == zeroMAC && pk.DstMAC == zeroMAC {
			return vxlanSpecialPacketFlowOp{
				fastdp:  fastdp,
				srcPeer: srcPeer,
				sender: &net.UDPAddr{
					IP:   net.IP(tunKey.Ipv4Src[:]),
					Port: udpPort,
				},
			}
		}

		key := ForwardPacketKey{
			SrcPeer:   srcPeer,
			DstPeer:   dstPeer,
			PacketKey: pk,
		}

		var tunnelFlowKey odp.TunnelFlowKey
		tunnelFlowKey.SetTunnelId(tunKey.TunnelId)
		tunnelFlowKey.SetIpv4Src(tunKey.Ipv4Src)
		tunnelFlowKey.SetIpv4Dst(tunKey.Ipv4Dst)

		return NewMultiFlowOp(false, odpFlowKey(tunnelFlowKey), consumer(key))
	}

	return vxlanVportID, nil
}
开发者ID:n054,项目名称:weave,代码行数:77,代码来源:fastdp.go


注:本文中的github.com/weaveworks/go-odp/odp.TunnelFlowKey.SetIpv4Src方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。