• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang odp.TunnelFlowKey类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了TunnelFlowKey类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: printTunnelOptions

func printTunnelOptions(fk odp.TunnelFlowKey, prefix string) {
	k := fk.Key()
	m := fk.Mask()

	printBytesOption(prefix+"id", k.TunnelId[:], m.TunnelId[:], hex.EncodeToString)
	printBytesOption(prefix+"ipv4-src", k.Ipv4Src[:], m.Ipv4Src[:], ipv4ToString)
	printBytesOption(prefix+"ipv4-dst", k.Ipv4Dst[:], m.Ipv4Dst[:], ipv4ToString)
	printByteOption(prefix+"tos", k.Tos, m.Tos)
	printByteOption(prefix+"ttl", k.Ttl, m.Ttl)

	if m.Df {
		fmt.Printf(" --%sdf=%t", prefix, k.Df)
	}

	if m.Csum {
		fmt.Printf(" --%scsum=%t", prefix, k.Csum)
	}
}
开发者ID:bboreham,项目名称:go-odp,代码行数:18,代码来源: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)
	}

	if tf.tpsrc >= 0 {
		fk.SetTpSrc(uint16(tf.tpsrc))
	}

	if tf.tpdst >= 0 {
		fk.SetTpDst(uint16(tf.tpdst))
	}

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


示例4: 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


示例5: 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类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mesh.PeerNameFromString函数代码示例发布时间:2022-05-28
下一篇:
Golang odp.FlowSpec类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap