main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. )
  6. // 假设的 VXLAN 信息结构体
  7. type VXLANInfo struct {
  8. VxLANPortName string
  9. VID uint32
  10. GroupIp string
  11. LocalIp string
  12. }
  13. // 假设的全局配置结构体
  14. type SysBasicConf struct {
  15. BusinessOvsName string
  16. }
  17. var Global = SysBasicConf{
  18. BusinessOvsName: "eth0", // 示例值,根据实际情况修改
  19. }
  20. func main() {
  21. // 示例 VXLAN 信息
  22. vxLANInfo := VXLANInfo{
  23. VxLANPortName: "vxlan0",
  24. VID: 1000,
  25. GroupIp: "239.1.1.1",
  26. LocalIp: "192.168.1.1",
  27. }
  28. // 构建命令参数
  29. commandArg := []string{}
  30. commandArg = append(commandArg, "ip")
  31. commandArg = append(commandArg, "link")
  32. commandArg = append(commandArg, "add")
  33. commandArg = append(commandArg, vxLANInfo.VxLANPortName)
  34. commandArg = append(commandArg, "type")
  35. commandArg = append(commandArg, "vxlan")
  36. commandArg = append(commandArg, "id")
  37. commandArg = append(commandArg, strconv.Itoa(int(vxLANInfo.VID)))
  38. commandArg = append(commandArg, "group")
  39. commandArg = append(commandArg, vxLANInfo.GroupIp)
  40. commandArg = append(commandArg, "local")
  41. commandArg = append(commandArg, vxLANInfo.LocalIp)
  42. commandArg = append(commandArg, "dstport")
  43. commandArg = append(commandArg, "4789")
  44. commandArg = append(commandArg, "dev")
  45. commandArg = append(commandArg, Global.BusinessOvsName)
  46. fmt.Println("commandArg:", commandArg)
  47. }