func validateTenantConfig(tenant *intent.ConfigTenant) error { if tenant.Name == "" { return core.Errorf("invalid tenant name") } err := checkPktTagType(tenant.DefaultNetType) if err != nil { return err } if tenant.SubnetPool != "" { _, _, err = net.ParseCIDR(tenant.SubnetPool) if err != nil { return err } } if tenant.VLANs != "" { _, err = netutils.ParseTagRanges(tenant.VLANs, "vlan") if err != nil { log.Errorf("error parsing vlan range '%s'. Error: %s", tenant.VLANs, err) return err } } if tenant.VXLANs != "" { _, err = netutils.ParseTagRanges(tenant.VXLANs, "vxlan") if err != nil { log.Errorf("error parsing vxlan range '%s'.Error: %s", tenant.VXLANs, err) return err } } return nil }
func (gc *Cfg) checkErrors() error { var err error if net.ParseIP(gc.Auto.SubnetPool) == nil { return core.Errorf("invalid ip address pool %s", gc.Auto.SubnetPool) } _, err = netutils.ParseTagRanges(gc.Auto.VLANs, "vlan") if err != nil { return err } _, err = netutils.ParseTagRanges(gc.Auto.VXLANs, "vxlan") if err != nil { return err } if gc.Deploy.DefaultNetType != "vlan" && gc.Deploy.DefaultNetType != "vxlan" { return core.Errorf("unsupported net type %s", gc.Deploy.DefaultNetType) } if gc.Auto.SubnetLen > gc.Auto.AllocSubnetLen { return core.Errorf("subnet size %d is smaller than subnets (%d) to be allocated from it", gc.Auto.SubnetLen, gc.Auto.AllocSubnetLen) } return err }
func (gc *Cfg) initVXLANBitset(vxlans string) (*resources.AutoVXLANCfgResource, uint, error) { vxlanRsrcCfg := &resources.AutoVXLANCfgResource{} vxlanRsrcCfg.VXLANs = netutils.CreateBitset(14) vxlanRange := netutils.TagRange{} vxlanRanges, err := netutils.ParseTagRanges(vxlans, "vxlan") if err != nil { return nil, 0, err } // XXX: REVISIT, we seem to accept one contiguous vxlan range vxlanRange = vxlanRanges[0] freeVXLANsStart := uint(vxlanRange.Min) for vxlan := vxlanRange.Min; vxlan <= vxlanRange.Max; vxlan++ { vxlanRsrcCfg.VXLANs.Set(uint(vxlan - vxlanRange.Min)) } availableVLANs, err := deriveAvailableVLANs(gc.StateDriver) if err != nil { return nil, 0, err } localVLANsReqd := vxlanRange.Max - vxlanRange.Min + 1 if count := availableVLANs.Count(); int(count) < localVLANsReqd { return nil, 0, core.Errorf("Available free local vlans (%d) is less than possible vxlans (%d)", count, vxlanRange.Max-vxlanRange.Min) } else if int(count) > localVLANsReqd { //only reserve the #vxlan amount of bits var clearBitMarker uint for i := 0; i < localVLANsReqd; i++ { clearBitMarker, _ = availableVLANs.NextSet(clearBitMarker) clearBitMarker++ } clearBitMarker++ for { if bit, ok := availableVLANs.NextSet(clearBitMarker); ok { availableVLANs.Clear(bit) } else { break } } } vxlanRsrcCfg.LocalVLANs = availableVLANs return vxlanRsrcCfg, freeVXLANsStart, nil }
func (gc *Cfg) initVLANBitset(vlans string) (*bitset.BitSet, error) { vlanBitset := netutils.CreateBitset(12) vlanRanges, err := netutils.ParseTagRanges(vlans, "vlan") if err != nil { return nil, err } for _, vlanRange := range vlanRanges { for vlan := vlanRange.Min; vlan <= vlanRange.Max; vlan++ { vlanBitset.Set(uint(vlan)) } } clearReservedVLANs(vlanBitset) return vlanBitset, nil }
func validateOpts(opts *cliOpts) error { var err error if flagSet.NArg() != 1 || opts.help { usage() return nil } if opts.debug { log.SetLevel(log.DebugLevel) } if opts.oper.Get() == "" { log.Fatalf("An operation must be specified") } if opts.construct.Get() == "" { log.Fatalf("A construct must be specified") } if opts.pktTagType != "vxlan" && opts.pktTagType != "vlan" { log.Fatalf("error '%s' packet tag type not supported", opts.pktTagType) } // global create params validation if opts.oper.Get() == cliOperCreate && opts.construct.Get() == cliConstructGlobal { if opts.vlans != "" { _, err = netutils.ParseTagRanges(opts.vlans, "vlan") if err != nil { log.Fatalf("error '%s' parsing vlan range '%s' \n", err, opts.vlans) } } if opts.vxlans != "" { _, err = netutils.ParseTagRanges(opts.vxlans, "vxlan") if err != nil { log.Fatalf("error '%s' parsing vxlan range '%s' \n", err, opts.vxlans) } } } if opts.pktTag == "auto" { if opts.oper.Get() == cliOperCreate && opts.construct.Get() == cliConstructNetwork { log.Infof(" auto allocating network subnet from global pool") } } else if opts.pktTag != "" { _, err = strconv.Atoi(opts.pktTag) if err != nil { log.Fatalf("Error convertinng tag %s to integer \n", opts.pktTag) } } // network create params validation if opts.oper.Get() == cliOperCreate && opts.construct.Get() == cliConstructNetwork { } if opts.homingHost == "" { opts.homingHost, err = os.Hostname() if err != nil { log.Fatalf("error obtaining the hostname, error %s \n", err) } } // default gw and mask parsing if opts.subnetCidr == "" { opts.subnetLen = 0 opts.subnetIP = "auto" } else { _, _, err = net.ParseCIDR(opts.subnetCidr) if err != nil { log.Fatalf("error '%s' parsing cidr ip %s \n", err, opts.subnetCidr) } opts.subnetIP, opts.subnetLen, err = netutils.ParseCIDR(opts.subnetCidr) if err != nil { logFatalSubnetAndMaskFormatError() } } if opts.vtepIP != "" && net.ParseIP(opts.vtepIP) == nil { log.Fatalf("error '%s' parsing vtep ip %s \n", err, opts.vtepIP) } // endpoint parameters validation if opts.oper.Get() == cliOperCreate && opts.construct.Get() == cliConstructEndpoint && opts.vtepIP != "" && (opts.netID == "" || opts.ipAddr == "") { if opts.ipAddr == "auto" { log.Debugf("doing auto ip address assignemt for the ep... \n") } else { log.Fatalf("Endpoint creation requires a valid net-id, vlan tag, " + "and ip address") } } // attach detach parameters validation if (opts.oper.Get() == cliOperAttach || opts.oper.Get() == cliOperDetach) && opts.construct.Get() == cliConstructEndpoint && opts.contName == "" { log.Fatalf("A valid container-id is needed to attach/detach a container to an ep") } return err }