Ai
5 Star 6 Fork 4

zstackio/zstack-vyos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dnat_perf_test.go 3.05 KB
一键复制 编辑 原始数据 按行查看 历史
shixin.ruan 提交于 2024-07-08 14:31 +08:00 . [root]: use openeuler image for vpc
package plugin
import (
"fmt"
"zstack-vyos/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = XDescribe("dnat_perf_test", func() {
var nicCmd configureNicCmd
It("[PERF]DNAT : prepare env", func() {
utils.InitLog(utils.GetVyosUtLogDir()+"dnat_perf_test.log", false)
SetKeepalivedStatusForUt(KeepAlivedStatus_Master)
utils.SetSkipVyosIptablesForUT(true)
nicCmd = configureNicCmd{}
nicCmd.Nics = append(nicCmd.Nics, utils.PubNicForUT)
nicCmd.Nics = append(nicCmd.Nics, utils.PrivateNicsForUT[0])
configureNic(&nicCmd)
})
Measure("[PERF]DNAT : test set dnat perf", func(b Benchmarker) {
runtime := b.Time("runtime", func() {
output := setDnatPerfTest(500)
Expect(output).To(BeNil())
})
Ω(runtime.Seconds()).Should(BeNumerically(">", 0), "setDnat() shouldn't take too short.")
}, 1)
Measure("[PERF]DNAT : test remove dnat perf ", func(b Benchmarker) {
runtime := b.Time("runtime", func() {
output := removeDnatPerfTest(500)
Expect(output).To(BeNil())
})
Ω(runtime.Seconds()).Should(BeNumerically(">", 0), "removeDnat() shouldn't take too short.")
}, 1)
It("[PERF]DNAT : destroy env", func() {
nicCmd = configureNicCmd{}
nicCmd.Nics = append(nicCmd.Nics, utils.PubNicForUT)
nicCmd.Nics = append(nicCmd.Nics, utils.PrivateNicsForUT[0])
removeNic(&nicCmd)
utils.SetSkipVyosIptablesForUT(false)
})
})
func setDnatPerfTest(number int) interface{} {
setCmd := &setDnatCmd{}
for i := 1; i <= number; i++ {
rule := dnatInfo{VipPortStart: 100, VipPortEnd: 65530,
PrivatePortStart: 101, PrivatePortEnd: 65531, ProtocolType: utils.IPTABLES_PROTO_TCP,
PublicMac: utils.PubNicForUT.Mac, PrivateMac: utils.PrivateNicsForUT[0].Mac,
SnatInboundTraffic: false,
}
rule.Uuid = fmt.Sprintf("uuid%d", i)
if i <= 255 {
rule.VipIp = fmt.Sprintf("10.10.1.%d", i)
rule.PrivateIp = fmt.Sprintf("192.168.1.%d", i)
rule.AllowedCidr = fmt.Sprintf("1.1.%d.0/24", i)
} else {
rule.VipIp = fmt.Sprintf("10.10.2.%d", i-255)
rule.PrivateIp = fmt.Sprintf("192.168.2.%d", i-255)
rule.AllowedCidr = fmt.Sprintf("1.2.%d.0/24", i-255)
}
setCmd.Rules = append(setCmd.Rules, rule)
}
if err := setDnat(setCmd); err != nil {
return err
}
return nil
}
func removeDnatPerfTest(number int) interface{} {
rmCmd := &removeDnatCmd{}
for i := 1; i <= number; i++ {
rule := dnatInfo{VipPortStart: 100, VipPortEnd: 65530,
PrivatePortStart: 101, PrivatePortEnd: 65531, ProtocolType: utils.IPTABLES_PROTO_TCP,
PublicMac: utils.PubNicForUT.Mac, PrivateMac: utils.PrivateNicsForUT[0].Mac,
SnatInboundTraffic: false,
}
rule.Uuid = fmt.Sprintf("uuid%d", i)
if i <= 255 {
rule.VipIp = fmt.Sprintf("10.10.1.%d", i)
rule.PrivateIp = fmt.Sprintf("192.168.1.%d", i)
rule.AllowedCidr = fmt.Sprintf("1.1.%d.0/24", i)
} else {
rule.VipIp = fmt.Sprintf("10.10.2.%d", i-255)
rule.PrivateIp = fmt.Sprintf("192.168.2.%d", i-255)
rule.AllowedCidr = fmt.Sprintf("1.2.%d.0/24", i-255)
}
rmCmd.Rules = append(rmCmd.Rules, rule)
}
if err := removeDnat(rmCmd); err != nil {
return err
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zstackio/zstack-vyos.git
git@gitee.com:zstackio/zstack-vyos.git
zstackio
zstack-vyos
zstack-vyos
master

搜索帮助