diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index 00ad60aa1..2537626ff 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -72,7 +72,6 @@ const ( type Intf struct { dev string - itype int state bool configApplied bool needRouteApply bool @@ -232,7 +231,7 @@ func applyConfigMap(name string, state bool, add bool) { configApplied = nNl.IMap[name].configApplied if !nNl.IMap[name].configApplied { tk.LogIt(tk.LogDebug, "[NLP] Applying Config for %s \n", name) - if applyAllConfig(name) == true { + if applyAllConfig(name) { configApplied = true tk.LogIt(tk.LogDebug, "[NLP] Applied Config for %s \n", name) } else { @@ -254,7 +253,7 @@ func applyConfigMap(name string, state bool, add bool) { tk.LogIt(tk.LogDebug, "[NLP] ConfigMap for %s : %v \n", name, nNl.IMap[name]) } else { tk.LogIt(tk.LogDebug, "[NLP] Applying Config for %s \n", name) - if applyAllConfig(name) == true { + if applyAllConfig(name) { configApplied = true tk.LogIt(tk.LogDebug, "[NLP] Applied Config for %s \n", name) } else { @@ -264,9 +263,7 @@ func applyConfigMap(name string, state bool, add bool) { nNl.IMap[name] = Intf{dev: name, state: state, configApplied: configApplied} } } else { - if _, ok := nNl.IMap[name]; ok { - delete(nNl.IMap, name) - } + delete(nNl.IMap, name) } } @@ -875,7 +872,7 @@ func AddAddr(addr nlp.Addr, link nlp.Link) int { name := attrs.Name ipStr := (addr.IPNet).String() - ret, err := hooks.NetAddrAdd(&cmn.IpAddrMod{Dev: name, IP: ipStr}) + ret, err := hooks.NetAddrAdd(&cmn.IPAddrMod{Dev: name, IP: ipStr}) if err != nil { tk.LogIt(tk.LogError, "[NLP] IPv4 Address %v Port %v failed %v\n", ipStr, name, err) ret = -1 @@ -1115,12 +1112,13 @@ func AddRoute(route nlp.Route) int { } else { ipNet = *route.Dst } + ret, err := hooks.NetRouteAdd(&cmn.RouteMod{Protocol: int(route.Protocol), Flags: route.Flags, Gw: route.Gw, LinkIndex: route.LinkIndex, Dst: ipNet}) if err != nil { if route.Gw != nil { - tk.LogIt(tk.LogError, "[NLP] RT %s via %s add failed-%s\n", ipNet.String(), - route.Gw.String(), err) + tk.LogIt(tk.LogError, "[NLP] RT %s via %s proto %d add failed-%s\n", ipNet.String(), + route.Gw.String(), route.Protocol, err) } else { tk.LogIt(tk.LogError, "[NLP] RT %s add failed-%s\n", ipNet.String(), err) } @@ -1215,7 +1213,7 @@ func AUWorkSingle(m nlp.AddrUpdate) int { attrs := link.Attrs() name := attrs.Name if m.NewAddr { - _, err := hooks.NetAddrAdd(&cmn.IpAddrMod{Dev: name, IP: m.LinkAddress.String()}) + _, err := hooks.NetAddrAdd(&cmn.IPAddrMod{Dev: name, IP: m.LinkAddress.String()}) if err != nil { tk.LogIt(tk.LogInfo, "[NLP] Address %v Port %v add failed\n", m.LinkAddress.String(), name) fmt.Println(err) @@ -1224,7 +1222,7 @@ func AUWorkSingle(m nlp.AddrUpdate) int { } } else { - _, err := hooks.NetAddrDel(&cmn.IpAddrMod{Dev: name, IP: m.LinkAddress.String()}) + _, err := hooks.NetAddrDel(&cmn.IPAddrMod{Dev: name, IP: m.LinkAddress.String()}) if err != nil { tk.LogIt(tk.LogInfo, "[NLP] Address %v Port %v delete failed\n", m.LinkAddress.String(), name) fmt.Println(err) @@ -1317,13 +1315,20 @@ func RUWorker(ch chan nlp.RouteUpdate, f chan struct{}) { } } -func NLWorker(nNl *NlH) { - for { /* Single thread for reading all NL msgs in below order */ - LUWorker(nNl.FromLUCh, nNl.FromLUDone) - AUWorker(nNl.FromAUCh, nNl.FromAUDone) - NUWorker(nNl.FromNUCh, nNl.FromNUDone) - RUWorker(nNl.FromRUCh, nNl.FromRUDone) - time.Sleep(1000 * time.Millisecond) +func NLWorker(nNl *NlH, bgpPeerMode bool) { + if bgpPeerMode { + for { /* Single thread for reading route NL msgs in below order */ + RUWorker(nNl.FromRUCh, nNl.FromRUDone) + time.Sleep(1000 * time.Millisecond) + } + } else { + for { /* Single thread for reading all NL msgs in below order */ + LUWorker(nNl.FromLUCh, nNl.FromLUDone) + AUWorker(nNl.FromAUCh, nNl.FromAUDone) + NUWorker(nNl.FromNUCh, nNl.FromNUDone) + RUWorker(nNl.FromRUCh, nNl.FromRUDone) + time.Sleep(1000 * time.Millisecond) + } } } @@ -1483,10 +1488,24 @@ func LbSessionGet(done bool) int { return 0 } -func NlpInit() *NlH { +func NlpInit(bgpPeerMode bool) *NlH { nNl = new(NlH) + if bgpPeerMode { + nNl.FromRUCh = make(chan nlp.RouteUpdate, cmn.RuWorkQLen) + nNl.FromRUCh = make(chan nlp.RouteUpdate, cmn.RuWorkQLen) + err := nlp.RouteSubscribe(nNl.FromRUCh, nNl.FromRUDone) + if err != nil { + fmt.Println(err) + } else { + tk.LogIt(tk.LogInfo, "[NLP] Route msgs subscribed\n") + } + + go NLWorker(nNl, bgpPeerMode) + return nNl + } + nNl.FromAUCh = make(chan nlp.AddrUpdate, cmn.AuWorkqLen) nNl.FromLUCh = make(chan nlp.LinkUpdate, cmn.LuWorkQLen) nNl.FromNUCh = make(chan nlp.NeighUpdate, cmn.NuWorkQLen) @@ -1494,7 +1513,7 @@ func NlpInit() *NlH { nNl.FromAUDone = make(chan struct{}) nNl.FromLUDone = make(chan struct{}) nNl.FromNUDone = make(chan struct{}) - nNl.FromRUDone = make(chan struct{}) + nNl.FromRUCh = make(chan nlp.RouteUpdate, cmn.RuWorkQLen) nNl.IMap = make(map[string]Intf) checkInit := make(chan bool) @@ -1513,20 +1532,20 @@ func NlpInit() *NlH { } else { tk.LogIt(tk.LogInfo, "[NLP] Addr msgs subscribed\n") } - err = nlp.NeighSubscribe(nNl.FromNUCh, nNl.FromAUDone) + err = nlp.NeighSubscribe(nNl.FromNUCh, nNl.FromNUDone) if err != nil { fmt.Println(err) } else { tk.LogIt(tk.LogInfo, "[NLP] Neigh msgs subscribed\n") } - err = nlp.RouteSubscribe(nNl.FromRUCh, nNl.FromAUDone) + err = nlp.RouteSubscribe(nNl.FromRUCh, nNl.FromRUDone) if err != nil { fmt.Println(err) } else { tk.LogIt(tk.LogInfo, "[NLP] Route msgs subscribed\n") } - go NLWorker(nNl) + go NLWorker(nNl, bgpPeerMode) tk.LogIt(tk.LogInfo, "[NLP] NLP Subscription done\n") go LbSessionGet(done) diff --git a/api/models/b_g_p_global.go b/api/models/b_g_p_global.go new file mode 100644 index 000000000..922730eaf --- /dev/null +++ b/api/models/b_g_p_global.go @@ -0,0 +1,160 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// BGPGlobal b g p global +// +// swagger:model BGPGlobal +type BGPGlobal struct { + + // apply policy + ApplyPolicy *BGPGlobalApplyPolicy `json:"apply-policy,omitempty"` + + // config + Config *BGPGlobalConfig `json:"config,omitempty"` +} + +// Validate validates this b g p global +func (m *BGPGlobal) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateApplyPolicy(formats); err != nil { + res = append(res, err) + } + + if err := m.validateConfig(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *BGPGlobal) validateApplyPolicy(formats strfmt.Registry) error { + if swag.IsZero(m.ApplyPolicy) { // not required + return nil + } + + if m.ApplyPolicy != nil { + if err := m.ApplyPolicy.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("apply-policy") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("apply-policy") + } + return err + } + } + + return nil +} + +func (m *BGPGlobal) validateConfig(formats strfmt.Registry) error { + if swag.IsZero(m.Config) { // not required + return nil + } + + if m.Config != nil { + if err := m.Config.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("config") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("config") + } + return err + } + } + + return nil +} + +// ContextValidate validate this b g p global based on the context it is used +func (m *BGPGlobal) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateApplyPolicy(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateConfig(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *BGPGlobal) contextValidateApplyPolicy(ctx context.Context, formats strfmt.Registry) error { + + if m.ApplyPolicy != nil { + + if swag.IsZero(m.ApplyPolicy) { // not required + return nil + } + + if err := m.ApplyPolicy.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("apply-policy") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("apply-policy") + } + return err + } + } + + return nil +} + +func (m *BGPGlobal) contextValidateConfig(ctx context.Context, formats strfmt.Registry) error { + + if m.Config != nil { + + if swag.IsZero(m.Config) { // not required + return nil + } + + if err := m.Config.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("config") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("config") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *BGPGlobal) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BGPGlobal) UnmarshalBinary(b []byte) error { + var res BGPGlobal + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/api/models/b_g_p_global_apply_policy.go b/api/models/b_g_p_global_apply_policy.go new file mode 100644 index 000000000..2eb6ff35e --- /dev/null +++ b/api/models/b_g_p_global_apply_policy.go @@ -0,0 +1,109 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// BGPGlobalApplyPolicy b g p global apply policy +// +// swagger:model BGPGlobalApplyPolicy +type BGPGlobalApplyPolicy struct { + + // config + Config *BGPPolicyConfig `json:"config,omitempty"` +} + +// Validate validates this b g p global apply policy +func (m *BGPGlobalApplyPolicy) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateConfig(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *BGPGlobalApplyPolicy) validateConfig(formats strfmt.Registry) error { + if swag.IsZero(m.Config) { // not required + return nil + } + + if m.Config != nil { + if err := m.Config.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("config") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("config") + } + return err + } + } + + return nil +} + +// ContextValidate validate this b g p global apply policy based on the context it is used +func (m *BGPGlobalApplyPolicy) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateConfig(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *BGPGlobalApplyPolicy) contextValidateConfig(ctx context.Context, formats strfmt.Registry) error { + + if m.Config != nil { + + if swag.IsZero(m.Config) { // not required + return nil + } + + if err := m.Config.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("config") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("config") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *BGPGlobalApplyPolicy) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BGPGlobalApplyPolicy) UnmarshalBinary(b []byte) error { + var res BGPGlobalApplyPolicy + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/api/models/b_g_p_global_config.go b/api/models/b_g_p_global_config.go new file mode 100644 index 000000000..4892b02bb --- /dev/null +++ b/api/models/b_g_p_global_config.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// BGPGlobalConfig b g p global config +// +// swagger:model BGPGlobalConfig +type BGPGlobalConfig struct { + + // Adds policy to set next hop as self, if enabled + SetNextHopSelf bool `json:"SetNextHopSelf,omitempty"` + + // Local AS number + LocalAs int64 `json:"localAs,omitempty"` + + // BGP Router ID + RouterID string `json:"routerId,omitempty"` +} + +// Validate validates this b g p global config +func (m *BGPGlobalConfig) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this b g p global config based on context it is used +func (m *BGPGlobalConfig) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *BGPGlobalConfig) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BGPGlobalConfig) UnmarshalBinary(b []byte) error { + var res BGPGlobalConfig + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/api/models/b_g_p_neigh.go b/api/models/b_g_p_neigh.go new file mode 100644 index 000000000..75c53cb69 --- /dev/null +++ b/api/models/b_g_p_neigh.go @@ -0,0 +1,53 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// BGPNeigh b g p neigh +// +// swagger:model BGPNeigh +type BGPNeigh struct { + + // BGP Nieghbor IP address + IPAddress string `json:"ipAddress,omitempty"` + + // Remote AS number + RemoteAs int64 `json:"remoteAs,omitempty"` +} + +// Validate validates this b g p neigh +func (m *BGPNeigh) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this b g p neigh based on context it is used +func (m *BGPNeigh) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *BGPNeigh) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BGPNeigh) UnmarshalBinary(b []byte) error { + var res BGPNeigh + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/api/models/b_g_p_policy_config.go b/api/models/b_g_p_policy_config.go new file mode 100644 index 000000000..40fe6d509 --- /dev/null +++ b/api/models/b_g_p_policy_config.go @@ -0,0 +1,50 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// BGPPolicyConfig b g p policy config +// +// swagger:model BGPPolicyConfig +type BGPPolicyConfig struct { + + // BGP export policy list + ExportPolicyList []string `json:"export-policy-list"` +} + +// Validate validates this b g p policy config +func (m *BGPPolicyConfig) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this b g p policy config based on context it is used +func (m *BGPPolicyConfig) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *BGPPolicyConfig) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *BGPPolicyConfig) UnmarshalBinary(b []byte) error { + var res BGPPolicyConfig + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/api/models/firewall_entry.go b/api/models/firewall_entry.go index 7de5c8fb9..571d5bc13 100644 --- a/api/models/firewall_entry.go +++ b/api/models/firewall_entry.go @@ -102,6 +102,11 @@ func (m *FirewallEntry) ContextValidate(ctx context.Context, formats strfmt.Regi func (m *FirewallEntry) contextValidateOpts(ctx context.Context, formats strfmt.Registry) error { if m.Opts != nil { + + if swag.IsZero(m.Opts) { // not required + return nil + } + if err := m.Opts.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("opts") @@ -118,6 +123,11 @@ func (m *FirewallEntry) contextValidateOpts(ctx context.Context, formats strfmt. func (m *FirewallEntry) contextValidateRuleArguments(ctx context.Context, formats strfmt.Registry) error { if m.RuleArguments != nil { + + if swag.IsZero(m.RuleArguments) { // not required + return nil + } + if err := m.RuleArguments.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("ruleArguments") diff --git a/api/models/loadbalance_entry.go b/api/models/loadbalance_entry.go index 5cd573bae..587a4fcb1 100644 --- a/api/models/loadbalance_entry.go +++ b/api/models/loadbalance_entry.go @@ -149,6 +149,11 @@ func (m *LoadbalanceEntry) contextValidateEndpoints(ctx context.Context, formats for i := 0; i < len(m.Endpoints); i++ { if m.Endpoints[i] != nil { + + if swag.IsZero(m.Endpoints[i]) { // not required + return nil + } + if err := m.Endpoints[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("endpoints" + "." + strconv.Itoa(i)) @@ -169,6 +174,11 @@ func (m *LoadbalanceEntry) contextValidateSecondaryIPs(ctx context.Context, form for i := 0; i < len(m.SecondaryIPs); i++ { if m.SecondaryIPs[i] != nil { + + if swag.IsZero(m.SecondaryIPs[i]) { // not required + return nil + } + if err := m.SecondaryIPs[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("secondaryIPs" + "." + strconv.Itoa(i)) @@ -187,6 +197,11 @@ func (m *LoadbalanceEntry) contextValidateSecondaryIPs(ctx context.Context, form func (m *LoadbalanceEntry) contextValidateServiceArguments(ctx context.Context, formats strfmt.Registry) error { if m.ServiceArguments != nil { + + if swag.IsZero(m.ServiceArguments) { // not required + return nil + } + if err := m.ServiceArguments.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("serviceArguments") diff --git a/api/models/mirror_entry.go b/api/models/mirror_entry.go index 062dd2b1f..1e75de1e0 100644 --- a/api/models/mirror_entry.go +++ b/api/models/mirror_entry.go @@ -105,6 +105,11 @@ func (m *MirrorEntry) ContextValidate(ctx context.Context, formats strfmt.Regist func (m *MirrorEntry) contextValidateMirrorInfo(ctx context.Context, formats strfmt.Registry) error { if m.MirrorInfo != nil { + + if swag.IsZero(m.MirrorInfo) { // not required + return nil + } + if err := m.MirrorInfo.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("mirrorInfo") @@ -121,6 +126,11 @@ func (m *MirrorEntry) contextValidateMirrorInfo(ctx context.Context, formats str func (m *MirrorEntry) contextValidateTargetObject(ctx context.Context, formats strfmt.Registry) error { if m.TargetObject != nil { + + if swag.IsZero(m.TargetObject) { // not required + return nil + } + if err := m.TargetObject.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("targetObject") diff --git a/api/models/mirror_get_entry.go b/api/models/mirror_get_entry.go index 62910e701..f9a7cb0b1 100644 --- a/api/models/mirror_get_entry.go +++ b/api/models/mirror_get_entry.go @@ -123,6 +123,11 @@ func (m *MirrorGetEntry) ContextValidate(ctx context.Context, formats strfmt.Reg func (m *MirrorGetEntry) contextValidateMirrorInfo(ctx context.Context, formats strfmt.Registry) error { if m.MirrorInfo != nil { + + if swag.IsZero(m.MirrorInfo) { // not required + return nil + } + if err := m.MirrorInfo.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("mirrorInfo") @@ -139,6 +144,11 @@ func (m *MirrorGetEntry) contextValidateMirrorInfo(ctx context.Context, formats func (m *MirrorGetEntry) contextValidateTargetObject(ctx context.Context, formats strfmt.Registry) error { if m.TargetObject != nil { + + if swag.IsZero(m.TargetObject) { // not required + return nil + } + if err := m.TargetObject.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("targetObject") diff --git a/api/models/policy_entry.go b/api/models/policy_entry.go index b9935512d..f1b62d4d1 100644 --- a/api/models/policy_entry.go +++ b/api/models/policy_entry.go @@ -105,6 +105,11 @@ func (m *PolicyEntry) ContextValidate(ctx context.Context, formats strfmt.Regist func (m *PolicyEntry) contextValidatePolicyInfo(ctx context.Context, formats strfmt.Registry) error { if m.PolicyInfo != nil { + + if swag.IsZero(m.PolicyInfo) { // not required + return nil + } + if err := m.PolicyInfo.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("policyInfo") @@ -121,6 +126,11 @@ func (m *PolicyEntry) contextValidatePolicyInfo(ctx context.Context, formats str func (m *PolicyEntry) contextValidateTargetObject(ctx context.Context, formats strfmt.Registry) error { if m.TargetObject != nil { + + if swag.IsZero(m.TargetObject) { // not required + return nil + } + if err := m.TargetObject.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("targetObject") diff --git a/api/models/port_entry.go b/api/models/port_entry.go index 09fde0403..d6273add4 100644 --- a/api/models/port_entry.go +++ b/api/models/port_entry.go @@ -204,6 +204,11 @@ func (m *PortEntry) ContextValidate(ctx context.Context, formats strfmt.Registry func (m *PortEntry) contextValidatePortHardwareInformation(ctx context.Context, formats strfmt.Registry) error { if m.PortHardwareInformation != nil { + + if swag.IsZero(m.PortHardwareInformation) { // not required + return nil + } + if err := m.PortHardwareInformation.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("portHardwareInformation") @@ -220,6 +225,11 @@ func (m *PortEntry) contextValidatePortHardwareInformation(ctx context.Context, func (m *PortEntry) contextValidatePortL2Information(ctx context.Context, formats strfmt.Registry) error { if m.PortL2Information != nil { + + if swag.IsZero(m.PortL2Information) { // not required + return nil + } + if err := m.PortL2Information.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("portL2Information") @@ -236,6 +246,11 @@ func (m *PortEntry) contextValidatePortL2Information(ctx context.Context, format func (m *PortEntry) contextValidatePortL3Information(ctx context.Context, formats strfmt.Registry) error { if m.PortL3Information != nil { + + if swag.IsZero(m.PortL3Information) { // not required + return nil + } + if err := m.PortL3Information.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("portL3Information") @@ -252,6 +267,11 @@ func (m *PortEntry) contextValidatePortL3Information(ctx context.Context, format func (m *PortEntry) contextValidatePortSoftwareInformation(ctx context.Context, formats strfmt.Registry) error { if m.PortSoftwareInformation != nil { + + if swag.IsZero(m.PortSoftwareInformation) { // not required + return nil + } + if err := m.PortSoftwareInformation.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("portSoftwareInformation") @@ -268,6 +288,11 @@ func (m *PortEntry) contextValidatePortSoftwareInformation(ctx context.Context, func (m *PortEntry) contextValidatePortStatisticInformation(ctx context.Context, formats strfmt.Registry) error { if m.PortStatisticInformation != nil { + + if swag.IsZero(m.PortStatisticInformation) { // not required + return nil + } + if err := m.PortStatisticInformation.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("portStatisticInformation") diff --git a/api/models/route_get_entry.go b/api/models/route_get_entry.go index f83534b4e..fbb3da5e3 100644 --- a/api/models/route_get_entry.go +++ b/api/models/route_get_entry.go @@ -91,6 +91,11 @@ func (m *RouteGetEntry) ContextValidate(ctx context.Context, formats strfmt.Regi func (m *RouteGetEntry) contextValidateStatistic(ctx context.Context, formats strfmt.Registry) error { if m.Statistic != nil { + + if swag.IsZero(m.Statistic) { // not required + return nil + } + if err := m.Statistic.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("statistic") diff --git a/api/models/session_entry.go b/api/models/session_entry.go index 1bfb83af6..6926eb34d 100644 --- a/api/models/session_entry.go +++ b/api/models/session_entry.go @@ -108,6 +108,11 @@ func (m *SessionEntry) ContextValidate(ctx context.Context, formats strfmt.Regis func (m *SessionEntry) contextValidateAccessNetworkTunnel(ctx context.Context, formats strfmt.Registry) error { if m.AccessNetworkTunnel != nil { + + if swag.IsZero(m.AccessNetworkTunnel) { // not required + return nil + } + if err := m.AccessNetworkTunnel.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("accessNetworkTunnel") @@ -124,6 +129,11 @@ func (m *SessionEntry) contextValidateAccessNetworkTunnel(ctx context.Context, f func (m *SessionEntry) contextValidateCoreNetworkTunnel(ctx context.Context, formats strfmt.Registry) error { if m.CoreNetworkTunnel != nil { + + if swag.IsZero(m.CoreNetworkTunnel) { // not required + return nil + } + if err := m.CoreNetworkTunnel.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("coreNetworkTunnel") diff --git a/api/models/session_ul_cl_entry.go b/api/models/session_ul_cl_entry.go index 1d0a8500e..b60c9069b 100644 --- a/api/models/session_ul_cl_entry.go +++ b/api/models/session_ul_cl_entry.go @@ -75,6 +75,11 @@ func (m *SessionUlClEntry) ContextValidate(ctx context.Context, formats strfmt.R func (m *SessionUlClEntry) contextValidateUlclArgument(ctx context.Context, formats strfmt.Registry) error { if m.UlclArgument != nil { + + if swag.IsZero(m.UlclArgument) { // not required + return nil + } + if err := m.UlclArgument.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("ulclArgument") diff --git a/api/models/vlan_get_entry.go b/api/models/vlan_get_entry.go index b7d28b37e..e20cdb092 100644 --- a/api/models/vlan_get_entry.go +++ b/api/models/vlan_get_entry.go @@ -118,6 +118,11 @@ func (m *VlanGetEntry) contextValidateMember(ctx context.Context, formats strfmt for i := 0; i < len(m.Member); i++ { if m.Member[i] != nil { + + if swag.IsZero(m.Member[i]) { // not required + return nil + } + if err := m.Member[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("member" + "." + strconv.Itoa(i)) @@ -136,6 +141,11 @@ func (m *VlanGetEntry) contextValidateMember(ctx context.Context, formats strfmt func (m *VlanGetEntry) contextValidateVlanStatistic(ctx context.Context, formats strfmt.Registry) error { if m.VlanStatistic != nil { + + if swag.IsZero(m.VlanStatistic) { // not required + return nil + } + if err := m.VlanStatistic.ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("vlanStatistic") diff --git a/api/restapi/configure_loxilb_rest_api.go b/api/restapi/configure_loxilb_rest_api.go index 859cd34d8..32a650cc4 100644 --- a/api/restapi/configure_loxilb_rest_api.go +++ b/api/restapi/configure_loxilb_rest_api.go @@ -152,6 +152,11 @@ func configureAPI(api *operations.LoxilbRestAPIAPI) http.Handler { // Prometheus api.GetMetricsHandler = operations.GetMetricsHandlerFunc(handler.ConfigGetPrometheusCounter) + // BGP Peer + api.PostConfigBgpGlobalHandler = operations.PostConfigBgpGlobalHandlerFunc(handler.ConfigPostBGPGlobal) + api.PostConfigBgpNeighHandler = operations.PostConfigBgpNeighHandlerFunc(handler.ConfigPostBGPNeigh) + api.DeleteConfigBgpNeighIPAddressHandler = operations.DeleteConfigBgpNeighIPAddressHandlerFunc(handler.ConfigDeleteBGPNeigh) + api.PreServerShutdown = func() {} api.ServerShutdown = func() {} diff --git a/api/restapi/embedded_spec.go b/api/restapi/embedded_spec.go index 18145b78d..134b51aaa 100644 --- a/api/restapi/embedded_spec.go +++ b/api/restapi/embedded_spec.go @@ -37,6 +37,203 @@ func init() { "host": "0.0.0.0:11111", "basePath": "/netlox/v1", "paths": { + "/config/bgp/global": { + "post": { + "description": "Adds a BGP global config", + "summary": "Adds a BGP global config", + "parameters": [ + { + "description": "Attributes of bgp global config", + "name": "attr", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/BGPGlobalConfig" + } + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/config/bgp/neigh": { + "post": { + "description": "Adds a BGP Neighbor", + "summary": "Adds a BGP Neighbor", + "parameters": [ + { + "description": "Attributes of bgp neighbor", + "name": "attr", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/BGPNeigh" + } + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/config/bgp/neigh/{ip_address}": { + "delete": { + "description": "Delete a BGP Neighbor", + "summary": "Delete a BGP neighbor", + "parameters": [ + { + "type": "string", + "description": "Neighbor IP address", + "name": "ip_address", + "in": "path", + "required": true + }, + { + "type": "integer", + "format": "int32", + "description": "Remote ASN number", + "name": "remote_as", + "in": "query" + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict. Neigh already exists", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/config/cistate": { "post": { "description": "Informs Current Cluster Instance state in the device", @@ -3032,6 +3229,36 @@ func init() { } }, "definitions": { + "BGPGlobalConfig": { + "type": "object", + "properties": { + "SetNextHopSelf": { + "description": "Adds policy to set next hop as self, if enabled", + "type": "boolean" + }, + "localAs": { + "description": "Local AS number", + "type": "integer" + }, + "routerId": { + "description": "BGP Router ID", + "type": "string" + } + } + }, + "BGPNeigh": { + "type": "object", + "properties": { + "ipAddress": { + "description": "BGP Nieghbor IP address", + "type": "string" + }, + "remoteAs": { + "description": "Remote AS number", + "type": "integer" + } + } + }, "CIStatusEntry": { "type": "object", "properties": { @@ -4173,6 +4400,203 @@ func init() { "host": "0.0.0.0:11111", "basePath": "/netlox/v1", "paths": { + "/config/bgp/global": { + "post": { + "description": "Adds a BGP global config", + "summary": "Adds a BGP global config", + "parameters": [ + { + "description": "Attributes of bgp global config", + "name": "attr", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/BGPGlobalConfig" + } + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/config/bgp/neigh": { + "post": { + "description": "Adds a BGP Neighbor", + "summary": "Adds a BGP Neighbor", + "parameters": [ + { + "description": "Attributes of bgp neighbor", + "name": "attr", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/BGPNeigh" + } + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict.", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/config/bgp/neigh/{ip_address}": { + "delete": { + "description": "Delete a BGP Neighbor", + "summary": "Delete a BGP neighbor", + "parameters": [ + { + "type": "string", + "description": "Neighbor IP address", + "name": "ip_address", + "in": "path", + "required": true + }, + { + "type": "integer", + "format": "int32", + "description": "Remote ASN number", + "name": "remote_as", + "in": "query" + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict. Neigh already exists", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/config/cistate": { "post": { "description": "Informs Current Cluster Instance state in the device", @@ -7168,6 +7592,36 @@ func init() { } }, "definitions": { + "BGPGlobalConfig": { + "type": "object", + "properties": { + "SetNextHopSelf": { + "description": "Adds policy to set next hop as self, if enabled", + "type": "boolean" + }, + "localAs": { + "description": "Local AS number", + "type": "integer" + }, + "routerId": { + "description": "BGP Router ID", + "type": "string" + } + } + }, + "BGPNeigh": { + "type": "object", + "properties": { + "ipAddress": { + "description": "BGP Nieghbor IP address", + "type": "string" + }, + "remoteAs": { + "description": "Remote AS number", + "type": "integer" + } + } + }, "CIStatusEntry": { "type": "object", "properties": { diff --git a/api/restapi/handler/gobgp.go b/api/restapi/handler/gobgp.go new file mode 100644 index 000000000..f7af8f50d --- /dev/null +++ b/api/restapi/handler/gobgp.go @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2022 NetLOX Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package handler + +import ( + "github.com/go-openapi/runtime/middleware" + "github.com/loxilb-io/loxilb/api/restapi/operations" + cmn "github.com/loxilb-io/loxilb/common" + tk "github.com/loxilb-io/loxilib" + "net" +) + +func ConfigPostBGPNeigh(params operations.PostConfigBgpNeighParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] BGP Neighbor %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + var bgpNeighMod cmn.GoBGPNeighMod + + // IP address + bgpNeighMod.Addr = net.ParseIP(params.Attr.IPAddress) + + // Remote AS + bgpNeighMod.RemoteAS = uint32(params.Attr.RemoteAs) + + tk.LogIt(tk.LogDebug, "[API] GoBGP neighAdd : %v\n", bgpNeighMod) + _, err := ApiHooks.NetGoBGPNeighAdd(&bgpNeighMod) + if err != nil { + tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) + return &ResultResponse{Result: err.Error()} + } + return &ResultResponse{Result: "Success"} +} + +func ConfigDeleteBGPNeigh(params operations.DeleteConfigBgpNeighIPAddressParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] BGP Neighbor %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + var bgpNeighMod cmn.GoBGPNeighMod + + // IP address + bgpNeighMod.Addr = net.ParseIP(params.IPAddress) + + // Remote AS + bgpNeighMod.RemoteAS = uint32(*params.RemoteAs) + + tk.LogIt(tk.LogDebug, "[API] GoBGP neighDel : %v\n", bgpNeighMod) + _, err := ApiHooks.NetGoBGPNeighDel(&bgpNeighMod) + if err != nil { + tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) + return &ResultResponse{Result: err.Error()} + } + return &ResultResponse{Result: "Success"} +} + +func ConfigPostBGPGlobal(params operations.PostConfigBgpGlobalParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] BGP Global Config %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + var bgpG cmn.GoBGPGlobalConfig + + // Router ID + bgpG.RouterID = params.Attr.RouterID + + // Local AS + bgpG.LocalAs = params.Attr.LocalAs + + // Export policy list + bgpG.SetNHSelf = params.Attr.SetNextHopSelf + + tk.LogIt(tk.LogDebug, "[API] GoBGP GCAdd : %v\n", bgpG) + _, err := ApiHooks.NetGoBGPGCAdd(&bgpG) + if err != nil { + tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) + return &ResultResponse{Result: err.Error()} + } + return &ResultResponse{Result: "Success"} +} diff --git a/api/restapi/handler/loadbalancer.go b/api/restapi/handler/loadbalancer.go index d141de836..bd4c5f19c 100644 --- a/api/restapi/handler/loadbalancer.go +++ b/api/restapi/handler/loadbalancer.go @@ -45,7 +45,7 @@ func ConfigPostLoadbalancer(params operations.PostConfigLoadbalancerParams) midd if lbRules.Serv.Proto == "sctp" { for _, data := range params.Attr.SecondaryIPs { - lbRules.SecIPs = append(lbRules.SecIPs, cmn.LbSecIpArg{ + lbRules.SecIPs = append(lbRules.SecIPs, cmn.LbSecIPArg{ SecIP: data.SecondaryIP, }) } diff --git a/api/restapi/operations/delete_config_bgp_neigh_ip_address.go b/api/restapi/operations/delete_config_bgp_neigh_ip_address.go new file mode 100644 index 000000000..5f54c16f9 --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_neigh_ip_address.go @@ -0,0 +1,58 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteConfigBgpNeighIPAddressHandlerFunc turns a function with the right signature into a delete config bgp neigh IP address handler +type DeleteConfigBgpNeighIPAddressHandlerFunc func(DeleteConfigBgpNeighIPAddressParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteConfigBgpNeighIPAddressHandlerFunc) Handle(params DeleteConfigBgpNeighIPAddressParams) middleware.Responder { + return fn(params) +} + +// DeleteConfigBgpNeighIPAddressHandler interface for that can handle valid delete config bgp neigh IP address params +type DeleteConfigBgpNeighIPAddressHandler interface { + Handle(DeleteConfigBgpNeighIPAddressParams) middleware.Responder +} + +// NewDeleteConfigBgpNeighIPAddress creates a new http.Handler for the delete config bgp neigh IP address operation +func NewDeleteConfigBgpNeighIPAddress(ctx *middleware.Context, handler DeleteConfigBgpNeighIPAddressHandler) *DeleteConfigBgpNeighIPAddress { + return &DeleteConfigBgpNeighIPAddress{Context: ctx, Handler: handler} +} + +/* + DeleteConfigBgpNeighIPAddress swagger:route DELETE /config/bgp/neigh/{ip_address} deleteConfigBgpNeighIpAddress + +# Delete a BGP neighbor + +Delete a BGP Neighbor +*/ +type DeleteConfigBgpNeighIPAddress struct { + Context *middleware.Context + Handler DeleteConfigBgpNeighIPAddressHandler +} + +func (o *DeleteConfigBgpNeighIPAddress) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteConfigBgpNeighIPAddressParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/api/restapi/operations/delete_config_bgp_neigh_ip_address_parameters.go b/api/restapi/operations/delete_config_bgp_neigh_ip_address_parameters.go new file mode 100644 index 000000000..9d6171867 --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_neigh_ip_address_parameters.go @@ -0,0 +1,107 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewDeleteConfigBgpNeighIPAddressParams creates a new DeleteConfigBgpNeighIPAddressParams object +// +// There are no default values defined in the spec. +func NewDeleteConfigBgpNeighIPAddressParams() DeleteConfigBgpNeighIPAddressParams { + + return DeleteConfigBgpNeighIPAddressParams{} +} + +// DeleteConfigBgpNeighIPAddressParams contains all the bound params for the delete config bgp neigh IP address operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteConfigBgpNeighIPAddress +type DeleteConfigBgpNeighIPAddressParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*Neighbor IP address + Required: true + In: path + */ + IPAddress string + /*Remote ASN number + In: query + */ + RemoteAs *int32 +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteConfigBgpNeighIPAddressParams() beforehand. +func (o *DeleteConfigBgpNeighIPAddressParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rIPAddress, rhkIPAddress, _ := route.Params.GetOK("ip_address") + if err := o.bindIPAddress(rIPAddress, rhkIPAddress, route.Formats); err != nil { + res = append(res, err) + } + + qRemoteAs, qhkRemoteAs, _ := qs.GetOK("remote_as") + if err := o.bindRemoteAs(qRemoteAs, qhkRemoteAs, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindIPAddress binds and validates parameter IPAddress from path. +func (o *DeleteConfigBgpNeighIPAddressParams) bindIPAddress(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.IPAddress = raw + + return nil +} + +// bindRemoteAs binds and validates parameter RemoteAs from query. +func (o *DeleteConfigBgpNeighIPAddressParams) bindRemoteAs(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + return nil + } + + value, err := swag.ConvertInt32(raw) + if err != nil { + return errors.InvalidType("remote_as", "query", "int32", raw) + } + o.RemoteAs = &value + + return nil +} diff --git a/api/restapi/operations/delete_config_bgp_neigh_ip_address_responses.go b/api/restapi/operations/delete_config_bgp_neigh_ip_address_responses.go new file mode 100644 index 000000000..4a8a56ee6 --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_neigh_ip_address_responses.go @@ -0,0 +1,354 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/loxilb-io/loxilb/api/models" +) + +// DeleteConfigBgpNeighIPAddressNoContentCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressNoContent +const DeleteConfigBgpNeighIPAddressNoContentCode int = 204 + +/* +DeleteConfigBgpNeighIPAddressNoContent OK + +swagger:response deleteConfigBgpNeighIpAddressNoContent +*/ +type DeleteConfigBgpNeighIPAddressNoContent struct { +} + +// NewDeleteConfigBgpNeighIPAddressNoContent creates DeleteConfigBgpNeighIPAddressNoContent with default headers values +func NewDeleteConfigBgpNeighIPAddressNoContent() *DeleteConfigBgpNeighIPAddressNoContent { + + return &DeleteConfigBgpNeighIPAddressNoContent{} +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(204) +} + +// DeleteConfigBgpNeighIPAddressBadRequestCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressBadRequest +const DeleteConfigBgpNeighIPAddressBadRequestCode int = 400 + +/* +DeleteConfigBgpNeighIPAddressBadRequest Malformed arguments for API call + +swagger:response deleteConfigBgpNeighIpAddressBadRequest +*/ +type DeleteConfigBgpNeighIPAddressBadRequest struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpNeighIPAddressBadRequest creates DeleteConfigBgpNeighIPAddressBadRequest with default headers values +func NewDeleteConfigBgpNeighIPAddressBadRequest() *DeleteConfigBgpNeighIPAddressBadRequest { + + return &DeleteConfigBgpNeighIPAddressBadRequest{} +} + +// WithPayload adds the payload to the delete config bgp neigh Ip address bad request response +func (o *DeleteConfigBgpNeighIPAddressBadRequest) WithPayload(payload *models.Error) *DeleteConfigBgpNeighIPAddressBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp neigh Ip address bad request response +func (o *DeleteConfigBgpNeighIPAddressBadRequest) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpNeighIPAddressUnauthorizedCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressUnauthorized +const DeleteConfigBgpNeighIPAddressUnauthorizedCode int = 401 + +/* +DeleteConfigBgpNeighIPAddressUnauthorized Invalid authentication credentials + +swagger:response deleteConfigBgpNeighIpAddressUnauthorized +*/ +type DeleteConfigBgpNeighIPAddressUnauthorized struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpNeighIPAddressUnauthorized creates DeleteConfigBgpNeighIPAddressUnauthorized with default headers values +func NewDeleteConfigBgpNeighIPAddressUnauthorized() *DeleteConfigBgpNeighIPAddressUnauthorized { + + return &DeleteConfigBgpNeighIPAddressUnauthorized{} +} + +// WithPayload adds the payload to the delete config bgp neigh Ip address unauthorized response +func (o *DeleteConfigBgpNeighIPAddressUnauthorized) WithPayload(payload *models.Error) *DeleteConfigBgpNeighIPAddressUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp neigh Ip address unauthorized response +func (o *DeleteConfigBgpNeighIPAddressUnauthorized) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpNeighIPAddressForbiddenCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressForbidden +const DeleteConfigBgpNeighIPAddressForbiddenCode int = 403 + +/* +DeleteConfigBgpNeighIPAddressForbidden Capacity insufficient + +swagger:response deleteConfigBgpNeighIpAddressForbidden +*/ +type DeleteConfigBgpNeighIPAddressForbidden struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpNeighIPAddressForbidden creates DeleteConfigBgpNeighIPAddressForbidden with default headers values +func NewDeleteConfigBgpNeighIPAddressForbidden() *DeleteConfigBgpNeighIPAddressForbidden { + + return &DeleteConfigBgpNeighIPAddressForbidden{} +} + +// WithPayload adds the payload to the delete config bgp neigh Ip address forbidden response +func (o *DeleteConfigBgpNeighIPAddressForbidden) WithPayload(payload *models.Error) *DeleteConfigBgpNeighIPAddressForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp neigh Ip address forbidden response +func (o *DeleteConfigBgpNeighIPAddressForbidden) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpNeighIPAddressNotFoundCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressNotFound +const DeleteConfigBgpNeighIPAddressNotFoundCode int = 404 + +/* +DeleteConfigBgpNeighIPAddressNotFound Resource not found + +swagger:response deleteConfigBgpNeighIpAddressNotFound +*/ +type DeleteConfigBgpNeighIPAddressNotFound struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpNeighIPAddressNotFound creates DeleteConfigBgpNeighIPAddressNotFound with default headers values +func NewDeleteConfigBgpNeighIPAddressNotFound() *DeleteConfigBgpNeighIPAddressNotFound { + + return &DeleteConfigBgpNeighIPAddressNotFound{} +} + +// WithPayload adds the payload to the delete config bgp neigh Ip address not found response +func (o *DeleteConfigBgpNeighIPAddressNotFound) WithPayload(payload *models.Error) *DeleteConfigBgpNeighIPAddressNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp neigh Ip address not found response +func (o *DeleteConfigBgpNeighIPAddressNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpNeighIPAddressConflictCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressConflict +const DeleteConfigBgpNeighIPAddressConflictCode int = 409 + +/* +DeleteConfigBgpNeighIPAddressConflict Resource Conflict. Neigh already exists + +swagger:response deleteConfigBgpNeighIpAddressConflict +*/ +type DeleteConfigBgpNeighIPAddressConflict struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpNeighIPAddressConflict creates DeleteConfigBgpNeighIPAddressConflict with default headers values +func NewDeleteConfigBgpNeighIPAddressConflict() *DeleteConfigBgpNeighIPAddressConflict { + + return &DeleteConfigBgpNeighIPAddressConflict{} +} + +// WithPayload adds the payload to the delete config bgp neigh Ip address conflict response +func (o *DeleteConfigBgpNeighIPAddressConflict) WithPayload(payload *models.Error) *DeleteConfigBgpNeighIPAddressConflict { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp neigh Ip address conflict response +func (o *DeleteConfigBgpNeighIPAddressConflict) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(409) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpNeighIPAddressInternalServerErrorCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressInternalServerError +const DeleteConfigBgpNeighIPAddressInternalServerErrorCode int = 500 + +/* +DeleteConfigBgpNeighIPAddressInternalServerError Internal service error + +swagger:response deleteConfigBgpNeighIpAddressInternalServerError +*/ +type DeleteConfigBgpNeighIPAddressInternalServerError struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpNeighIPAddressInternalServerError creates DeleteConfigBgpNeighIPAddressInternalServerError with default headers values +func NewDeleteConfigBgpNeighIPAddressInternalServerError() *DeleteConfigBgpNeighIPAddressInternalServerError { + + return &DeleteConfigBgpNeighIPAddressInternalServerError{} +} + +// WithPayload adds the payload to the delete config bgp neigh Ip address internal server error response +func (o *DeleteConfigBgpNeighIPAddressInternalServerError) WithPayload(payload *models.Error) *DeleteConfigBgpNeighIPAddressInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp neigh Ip address internal server error response +func (o *DeleteConfigBgpNeighIPAddressInternalServerError) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpNeighIPAddressServiceUnavailableCode is the HTTP code returned for type DeleteConfigBgpNeighIPAddressServiceUnavailable +const DeleteConfigBgpNeighIPAddressServiceUnavailableCode int = 503 + +/* +DeleteConfigBgpNeighIPAddressServiceUnavailable Maintanence mode + +swagger:response deleteConfigBgpNeighIpAddressServiceUnavailable +*/ +type DeleteConfigBgpNeighIPAddressServiceUnavailable struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpNeighIPAddressServiceUnavailable creates DeleteConfigBgpNeighIPAddressServiceUnavailable with default headers values +func NewDeleteConfigBgpNeighIPAddressServiceUnavailable() *DeleteConfigBgpNeighIPAddressServiceUnavailable { + + return &DeleteConfigBgpNeighIPAddressServiceUnavailable{} +} + +// WithPayload adds the payload to the delete config bgp neigh Ip address service unavailable response +func (o *DeleteConfigBgpNeighIPAddressServiceUnavailable) WithPayload(payload *models.Error) *DeleteConfigBgpNeighIPAddressServiceUnavailable { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp neigh Ip address service unavailable response +func (o *DeleteConfigBgpNeighIPAddressServiceUnavailable) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpNeighIPAddressServiceUnavailable) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(503) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/api/restapi/operations/delete_config_bgp_neigh_ip_address_urlbuilder.go b/api/restapi/operations/delete_config_bgp_neigh_ip_address_urlbuilder.go new file mode 100644 index 000000000..80dfc51a7 --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_neigh_ip_address_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// DeleteConfigBgpNeighIPAddressURL generates an URL for the delete config bgp neigh IP address operation +type DeleteConfigBgpNeighIPAddressURL struct { + IPAddress string + + RemoteAs *int32 + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteConfigBgpNeighIPAddressURL) WithBasePath(bp string) *DeleteConfigBgpNeighIPAddressURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteConfigBgpNeighIPAddressURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteConfigBgpNeighIPAddressURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/config/bgp/neigh/{ip_address}" + + iPAddress := o.IPAddress + if iPAddress != "" { + _path = strings.Replace(_path, "{ip_address}", iPAddress, -1) + } else { + return nil, errors.New("ipAddress is required on DeleteConfigBgpNeighIPAddressURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/netlox/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var remoteAsQ string + if o.RemoteAs != nil { + remoteAsQ = swag.FormatInt32(*o.RemoteAs) + } + if remoteAsQ != "" { + qs.Set("remote_as", remoteAsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteConfigBgpNeighIPAddressURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteConfigBgpNeighIPAddressURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteConfigBgpNeighIPAddressURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteConfigBgpNeighIPAddressURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteConfigBgpNeighIPAddressURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteConfigBgpNeighIPAddressURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/api/restapi/operations/get_config_cistate_all.go b/api/restapi/operations/get_config_cistate_all.go index 7c792381e..005aef2a9 100644 --- a/api/restapi/operations/get_config_cistate_all.go +++ b/api/restapi/operations/get_config_cistate_all.go @@ -132,6 +132,11 @@ func (o *GetConfigCistateAllOKBody) contextValidateAttr(ctx context.Context, for for i := 0; i < len(o.Attr); i++ { if o.Attr[i] != nil { + + if swag.IsZero(o.Attr[i]) { // not required + return nil + } + if err := o.Attr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigCistateAllOK" + "." + "Attr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_conntrack_all.go b/api/restapi/operations/get_config_conntrack_all.go index b6e73fcae..fdd98f30f 100644 --- a/api/restapi/operations/get_config_conntrack_all.go +++ b/api/restapi/operations/get_config_conntrack_all.go @@ -132,6 +132,11 @@ func (o *GetConfigConntrackAllOKBody) contextValidateCtAttr(ctx context.Context, for i := 0; i < len(o.CtAttr); i++ { if o.CtAttr[i] != nil { + + if swag.IsZero(o.CtAttr[i]) { // not required + return nil + } + if err := o.CtAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigConntrackAllOK" + "." + "ctAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_endpoint_all.go b/api/restapi/operations/get_config_endpoint_all.go index 014afbde5..dc7cb6475 100644 --- a/api/restapi/operations/get_config_endpoint_all.go +++ b/api/restapi/operations/get_config_endpoint_all.go @@ -132,6 +132,11 @@ func (o *GetConfigEndpointAllOKBody) contextValidateAttr(ctx context.Context, fo for i := 0; i < len(o.Attr); i++ { if o.Attr[i] != nil { + + if swag.IsZero(o.Attr[i]) { // not required + return nil + } + if err := o.Attr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigEndpointAllOK" + "." + "Attr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_fdb_all.go b/api/restapi/operations/get_config_fdb_all.go index 64ea648b8..c5181c171 100644 --- a/api/restapi/operations/get_config_fdb_all.go +++ b/api/restapi/operations/get_config_fdb_all.go @@ -132,6 +132,11 @@ func (o *GetConfigFdbAllOKBody) contextValidateFdbAttr(ctx context.Context, form for i := 0; i < len(o.FdbAttr); i++ { if o.FdbAttr[i] != nil { + + if swag.IsZero(o.FdbAttr[i]) { // not required + return nil + } + if err := o.FdbAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigFdbAllOK" + "." + "fdbAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_firewall_all.go b/api/restapi/operations/get_config_firewall_all.go index de42ddaf8..79031bfbd 100644 --- a/api/restapi/operations/get_config_firewall_all.go +++ b/api/restapi/operations/get_config_firewall_all.go @@ -132,6 +132,11 @@ func (o *GetConfigFirewallAllOKBody) contextValidateFwAttr(ctx context.Context, for i := 0; i < len(o.FwAttr); i++ { if o.FwAttr[i] != nil { + + if swag.IsZero(o.FwAttr[i]) { // not required + return nil + } + if err := o.FwAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigFirewallAllOK" + "." + "fwAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_ipv4address_all.go b/api/restapi/operations/get_config_ipv4address_all.go index 4b5c94e83..29e3b484b 100644 --- a/api/restapi/operations/get_config_ipv4address_all.go +++ b/api/restapi/operations/get_config_ipv4address_all.go @@ -132,6 +132,11 @@ func (o *GetConfigIpv4addressAllOKBody) contextValidateIPAttr(ctx context.Contex for i := 0; i < len(o.IPAttr); i++ { if o.IPAttr[i] != nil { + + if swag.IsZero(o.IPAttr[i]) { // not required + return nil + } + if err := o.IPAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigIpv4addressAllOK" + "." + "ipAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_loadbalancer_all.go b/api/restapi/operations/get_config_loadbalancer_all.go index 2f460083e..c7c5146a0 100644 --- a/api/restapi/operations/get_config_loadbalancer_all.go +++ b/api/restapi/operations/get_config_loadbalancer_all.go @@ -132,6 +132,11 @@ func (o *GetConfigLoadbalancerAllOKBody) contextValidateLbAttr(ctx context.Conte for i := 0; i < len(o.LbAttr); i++ { if o.LbAttr[i] != nil { + + if swag.IsZero(o.LbAttr[i]) { // not required + return nil + } + if err := o.LbAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigLoadbalancerAllOK" + "." + "lbAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_mirror_all.go b/api/restapi/operations/get_config_mirror_all.go index 469edc0fa..abc19dc96 100644 --- a/api/restapi/operations/get_config_mirror_all.go +++ b/api/restapi/operations/get_config_mirror_all.go @@ -132,6 +132,11 @@ func (o *GetConfigMirrorAllOKBody) contextValidateMirrAttr(ctx context.Context, for i := 0; i < len(o.MirrAttr); i++ { if o.MirrAttr[i] != nil { + + if swag.IsZero(o.MirrAttr[i]) { // not required + return nil + } + if err := o.MirrAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigMirrorAllOK" + "." + "mirrAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_neighbor_all.go b/api/restapi/operations/get_config_neighbor_all.go index 6898458a8..71424804f 100644 --- a/api/restapi/operations/get_config_neighbor_all.go +++ b/api/restapi/operations/get_config_neighbor_all.go @@ -132,6 +132,11 @@ func (o *GetConfigNeighborAllOKBody) contextValidateNeighborAttr(ctx context.Con for i := 0; i < len(o.NeighborAttr); i++ { if o.NeighborAttr[i] != nil { + + if swag.IsZero(o.NeighborAttr[i]) { // not required + return nil + } + if err := o.NeighborAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigNeighborAllOK" + "." + "neighborAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_policy_all.go b/api/restapi/operations/get_config_policy_all.go index 189bcdc52..73835733a 100644 --- a/api/restapi/operations/get_config_policy_all.go +++ b/api/restapi/operations/get_config_policy_all.go @@ -132,6 +132,11 @@ func (o *GetConfigPolicyAllOKBody) contextValidatePolAttr(ctx context.Context, f for i := 0; i < len(o.PolAttr); i++ { if o.PolAttr[i] != nil { + + if swag.IsZero(o.PolAttr[i]) { // not required + return nil + } + if err := o.PolAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigPolicyAllOK" + "." + "polAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_port_all.go b/api/restapi/operations/get_config_port_all.go index b7e645928..b2c35dfc7 100644 --- a/api/restapi/operations/get_config_port_all.go +++ b/api/restapi/operations/get_config_port_all.go @@ -132,6 +132,11 @@ func (o *GetConfigPortAllOKBody) contextValidatePortAttr(ctx context.Context, fo for i := 0; i < len(o.PortAttr); i++ { if o.PortAttr[i] != nil { + + if swag.IsZero(o.PortAttr[i]) { // not required + return nil + } + if err := o.PortAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigPortAllOK" + "." + "portAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_route_all.go b/api/restapi/operations/get_config_route_all.go index f4430d264..715bd4483 100644 --- a/api/restapi/operations/get_config_route_all.go +++ b/api/restapi/operations/get_config_route_all.go @@ -132,6 +132,11 @@ func (o *GetConfigRouteAllOKBody) contextValidateRouteAttr(ctx context.Context, for i := 0; i < len(o.RouteAttr); i++ { if o.RouteAttr[i] != nil { + + if swag.IsZero(o.RouteAttr[i]) { // not required + return nil + } + if err := o.RouteAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigRouteAllOK" + "." + "routeAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_session_all.go b/api/restapi/operations/get_config_session_all.go index 3e30ac8e8..e51e2c2f0 100644 --- a/api/restapi/operations/get_config_session_all.go +++ b/api/restapi/operations/get_config_session_all.go @@ -132,6 +132,11 @@ func (o *GetConfigSessionAllOKBody) contextValidateSessionAttr(ctx context.Conte for i := 0; i < len(o.SessionAttr); i++ { if o.SessionAttr[i] != nil { + + if swag.IsZero(o.SessionAttr[i]) { // not required + return nil + } + if err := o.SessionAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigSessionAllOK" + "." + "sessionAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_sessionulcl_all.go b/api/restapi/operations/get_config_sessionulcl_all.go index 76db8c587..756518852 100644 --- a/api/restapi/operations/get_config_sessionulcl_all.go +++ b/api/restapi/operations/get_config_sessionulcl_all.go @@ -132,6 +132,11 @@ func (o *GetConfigSessionulclAllOKBody) contextValidateUlclAttr(ctx context.Cont for i := 0; i < len(o.UlclAttr); i++ { if o.UlclAttr[i] != nil { + + if swag.IsZero(o.UlclAttr[i]) { // not required + return nil + } + if err := o.UlclAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigSessionulclAllOK" + "." + "ulclAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_tunnel_vxlan_all.go b/api/restapi/operations/get_config_tunnel_vxlan_all.go index d79cfe1a8..06be74888 100644 --- a/api/restapi/operations/get_config_tunnel_vxlan_all.go +++ b/api/restapi/operations/get_config_tunnel_vxlan_all.go @@ -132,6 +132,11 @@ func (o *GetConfigTunnelVxlanAllOKBody) contextValidateVxlanAttr(ctx context.Con for i := 0; i < len(o.VxlanAttr); i++ { if o.VxlanAttr[i] != nil { + + if swag.IsZero(o.VxlanAttr[i]) { // not required + return nil + } + if err := o.VxlanAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigTunnelVxlanAllOK" + "." + "vxlanAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_config_vlan_all.go b/api/restapi/operations/get_config_vlan_all.go index e38e217be..f52141cd9 100644 --- a/api/restapi/operations/get_config_vlan_all.go +++ b/api/restapi/operations/get_config_vlan_all.go @@ -132,6 +132,11 @@ func (o *GetConfigVlanAllOKBody) contextValidateVlanAttr(ctx context.Context, fo for i := 0; i < len(o.VlanAttr); i++ { if o.VlanAttr[i] != nil { + + if swag.IsZero(o.VlanAttr[i]) { // not required + return nil + } + if err := o.VlanAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getConfigVlanAllOK" + "." + "vlanAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_status_filesystem.go b/api/restapi/operations/get_status_filesystem.go index 817708add..54e463690 100644 --- a/api/restapi/operations/get_status_filesystem.go +++ b/api/restapi/operations/get_status_filesystem.go @@ -132,6 +132,11 @@ func (o *GetStatusFilesystemOKBody) contextValidateFilesystemAttr(ctx context.Co for i := 0; i < len(o.FilesystemAttr); i++ { if o.FilesystemAttr[i] != nil { + + if swag.IsZero(o.FilesystemAttr[i]) { // not required + return nil + } + if err := o.FilesystemAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getStatusFilesystemOK" + "." + "filesystemAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/get_status_process.go b/api/restapi/operations/get_status_process.go index b4fc54b10..4d25fd726 100644 --- a/api/restapi/operations/get_status_process.go +++ b/api/restapi/operations/get_status_process.go @@ -132,6 +132,11 @@ func (o *GetStatusProcessOKBody) contextValidateProcessAttr(ctx context.Context, for i := 0; i < len(o.ProcessAttr); i++ { if o.ProcessAttr[i] != nil { + + if swag.IsZero(o.ProcessAttr[i]) { // not required + return nil + } + if err := o.ProcessAttr[i].ContextValidate(ctx, formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("getStatusProcessOK" + "." + "processAttr" + "." + strconv.Itoa(i)) diff --git a/api/restapi/operations/loxilb_rest_api_api.go b/api/restapi/operations/loxilb_rest_api_api.go index 4e18c0dd8..68444baf6 100644 --- a/api/restapi/operations/loxilb_rest_api_api.go +++ b/api/restapi/operations/loxilb_rest_api_api.go @@ -42,6 +42,9 @@ func NewLoxilbRestAPIAPI(spec *loads.Document) *LoxilbRestAPIAPI { JSONProducer: runtime.JSONProducer(), + DeleteConfigBgpNeighIPAddressHandler: DeleteConfigBgpNeighIPAddressHandlerFunc(func(params DeleteConfigBgpNeighIPAddressParams) middleware.Responder { + return middleware.NotImplemented("operation DeleteConfigBgpNeighIPAddress has not yet been implemented") + }), DeleteConfigEndpointEpipaddressIPAddressHandler: DeleteConfigEndpointEpipaddressIPAddressHandlerFunc(func(params DeleteConfigEndpointEpipaddressIPAddressParams) middleware.Responder { return middleware.NotImplemented("operation DeleteConfigEndpointEpipaddressIPAddress has not yet been implemented") }), @@ -153,6 +156,12 @@ func NewLoxilbRestAPIAPI(spec *loads.Document) *LoxilbRestAPIAPI { GetStatusProcessHandler: GetStatusProcessHandlerFunc(func(params GetStatusProcessParams) middleware.Responder { return middleware.NotImplemented("operation GetStatusProcess has not yet been implemented") }), + PostConfigBgpGlobalHandler: PostConfigBgpGlobalHandlerFunc(func(params PostConfigBgpGlobalParams) middleware.Responder { + return middleware.NotImplemented("operation PostConfigBgpGlobal has not yet been implemented") + }), + PostConfigBgpNeighHandler: PostConfigBgpNeighHandlerFunc(func(params PostConfigBgpNeighParams) middleware.Responder { + return middleware.NotImplemented("operation PostConfigBgpNeigh has not yet been implemented") + }), PostConfigCistateHandler: PostConfigCistateHandlerFunc(func(params PostConfigCistateParams) middleware.Responder { return middleware.NotImplemented("operation PostConfigCistate has not yet been implemented") }), @@ -240,6 +249,8 @@ type LoxilbRestAPIAPI struct { // - application/json JSONProducer runtime.Producer + // DeleteConfigBgpNeighIPAddressHandler sets the operation handler for the delete config bgp neigh IP address operation + DeleteConfigBgpNeighIPAddressHandler DeleteConfigBgpNeighIPAddressHandler // DeleteConfigEndpointEpipaddressIPAddressHandler sets the operation handler for the delete config endpoint epipaddress IP address operation DeleteConfigEndpointEpipaddressIPAddressHandler DeleteConfigEndpointEpipaddressIPAddressHandler // DeleteConfigFdbMacAddressDevIfNameHandler sets the operation handler for the delete config fdb mac address dev if name operation @@ -314,6 +325,10 @@ type LoxilbRestAPIAPI struct { GetStatusFilesystemHandler GetStatusFilesystemHandler // GetStatusProcessHandler sets the operation handler for the get status process operation GetStatusProcessHandler GetStatusProcessHandler + // PostConfigBgpGlobalHandler sets the operation handler for the post config bgp global operation + PostConfigBgpGlobalHandler PostConfigBgpGlobalHandler + // PostConfigBgpNeighHandler sets the operation handler for the post config bgp neigh operation + PostConfigBgpNeighHandler PostConfigBgpNeighHandler // PostConfigCistateHandler sets the operation handler for the post config cistate operation PostConfigCistateHandler PostConfigCistateHandler // PostConfigEndpointHandler sets the operation handler for the post config endpoint operation @@ -425,6 +440,9 @@ func (o *LoxilbRestAPIAPI) Validate() error { unregistered = append(unregistered, "JSONProducer") } + if o.DeleteConfigBgpNeighIPAddressHandler == nil { + unregistered = append(unregistered, "DeleteConfigBgpNeighIPAddressHandler") + } if o.DeleteConfigEndpointEpipaddressIPAddressHandler == nil { unregistered = append(unregistered, "DeleteConfigEndpointEpipaddressIPAddressHandler") } @@ -536,6 +554,12 @@ func (o *LoxilbRestAPIAPI) Validate() error { if o.GetStatusProcessHandler == nil { unregistered = append(unregistered, "GetStatusProcessHandler") } + if o.PostConfigBgpGlobalHandler == nil { + unregistered = append(unregistered, "PostConfigBgpGlobalHandler") + } + if o.PostConfigBgpNeighHandler == nil { + unregistered = append(unregistered, "PostConfigBgpNeighHandler") + } if o.PostConfigCistateHandler == nil { unregistered = append(unregistered, "PostConfigCistateHandler") } @@ -675,6 +699,10 @@ func (o *LoxilbRestAPIAPI) initHandlerCache() { o.handlers = make(map[string]map[string]http.Handler) } + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/config/bgp/neigh/{ip_address}"] = NewDeleteConfigBgpNeighIPAddress(o.context, o.DeleteConfigBgpNeighIPAddressHandler) if o.handlers["DELETE"] == nil { o.handlers["DELETE"] = make(map[string]http.Handler) } @@ -826,6 +854,14 @@ func (o *LoxilbRestAPIAPI) initHandlerCache() { if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) } + o.handlers["POST"]["/config/bgp/global"] = NewPostConfigBgpGlobal(o.context, o.PostConfigBgpGlobalHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } + o.handlers["POST"]["/config/bgp/neigh"] = NewPostConfigBgpNeigh(o.context, o.PostConfigBgpNeighHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } o.handlers["POST"]["/config/cistate"] = NewPostConfigCistate(o.context, o.PostConfigCistateHandler) if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) @@ -932,6 +968,6 @@ func (o *LoxilbRestAPIAPI) AddMiddlewareFor(method, path string, builder middlew } o.Init() if h, ok := o.handlers[um][path]; ok { - o.handlers[method][path] = builder(h) + o.handlers[um][path] = builder(h) } } diff --git a/api/restapi/operations/post_config_bgp_global.go b/api/restapi/operations/post_config_bgp_global.go new file mode 100644 index 000000000..c8541bddd --- /dev/null +++ b/api/restapi/operations/post_config_bgp_global.go @@ -0,0 +1,58 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PostConfigBgpGlobalHandlerFunc turns a function with the right signature into a post config bgp global handler +type PostConfigBgpGlobalHandlerFunc func(PostConfigBgpGlobalParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostConfigBgpGlobalHandlerFunc) Handle(params PostConfigBgpGlobalParams) middleware.Responder { + return fn(params) +} + +// PostConfigBgpGlobalHandler interface for that can handle valid post config bgp global params +type PostConfigBgpGlobalHandler interface { + Handle(PostConfigBgpGlobalParams) middleware.Responder +} + +// NewPostConfigBgpGlobal creates a new http.Handler for the post config bgp global operation +func NewPostConfigBgpGlobal(ctx *middleware.Context, handler PostConfigBgpGlobalHandler) *PostConfigBgpGlobal { + return &PostConfigBgpGlobal{Context: ctx, Handler: handler} +} + +/* + PostConfigBgpGlobal swagger:route POST /config/bgp/global postConfigBgpGlobal + +# Adds a BGP global config + +Adds a BGP global config +*/ +type PostConfigBgpGlobal struct { + Context *middleware.Context + Handler PostConfigBgpGlobalHandler +} + +func (o *PostConfigBgpGlobal) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPostConfigBgpGlobalParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/api/restapi/operations/post_config_bgp_global_parameters.go b/api/restapi/operations/post_config_bgp_global_parameters.go new file mode 100644 index 000000000..9b1265998 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_global_parameters.go @@ -0,0 +1,84 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + "github.com/loxilb-io/loxilb/api/models" +) + +// NewPostConfigBgpGlobalParams creates a new PostConfigBgpGlobalParams object +// +// There are no default values defined in the spec. +func NewPostConfigBgpGlobalParams() PostConfigBgpGlobalParams { + + return PostConfigBgpGlobalParams{} +} + +// PostConfigBgpGlobalParams contains all the bound params for the post config bgp global operation +// typically these are obtained from a http.Request +// +// swagger:parameters PostConfigBgpGlobal +type PostConfigBgpGlobalParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*Attributes of bgp global config + Required: true + In: body + */ + Attr *models.BGPGlobalConfig +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPostConfigBgpGlobalParams() beforehand. +func (o *PostConfigBgpGlobalParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.BGPGlobalConfig + if err := route.Consumer.Consume(r.Body, &body); err != nil { + if err == io.EOF { + res = append(res, errors.Required("attr", "body", "")) + } else { + res = append(res, errors.NewParseError("attr", "body", "", err)) + } + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Attr = &body + } + } + } else { + res = append(res, errors.Required("attr", "body", "")) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/restapi/operations/post_config_bgp_global_responses.go b/api/restapi/operations/post_config_bgp_global_responses.go new file mode 100644 index 000000000..9257277de --- /dev/null +++ b/api/restapi/operations/post_config_bgp_global_responses.go @@ -0,0 +1,354 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/loxilb-io/loxilb/api/models" +) + +// PostConfigBgpGlobalNoContentCode is the HTTP code returned for type PostConfigBgpGlobalNoContent +const PostConfigBgpGlobalNoContentCode int = 204 + +/* +PostConfigBgpGlobalNoContent OK + +swagger:response postConfigBgpGlobalNoContent +*/ +type PostConfigBgpGlobalNoContent struct { +} + +// NewPostConfigBgpGlobalNoContent creates PostConfigBgpGlobalNoContent with default headers values +func NewPostConfigBgpGlobalNoContent() *PostConfigBgpGlobalNoContent { + + return &PostConfigBgpGlobalNoContent{} +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(204) +} + +// PostConfigBgpGlobalBadRequestCode is the HTTP code returned for type PostConfigBgpGlobalBadRequest +const PostConfigBgpGlobalBadRequestCode int = 400 + +/* +PostConfigBgpGlobalBadRequest Malformed arguments for API call + +swagger:response postConfigBgpGlobalBadRequest +*/ +type PostConfigBgpGlobalBadRequest struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpGlobalBadRequest creates PostConfigBgpGlobalBadRequest with default headers values +func NewPostConfigBgpGlobalBadRequest() *PostConfigBgpGlobalBadRequest { + + return &PostConfigBgpGlobalBadRequest{} +} + +// WithPayload adds the payload to the post config bgp global bad request response +func (o *PostConfigBgpGlobalBadRequest) WithPayload(payload *models.Error) *PostConfigBgpGlobalBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp global bad request response +func (o *PostConfigBgpGlobalBadRequest) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpGlobalUnauthorizedCode is the HTTP code returned for type PostConfigBgpGlobalUnauthorized +const PostConfigBgpGlobalUnauthorizedCode int = 401 + +/* +PostConfigBgpGlobalUnauthorized Invalid authentication credentials + +swagger:response postConfigBgpGlobalUnauthorized +*/ +type PostConfigBgpGlobalUnauthorized struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpGlobalUnauthorized creates PostConfigBgpGlobalUnauthorized with default headers values +func NewPostConfigBgpGlobalUnauthorized() *PostConfigBgpGlobalUnauthorized { + + return &PostConfigBgpGlobalUnauthorized{} +} + +// WithPayload adds the payload to the post config bgp global unauthorized response +func (o *PostConfigBgpGlobalUnauthorized) WithPayload(payload *models.Error) *PostConfigBgpGlobalUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp global unauthorized response +func (o *PostConfigBgpGlobalUnauthorized) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpGlobalForbiddenCode is the HTTP code returned for type PostConfigBgpGlobalForbidden +const PostConfigBgpGlobalForbiddenCode int = 403 + +/* +PostConfigBgpGlobalForbidden Capacity insufficient + +swagger:response postConfigBgpGlobalForbidden +*/ +type PostConfigBgpGlobalForbidden struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpGlobalForbidden creates PostConfigBgpGlobalForbidden with default headers values +func NewPostConfigBgpGlobalForbidden() *PostConfigBgpGlobalForbidden { + + return &PostConfigBgpGlobalForbidden{} +} + +// WithPayload adds the payload to the post config bgp global forbidden response +func (o *PostConfigBgpGlobalForbidden) WithPayload(payload *models.Error) *PostConfigBgpGlobalForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp global forbidden response +func (o *PostConfigBgpGlobalForbidden) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpGlobalNotFoundCode is the HTTP code returned for type PostConfigBgpGlobalNotFound +const PostConfigBgpGlobalNotFoundCode int = 404 + +/* +PostConfigBgpGlobalNotFound Resource not found + +swagger:response postConfigBgpGlobalNotFound +*/ +type PostConfigBgpGlobalNotFound struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpGlobalNotFound creates PostConfigBgpGlobalNotFound with default headers values +func NewPostConfigBgpGlobalNotFound() *PostConfigBgpGlobalNotFound { + + return &PostConfigBgpGlobalNotFound{} +} + +// WithPayload adds the payload to the post config bgp global not found response +func (o *PostConfigBgpGlobalNotFound) WithPayload(payload *models.Error) *PostConfigBgpGlobalNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp global not found response +func (o *PostConfigBgpGlobalNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpGlobalConflictCode is the HTTP code returned for type PostConfigBgpGlobalConflict +const PostConfigBgpGlobalConflictCode int = 409 + +/* +PostConfigBgpGlobalConflict Resource Conflict. + +swagger:response postConfigBgpGlobalConflict +*/ +type PostConfigBgpGlobalConflict struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpGlobalConflict creates PostConfigBgpGlobalConflict with default headers values +func NewPostConfigBgpGlobalConflict() *PostConfigBgpGlobalConflict { + + return &PostConfigBgpGlobalConflict{} +} + +// WithPayload adds the payload to the post config bgp global conflict response +func (o *PostConfigBgpGlobalConflict) WithPayload(payload *models.Error) *PostConfigBgpGlobalConflict { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp global conflict response +func (o *PostConfigBgpGlobalConflict) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(409) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpGlobalInternalServerErrorCode is the HTTP code returned for type PostConfigBgpGlobalInternalServerError +const PostConfigBgpGlobalInternalServerErrorCode int = 500 + +/* +PostConfigBgpGlobalInternalServerError Internal service error + +swagger:response postConfigBgpGlobalInternalServerError +*/ +type PostConfigBgpGlobalInternalServerError struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpGlobalInternalServerError creates PostConfigBgpGlobalInternalServerError with default headers values +func NewPostConfigBgpGlobalInternalServerError() *PostConfigBgpGlobalInternalServerError { + + return &PostConfigBgpGlobalInternalServerError{} +} + +// WithPayload adds the payload to the post config bgp global internal server error response +func (o *PostConfigBgpGlobalInternalServerError) WithPayload(payload *models.Error) *PostConfigBgpGlobalInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp global internal server error response +func (o *PostConfigBgpGlobalInternalServerError) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpGlobalServiceUnavailableCode is the HTTP code returned for type PostConfigBgpGlobalServiceUnavailable +const PostConfigBgpGlobalServiceUnavailableCode int = 503 + +/* +PostConfigBgpGlobalServiceUnavailable Maintanence mode + +swagger:response postConfigBgpGlobalServiceUnavailable +*/ +type PostConfigBgpGlobalServiceUnavailable struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpGlobalServiceUnavailable creates PostConfigBgpGlobalServiceUnavailable with default headers values +func NewPostConfigBgpGlobalServiceUnavailable() *PostConfigBgpGlobalServiceUnavailable { + + return &PostConfigBgpGlobalServiceUnavailable{} +} + +// WithPayload adds the payload to the post config bgp global service unavailable response +func (o *PostConfigBgpGlobalServiceUnavailable) WithPayload(payload *models.Error) *PostConfigBgpGlobalServiceUnavailable { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp global service unavailable response +func (o *PostConfigBgpGlobalServiceUnavailable) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpGlobalServiceUnavailable) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(503) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/api/restapi/operations/post_config_bgp_global_urlbuilder.go b/api/restapi/operations/post_config_bgp_global_urlbuilder.go new file mode 100644 index 000000000..1a0096ce0 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_global_urlbuilder.go @@ -0,0 +1,87 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// PostConfigBgpGlobalURL generates an URL for the post config bgp global operation +type PostConfigBgpGlobalURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostConfigBgpGlobalURL) WithBasePath(bp string) *PostConfigBgpGlobalURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostConfigBgpGlobalURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PostConfigBgpGlobalURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/config/bgp/global" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/netlox/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PostConfigBgpGlobalURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PostConfigBgpGlobalURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PostConfigBgpGlobalURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PostConfigBgpGlobalURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PostConfigBgpGlobalURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PostConfigBgpGlobalURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/api/restapi/operations/post_config_bgp_neigh.go b/api/restapi/operations/post_config_bgp_neigh.go new file mode 100644 index 000000000..a5c4503bc --- /dev/null +++ b/api/restapi/operations/post_config_bgp_neigh.go @@ -0,0 +1,58 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PostConfigBgpNeighHandlerFunc turns a function with the right signature into a post config bgp neigh handler +type PostConfigBgpNeighHandlerFunc func(PostConfigBgpNeighParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostConfigBgpNeighHandlerFunc) Handle(params PostConfigBgpNeighParams) middleware.Responder { + return fn(params) +} + +// PostConfigBgpNeighHandler interface for that can handle valid post config bgp neigh params +type PostConfigBgpNeighHandler interface { + Handle(PostConfigBgpNeighParams) middleware.Responder +} + +// NewPostConfigBgpNeigh creates a new http.Handler for the post config bgp neigh operation +func NewPostConfigBgpNeigh(ctx *middleware.Context, handler PostConfigBgpNeighHandler) *PostConfigBgpNeigh { + return &PostConfigBgpNeigh{Context: ctx, Handler: handler} +} + +/* + PostConfigBgpNeigh swagger:route POST /config/bgp/neigh postConfigBgpNeigh + +# Adds a BGP Neighbor + +Adds a BGP Neighbor +*/ +type PostConfigBgpNeigh struct { + Context *middleware.Context + Handler PostConfigBgpNeighHandler +} + +func (o *PostConfigBgpNeigh) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPostConfigBgpNeighParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/api/restapi/operations/post_config_bgp_neigh_parameters.go b/api/restapi/operations/post_config_bgp_neigh_parameters.go new file mode 100644 index 000000000..94cfa81b5 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_neigh_parameters.go @@ -0,0 +1,84 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + "github.com/loxilb-io/loxilb/api/models" +) + +// NewPostConfigBgpNeighParams creates a new PostConfigBgpNeighParams object +// +// There are no default values defined in the spec. +func NewPostConfigBgpNeighParams() PostConfigBgpNeighParams { + + return PostConfigBgpNeighParams{} +} + +// PostConfigBgpNeighParams contains all the bound params for the post config bgp neigh operation +// typically these are obtained from a http.Request +// +// swagger:parameters PostConfigBgpNeigh +type PostConfigBgpNeighParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*Attributes of bgp neighbor + Required: true + In: body + */ + Attr *models.BGPNeigh +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPostConfigBgpNeighParams() beforehand. +func (o *PostConfigBgpNeighParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.BGPNeigh + if err := route.Consumer.Consume(r.Body, &body); err != nil { + if err == io.EOF { + res = append(res, errors.Required("attr", "body", "")) + } else { + res = append(res, errors.NewParseError("attr", "body", "", err)) + } + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Attr = &body + } + } + } else { + res = append(res, errors.Required("attr", "body", "")) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/restapi/operations/post_config_bgp_neigh_responses.go b/api/restapi/operations/post_config_bgp_neigh_responses.go new file mode 100644 index 000000000..4e574e51e --- /dev/null +++ b/api/restapi/operations/post_config_bgp_neigh_responses.go @@ -0,0 +1,354 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/loxilb-io/loxilb/api/models" +) + +// PostConfigBgpNeighNoContentCode is the HTTP code returned for type PostConfigBgpNeighNoContent +const PostConfigBgpNeighNoContentCode int = 204 + +/* +PostConfigBgpNeighNoContent OK + +swagger:response postConfigBgpNeighNoContent +*/ +type PostConfigBgpNeighNoContent struct { +} + +// NewPostConfigBgpNeighNoContent creates PostConfigBgpNeighNoContent with default headers values +func NewPostConfigBgpNeighNoContent() *PostConfigBgpNeighNoContent { + + return &PostConfigBgpNeighNoContent{} +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(204) +} + +// PostConfigBgpNeighBadRequestCode is the HTTP code returned for type PostConfigBgpNeighBadRequest +const PostConfigBgpNeighBadRequestCode int = 400 + +/* +PostConfigBgpNeighBadRequest Malformed arguments for API call + +swagger:response postConfigBgpNeighBadRequest +*/ +type PostConfigBgpNeighBadRequest struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpNeighBadRequest creates PostConfigBgpNeighBadRequest with default headers values +func NewPostConfigBgpNeighBadRequest() *PostConfigBgpNeighBadRequest { + + return &PostConfigBgpNeighBadRequest{} +} + +// WithPayload adds the payload to the post config bgp neigh bad request response +func (o *PostConfigBgpNeighBadRequest) WithPayload(payload *models.Error) *PostConfigBgpNeighBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp neigh bad request response +func (o *PostConfigBgpNeighBadRequest) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpNeighUnauthorizedCode is the HTTP code returned for type PostConfigBgpNeighUnauthorized +const PostConfigBgpNeighUnauthorizedCode int = 401 + +/* +PostConfigBgpNeighUnauthorized Invalid authentication credentials + +swagger:response postConfigBgpNeighUnauthorized +*/ +type PostConfigBgpNeighUnauthorized struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpNeighUnauthorized creates PostConfigBgpNeighUnauthorized with default headers values +func NewPostConfigBgpNeighUnauthorized() *PostConfigBgpNeighUnauthorized { + + return &PostConfigBgpNeighUnauthorized{} +} + +// WithPayload adds the payload to the post config bgp neigh unauthorized response +func (o *PostConfigBgpNeighUnauthorized) WithPayload(payload *models.Error) *PostConfigBgpNeighUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp neigh unauthorized response +func (o *PostConfigBgpNeighUnauthorized) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpNeighForbiddenCode is the HTTP code returned for type PostConfigBgpNeighForbidden +const PostConfigBgpNeighForbiddenCode int = 403 + +/* +PostConfigBgpNeighForbidden Capacity insufficient + +swagger:response postConfigBgpNeighForbidden +*/ +type PostConfigBgpNeighForbidden struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpNeighForbidden creates PostConfigBgpNeighForbidden with default headers values +func NewPostConfigBgpNeighForbidden() *PostConfigBgpNeighForbidden { + + return &PostConfigBgpNeighForbidden{} +} + +// WithPayload adds the payload to the post config bgp neigh forbidden response +func (o *PostConfigBgpNeighForbidden) WithPayload(payload *models.Error) *PostConfigBgpNeighForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp neigh forbidden response +func (o *PostConfigBgpNeighForbidden) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpNeighNotFoundCode is the HTTP code returned for type PostConfigBgpNeighNotFound +const PostConfigBgpNeighNotFoundCode int = 404 + +/* +PostConfigBgpNeighNotFound Resource not found + +swagger:response postConfigBgpNeighNotFound +*/ +type PostConfigBgpNeighNotFound struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpNeighNotFound creates PostConfigBgpNeighNotFound with default headers values +func NewPostConfigBgpNeighNotFound() *PostConfigBgpNeighNotFound { + + return &PostConfigBgpNeighNotFound{} +} + +// WithPayload adds the payload to the post config bgp neigh not found response +func (o *PostConfigBgpNeighNotFound) WithPayload(payload *models.Error) *PostConfigBgpNeighNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp neigh not found response +func (o *PostConfigBgpNeighNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpNeighConflictCode is the HTTP code returned for type PostConfigBgpNeighConflict +const PostConfigBgpNeighConflictCode int = 409 + +/* +PostConfigBgpNeighConflict Resource Conflict. + +swagger:response postConfigBgpNeighConflict +*/ +type PostConfigBgpNeighConflict struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpNeighConflict creates PostConfigBgpNeighConflict with default headers values +func NewPostConfigBgpNeighConflict() *PostConfigBgpNeighConflict { + + return &PostConfigBgpNeighConflict{} +} + +// WithPayload adds the payload to the post config bgp neigh conflict response +func (o *PostConfigBgpNeighConflict) WithPayload(payload *models.Error) *PostConfigBgpNeighConflict { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp neigh conflict response +func (o *PostConfigBgpNeighConflict) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(409) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpNeighInternalServerErrorCode is the HTTP code returned for type PostConfigBgpNeighInternalServerError +const PostConfigBgpNeighInternalServerErrorCode int = 500 + +/* +PostConfigBgpNeighInternalServerError Internal service error + +swagger:response postConfigBgpNeighInternalServerError +*/ +type PostConfigBgpNeighInternalServerError struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpNeighInternalServerError creates PostConfigBgpNeighInternalServerError with default headers values +func NewPostConfigBgpNeighInternalServerError() *PostConfigBgpNeighInternalServerError { + + return &PostConfigBgpNeighInternalServerError{} +} + +// WithPayload adds the payload to the post config bgp neigh internal server error response +func (o *PostConfigBgpNeighInternalServerError) WithPayload(payload *models.Error) *PostConfigBgpNeighInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp neigh internal server error response +func (o *PostConfigBgpNeighInternalServerError) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// PostConfigBgpNeighServiceUnavailableCode is the HTTP code returned for type PostConfigBgpNeighServiceUnavailable +const PostConfigBgpNeighServiceUnavailableCode int = 503 + +/* +PostConfigBgpNeighServiceUnavailable Maintanence mode + +swagger:response postConfigBgpNeighServiceUnavailable +*/ +type PostConfigBgpNeighServiceUnavailable struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewPostConfigBgpNeighServiceUnavailable creates PostConfigBgpNeighServiceUnavailable with default headers values +func NewPostConfigBgpNeighServiceUnavailable() *PostConfigBgpNeighServiceUnavailable { + + return &PostConfigBgpNeighServiceUnavailable{} +} + +// WithPayload adds the payload to the post config bgp neigh service unavailable response +func (o *PostConfigBgpNeighServiceUnavailable) WithPayload(payload *models.Error) *PostConfigBgpNeighServiceUnavailable { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post config bgp neigh service unavailable response +func (o *PostConfigBgpNeighServiceUnavailable) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostConfigBgpNeighServiceUnavailable) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(503) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/api/restapi/operations/post_config_bgp_neigh_urlbuilder.go b/api/restapi/operations/post_config_bgp_neigh_urlbuilder.go new file mode 100644 index 000000000..008e425e7 --- /dev/null +++ b/api/restapi/operations/post_config_bgp_neigh_urlbuilder.go @@ -0,0 +1,87 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// PostConfigBgpNeighURL generates an URL for the post config bgp neigh operation +type PostConfigBgpNeighURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostConfigBgpNeighURL) WithBasePath(bp string) *PostConfigBgpNeighURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostConfigBgpNeighURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PostConfigBgpNeighURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/config/bgp/neigh" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/netlox/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PostConfigBgpNeighURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PostConfigBgpNeighURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PostConfigBgpNeighURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PostConfigBgpNeighURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PostConfigBgpNeighURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PostConfigBgpNeighURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/api/swagger.yml b/api/swagger.yml index f15c2a7b2..551aa43d4 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -2099,6 +2099,143 @@ paths: schema: $ref: '#/definitions/Error' +#---------------------------------------------- +# GoBGP +#---------------------------------------------- + '/config/bgp/neigh': + post: + summary: Adds a BGP Neighbor + description: Adds a BGP Neighbor + parameters: + - name: attr + in: body + required: true + description: Attributes of bgp neighbor + schema: + $ref: '#/definitions/BGPNeigh' + responses: + '204': + description: OK + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '403': + description: Capacity insufficient + schema: + $ref: '#/definitions/Error' + '404': + description: Resource not found + schema: + $ref: '#/definitions/Error' + '409': + description: Resource Conflict. + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintanence mode + schema: + $ref: '#/definitions/Error' + + '/config/bgp/neigh/{ip_address}': + delete: + summary: Delete a BGP neighbor + description: Delete a BGP Neighbor + parameters: + - name: ip_address + in: path + type: string + required: true + description: Neighbor IP address + - name: remote_as + in: query + type: integer + format: int32 + required: false + description: Remote ASN number + responses: + '204': + description: OK + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '403': + description: Capacity insufficient + schema: + $ref: '#/definitions/Error' + '404': + description: Resource not found + schema: + $ref: '#/definitions/Error' + '409': + description: Resource Conflict. Neigh already exists + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintanence mode + schema: + $ref: '#/definitions/Error' + + '/config/bgp/global': + post: + summary: Adds a BGP global config + description: Adds a BGP global config + parameters: + - name: attr + in: body + required: true + description: Attributes of bgp global config + schema: + $ref: '#/definitions/BGPGlobalConfig' + responses: + '204': + description: OK + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '403': + description: Capacity insufficient + schema: + $ref: '#/definitions/Error' + '404': + description: Resource not found + schema: + $ref: '#/definitions/Error' + '409': + description: Resource Conflict. + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintanence mode + schema: + $ref: '#/definitions/Error' + #---------------------------------------------- # LoxiLB Prometheus #---------------------------------------------- @@ -2947,3 +3084,26 @@ definitions: logLevel: type: string description: Set level to debug,info,error,warning,notice,critical,emergency,alert + + BGPNeigh: + type: object + properties: + ipAddress: + type: string + description: BGP Nieghbor IP address + remoteAs: + type: integer + description: Remote AS number + + BGPGlobalConfig: + type: object + properties: + routerId: + type: string + description: BGP Router ID + localAs: + type: integer + description: Local AS number + SetNextHopSelf: + type: boolean + description: Adds policy to set next hop as self, if enabled diff --git a/common/common.go b/common/common.go index 6cf435887..dbc2d5e4b 100644 --- a/common/common.go +++ b/common/common.go @@ -262,7 +262,7 @@ type VlanPortMod struct { Tagged bool `json:"tagged"` } -// vlanStat - statistics for vlan interface +// VlanStat - statistics for vlan interface type VlanStat struct { InBytes uint64 InPackets uint64 @@ -305,8 +305,8 @@ type FdbMod struct { Type int } -// IpAddrMod - Info about an ip address -type IpAddrMod struct { +// IPAddrMod - Info about an ip address +type IPAddrMod struct { // Dev - name of the related device Dev string // IP - Actual IP address @@ -325,8 +325,8 @@ type NeighMod struct { HardwareAddr net.HardwareAddr } -// IpAddrGet - Info about an ip addresses -type IpAddrGet struct { +// IPAddrGet - Info about an ip addresses +type IPAddrGet struct { // Dev - name of the related device Dev string // IP - Actual IP address @@ -377,7 +377,7 @@ type RouteMod struct { Dst net.IPNet } -// FwRuleOpts - Information related to Firewall options +// FwOptArg - Information related to Firewall options type FwOptArg struct { // Drop - Drop any matching rule Drop bool `json:"drop"` @@ -465,6 +465,7 @@ const ( LbSelPrio ) +// LBMode - Variable to define LB mode type LBMode int32 const ( @@ -472,7 +473,7 @@ const ( LBModeDefault LBMode = iota // LBModeOneArm - One Arm Mode LBModeOneArm - // LBModeOneArm - Full NAT Mode + // LBModeFullNAT - Full NAT Mode LBModeFullNAT // LBModeDSR - DSR Mode LBModeDSR @@ -523,8 +524,8 @@ type LbEndPointArg struct { State string `json:"state"` } -// LbSecIpArg - Secondary IP -type LbSecIpArg struct { +// LbSecIPArg - Secondary IP +type LbSecIPArg struct { // SecIP - Secondary IP address SecIP string `json:"secondaryIP"` } @@ -534,7 +535,7 @@ type LbRuleMod struct { // Serv - service argument of type LbServiceArg Serv LbServiceArg `json:"serviceArguments"` // SecIPs - Secondary IPs for SCTP multi-homed service - SecIPs []LbSecIpArg `json:"secondaryIPs"` + SecIPs []LbSecIPArg `json:"secondaryIPs"` // Eps - slice containing LbEndPointArg Eps []LbEndPointArg `json:"endpoints"` } @@ -583,6 +584,21 @@ type ParamMod struct { LogLevel string `json:"logLevel"` } +// GoBGPGlobalConfig - Info related to goBGP global config +type GoBGPGlobalConfig struct { + // Local AS number + LocalAs int64 `json:"localAs,omitempty"` + // BGP Router ID + RouterID string `json:"routerId,omitempty"` + SetNHSelf bool `json:"setNextHopSelf,omitempty"` +} + +// GoBGPNeighMod - Info related to goBGP neigh +type GoBGPNeighMod struct { + Addr net.IP `json:"neighIP"` + RemoteAS uint32 `json:"remoteAS"` +} + // Equal - check if two session tunnel entries are equal func (ut *SessTun) Equal(ut1 *SessTun) bool { if ut.TeID == ut1.TeID && ut.Addr.Equal(ut1.Addr) { @@ -622,7 +638,7 @@ type HASMod struct { } // ClusterNodeMod - information related to a cluster node instance -type CluserNodeMod struct { +type ClusterNodeMod struct { // Instance - Cluster Instance Addr net.IP `json:"Addr"` } @@ -760,9 +776,9 @@ type NetHookInterface interface { NetVlanPortDel(*VlanPortMod) (int, error) NetFdbAdd(*FdbMod) (int, error) NetFdbDel(*FdbMod) (int, error) - NetAddrGet() ([]IpAddrGet, error) - NetAddrAdd(*IpAddrMod) (int, error) - NetAddrDel(*IpAddrMod) (int, error) + NetAddrGet() ([]IPAddrGet, error) + NetAddrAdd(*IPAddrMod) (int, error) + NetAddrDel(*IPAddrMod) (int, error) NetNeighGet() ([]NeighMod, error) NetNeighAdd(*NeighMod) (int, error) NetNeighDel(*NeighMod) (int, error) @@ -792,4 +808,7 @@ type NetHookInterface interface { NetEpHostGet() ([]EndPointMod, error) NetParamSet(param ParamMod) (int, error) NetParamGet(param *ParamMod) (int, error) + NetGoBGPNeighAdd(nm *GoBGPNeighMod) (int, error) + NetGoBGPNeighDel(nm *GoBGPNeighMod) (int, error) + NetGoBGPGCAdd(gc *GoBGPGlobalConfig) (int, error) } diff --git a/loxinet/apiclient.go b/loxinet/apiclient.go index a51130af0..2c3b8c277 100644 --- a/loxinet/apiclient.go +++ b/loxinet/apiclient.go @@ -17,6 +17,8 @@ package loxinet import ( + "errors" + cmn "github.com/loxilb-io/loxilb/common" tk "github.com/loxilb-io/loxilib" ) @@ -26,11 +28,13 @@ import ( // NetAPIStruct - empty struct for anchoring client routines type NetAPIStruct struct { + BgpPeerMode bool } // NetAPIInit - Initialize a new instance of NetAPI -func NetAPIInit() *NetAPIStruct { +func NetAPIInit(bgpPeerMode bool) *NetAPIStruct { na := new(NetAPIStruct) + na.BgpPeerMode = bgpPeerMode return na } @@ -69,7 +73,10 @@ func (*NetAPIStruct) NetPortGet() ([]cmn.PortDump, error) { } // NetPortAdd - Add a port in loxinet -func (*NetAPIStruct) NetPortAdd(pm *cmn.PortMod) (int, error) { +func (na *NetAPIStruct) NetPortAdd(pm *cmn.PortMod) (int, error) { + if na.BgpPeerMode { + return PortBaseErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -81,7 +88,10 @@ func (*NetAPIStruct) NetPortAdd(pm *cmn.PortMod) (int, error) { } // NetPortDel - Delete port from loxinet -func (*NetAPIStruct) NetPortDel(pm *cmn.PortMod) (int, error) { +func (na *NetAPIStruct) NetPortDel(pm *cmn.PortMod) (int, error) { + if na.BgpPeerMode { + return PortBaseErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -90,7 +100,10 @@ func (*NetAPIStruct) NetPortDel(pm *cmn.PortMod) (int, error) { } // NetVlanGet - Get Vlan Information of loxinet -func (*NetAPIStruct) NetVlanGet() ([]cmn.VlanGet, error) { +func (na *NetAPIStruct) NetVlanGet() ([]cmn.VlanGet, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } ret, err := mh.zr.Vlans.VlanGet() if err != nil { return nil, err @@ -99,7 +112,10 @@ func (*NetAPIStruct) NetVlanGet() ([]cmn.VlanGet, error) { } // NetVlanAdd - Add vlan info to loxinet -func (*NetAPIStruct) NetVlanAdd(vm *cmn.VlanMod) (int, error) { +func (na *NetAPIStruct) NetVlanAdd(vm *cmn.VlanMod) (int, error) { + if na.BgpPeerMode { + return VlanBaseErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -113,7 +129,10 @@ func (*NetAPIStruct) NetVlanAdd(vm *cmn.VlanMod) (int, error) { } // NetVlanDel - Delete vlan info from loxinet -func (*NetAPIStruct) NetVlanDel(vm *cmn.VlanMod) (int, error) { +func (na *NetAPIStruct) NetVlanDel(vm *cmn.VlanMod) (int, error) { + if na.BgpPeerMode { + return VlanBaseErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -122,7 +141,10 @@ func (*NetAPIStruct) NetVlanDel(vm *cmn.VlanMod) (int, error) { } // NetVlanPortAdd - Add a port to vlan in loxinet -func (*NetAPIStruct) NetVlanPortAdd(vm *cmn.VlanPortMod) (int, error) { +func (na *NetAPIStruct) NetVlanPortAdd(vm *cmn.VlanPortMod) (int, error) { + if na.BgpPeerMode { + return VlanPortCreateErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -131,7 +153,10 @@ func (*NetAPIStruct) NetVlanPortAdd(vm *cmn.VlanPortMod) (int, error) { } // NetVlanPortDel - Delete a port from vlan in loxinet -func (*NetAPIStruct) NetVlanPortDel(vm *cmn.VlanPortMod) (int, error) { +func (na *NetAPIStruct) NetVlanPortDel(vm *cmn.VlanPortMod) (int, error) { + if na.BgpPeerMode { + return VlanPortExistErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -139,15 +164,21 @@ func (*NetAPIStruct) NetVlanPortDel(vm *cmn.VlanPortMod) (int, error) { return ret, err } -// NetIpv4AddrGet - Get an IPv4 Address info from loxinet -func (*NetAPIStruct) NetAddrGet() ([]cmn.IpAddrGet, error) { +// NetAddrGet - Get an IPv4 Address info from loxinet +func (na *NetAPIStruct) NetAddrGet() ([]cmn.IPAddrGet, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } // There is no locking requirement for this operation ret := mh.zr.L3.IfaGet() return ret, nil } // NetAddrAdd - Add an ipv4 address in loxinet -func (*NetAPIStruct) NetAddrAdd(am *cmn.IpAddrMod) (int, error) { +func (na *NetAPIStruct) NetAddrAdd(am *cmn.IPAddrMod) (int, error) { + if na.BgpPeerMode { + return L3AddrErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -156,7 +187,10 @@ func (*NetAPIStruct) NetAddrAdd(am *cmn.IpAddrMod) (int, error) { } // NetAddrDel - Delete an ipv4 address in loxinet -func (*NetAPIStruct) NetAddrDel(am *cmn.IpAddrMod) (int, error) { +func (na *NetAPIStruct) NetAddrDel(am *cmn.IPAddrMod) (int, error) { + if na.BgpPeerMode { + return L3AddrErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -165,13 +199,19 @@ func (*NetAPIStruct) NetAddrDel(am *cmn.IpAddrMod) (int, error) { } // NetNeighGet - Get a neighbor in loxinet -func (*NetAPIStruct) NetNeighGet() ([]cmn.NeighMod, error) { +func (na *NetAPIStruct) NetNeighGet() ([]cmn.NeighMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } ret, err := mh.zr.Nh.NeighGet() return ret, err } // NetNeighAdd - Add a neighbor in loxinet -func (*NetAPIStruct) NetNeighAdd(nm *cmn.NeighMod) (int, error) { +func (na *NetAPIStruct) NetNeighAdd(nm *cmn.NeighMod) (int, error) { + if na.BgpPeerMode { + return NeighErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -186,7 +226,10 @@ func (*NetAPIStruct) NetNeighAdd(nm *cmn.NeighMod) (int, error) { } // NetNeighDel - Delete a neighbor in loxinet -func (*NetAPIStruct) NetNeighDel(nm *cmn.NeighMod) (int, error) { +func (na *NetAPIStruct) NetNeighDel(nm *cmn.NeighMod) (int, error) { + if na.BgpPeerMode { + return NeighErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -195,7 +238,10 @@ func (*NetAPIStruct) NetNeighDel(nm *cmn.NeighMod) (int, error) { } // NetFdbAdd - Add a forwarding database entry in loxinet -func (*NetAPIStruct) NetFdbAdd(fm *cmn.FdbMod) (int, error) { +func (na *NetAPIStruct) NetFdbAdd(fm *cmn.FdbMod) (int, error) { + if na.BgpPeerMode { + return L2ErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() fdbKey := FdbKey{fm.MacAddr, fm.BridgeID} @@ -205,7 +251,11 @@ func (*NetAPIStruct) NetFdbAdd(fm *cmn.FdbMod) (int, error) { } // NetFdbDel - Delete a forwarding database entry in loxinet -func (*NetAPIStruct) NetFdbDel(fm *cmn.FdbMod) (int, error) { +func (na *NetAPIStruct) NetFdbDel(fm *cmn.FdbMod) (int, error) { + if na.BgpPeerMode { + return L2ErrBase, errors.New("running in bgp only mode") + } + fdbKey := FdbKey{fm.MacAddr, fm.BridgeID} mh.mtx.Lock() defer mh.mtx.Unlock() @@ -215,17 +265,23 @@ func (*NetAPIStruct) NetFdbDel(fm *cmn.FdbMod) (int, error) { } // NetRouteGet - Get Route info from loxinet -func (*NetAPIStruct) NetRouteGet() ([]cmn.RouteGet, error) { +func (na *NetAPIStruct) NetRouteGet() ([]cmn.RouteGet, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } // There is no locking requirement for this operation ret, _ := mh.zr.Rt.RouteGet() return ret, nil } // NetRouteAdd - Add a route in loxinet -func (*NetAPIStruct) NetRouteAdd(rm *cmn.RouteMod) (int, error) { +func (na *NetAPIStruct) NetRouteAdd(rm *cmn.RouteMod) (int, error) { var ret int var err error + if na.BgpPeerMode { + return RtNhErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -241,7 +297,10 @@ func (*NetAPIStruct) NetRouteAdd(rm *cmn.RouteMod) (int, error) { } // NetRouteDel - Delete a route in loxinet -func (*NetAPIStruct) NetRouteDel(rm *cmn.RouteMod) (int, error) { +func (na *NetAPIStruct) NetRouteDel(rm *cmn.RouteMod) (int, error) { + if na.BgpPeerMode { + return RtNhErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -250,7 +309,10 @@ func (*NetAPIStruct) NetRouteDel(rm *cmn.RouteMod) (int, error) { } // NetLbRuleAdd - Add a load-balancer rule in loxinet -func (*NetAPIStruct) NetLbRuleAdd(lm *cmn.LbRuleMod) (int, error) { +func (na *NetAPIStruct) NetLbRuleAdd(lm *cmn.LbRuleMod) (int, error) { + if na.BgpPeerMode { + return RuleErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() var ips []string @@ -270,7 +332,10 @@ func (*NetAPIStruct) NetLbRuleAdd(lm *cmn.LbRuleMod) (int, error) { } // NetLbRuleDel - Delete a load-balancer rule in loxinet -func (*NetAPIStruct) NetLbRuleDel(lm *cmn.LbRuleMod) (int, error) { +func (na *NetAPIStruct) NetLbRuleDel(lm *cmn.LbRuleMod) (int, error) { + if na.BgpPeerMode { + return RuleErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -288,20 +353,29 @@ func (*NetAPIStruct) NetLbRuleDel(lm *cmn.LbRuleMod) (int, error) { } // NetLbRuleGet - Get a load-balancer rule from loxinet -func (*NetAPIStruct) NetLbRuleGet() ([]cmn.LbRuleMod, error) { +func (na *NetAPIStruct) NetLbRuleGet() ([]cmn.LbRuleMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } ret, err := mh.zr.Rules.GetNatLbRule() return ret, err } // NetCtInfoGet - Get connection track info from loxinet -func (*NetAPIStruct) NetCtInfoGet() ([]cmn.CtInfo, error) { +func (na *NetAPIStruct) NetCtInfoGet() ([]cmn.CtInfo, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } // There is no locking requirement for this operation ret := mh.dp.DpMapGetCt4() return ret, nil } // NetSessionAdd - Add a 3gpp user-session info in loxinet -func (*NetAPIStruct) NetSessionAdd(sm *cmn.SessionMod) (int, error) { +func (na *NetAPIStruct) NetSessionAdd(sm *cmn.SessionMod) (int, error) { + if na.BgpPeerMode { + return SessErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -310,7 +384,10 @@ func (*NetAPIStruct) NetSessionAdd(sm *cmn.SessionMod) (int, error) { } // NetSessionDel - Delete a 3gpp user-session info in loxinet -func (*NetAPIStruct) NetSessionDel(sm *cmn.SessionMod) (int, error) { +func (na *NetAPIStruct) NetSessionDel(sm *cmn.SessionMod) (int, error) { + if na.BgpPeerMode { + return SessErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -319,7 +396,10 @@ func (*NetAPIStruct) NetSessionDel(sm *cmn.SessionMod) (int, error) { } // NetSessionUlClAdd - Add a 3gpp ulcl-filter info in loxinet -func (*NetAPIStruct) NetSessionUlClAdd(sr *cmn.SessionUlClMod) (int, error) { +func (na *NetAPIStruct) NetSessionUlClAdd(sr *cmn.SessionUlClMod) (int, error) { + if na.BgpPeerMode { + return SessErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -328,7 +408,10 @@ func (*NetAPIStruct) NetSessionUlClAdd(sr *cmn.SessionUlClMod) (int, error) { } // NetSessionUlClDel - Delete a 3gpp ulcl-filter info in loxinet -func (*NetAPIStruct) NetSessionUlClDel(sr *cmn.SessionUlClMod) (int, error) { +func (na *NetAPIStruct) NetSessionUlClDel(sr *cmn.SessionUlClMod) (int, error) { + if na.BgpPeerMode { + return SessErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -337,28 +420,40 @@ func (*NetAPIStruct) NetSessionUlClDel(sr *cmn.SessionUlClMod) (int, error) { } // NetSessionGet - Get 3gpp user-session info in loxinet -func (*NetAPIStruct) NetSessionGet() ([]cmn.SessionMod, error) { +func (na *NetAPIStruct) NetSessionGet() ([]cmn.SessionMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } // There is no locking requirement for this operation ret, err := mh.zr.Sess.SessGet() return ret, err } // NetSessionUlClGet - Get 3gpp ulcl filter info from loxinet -func (*NetAPIStruct) NetSessionUlClGet() ([]cmn.SessionUlClMod, error) { +func (na *NetAPIStruct) NetSessionUlClGet() ([]cmn.SessionUlClMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } // There is no locking requirement for this operation ret, err := mh.zr.Sess.SessUlclGet() return ret, err } // NetPolicerGet - Get a policer in loxinet -func (*NetAPIStruct) NetPolicerGet() ([]cmn.PolMod, error) { +func (na *NetAPIStruct) NetPolicerGet() ([]cmn.PolMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } // There is no locking requirement for this operation ret, err := mh.zr.Pols.PolGetAll() return ret, err } // NetPolicerAdd - Add a policer in loxinet -func (*NetAPIStruct) NetPolicerAdd(pm *cmn.PolMod) (int, error) { +func (na *NetAPIStruct) NetPolicerAdd(pm *cmn.PolMod) (int, error) { + if na.BgpPeerMode { + return PolInfoErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -367,7 +462,10 @@ func (*NetAPIStruct) NetPolicerAdd(pm *cmn.PolMod) (int, error) { } // NetPolicerDel - Delete a policer in loxinet -func (*NetAPIStruct) NetPolicerDel(pm *cmn.PolMod) (int, error) { +func (na *NetAPIStruct) NetPolicerDel(pm *cmn.PolMod) (int, error) { + if na.BgpPeerMode { + return PolInfoErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -376,14 +474,20 @@ func (*NetAPIStruct) NetPolicerDel(pm *cmn.PolMod) (int, error) { } // NetCIStateGet - Get current node cluster state -func (*NetAPIStruct) NetCIStateGet() ([]cmn.HASMod, error) { +func (na *NetAPIStruct) NetCIStateGet() ([]cmn.HASMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } // There is no locking requirement for this operation ret, err := mh.has.CIStateGet() return ret, err } // NetCIStateMod - Modify cluster state -func (*NetAPIStruct) NetCIStateMod(hm *cmn.HASMod) (int, error) { +func (na *NetAPIStruct) NetCIStateMod(hm *cmn.HASMod) (int, error) { + if na.BgpPeerMode { + return CIErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -396,7 +500,10 @@ func (*NetAPIStruct) NetCIStateMod(hm *cmn.HASMod) (int, error) { } // NetFwRuleAdd - Add a firewall rule in loxinet -func (*NetAPIStruct) NetFwRuleAdd(fm *cmn.FwRuleMod) (int, error) { +func (na *NetAPIStruct) NetFwRuleAdd(fm *cmn.FwRuleMod) (int, error) { + if na.BgpPeerMode { + return RuleTupleErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -405,7 +512,10 @@ func (*NetAPIStruct) NetFwRuleAdd(fm *cmn.FwRuleMod) (int, error) { } // NetFwRuleDel - Delete a firewall rule in loxinet -func (*NetAPIStruct) NetFwRuleDel(fm *cmn.FwRuleMod) (int, error) { +func (na *NetAPIStruct) NetFwRuleDel(fm *cmn.FwRuleMod) (int, error) { + if na.BgpPeerMode { + return RuleTupleErr, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -414,13 +524,19 @@ func (*NetAPIStruct) NetFwRuleDel(fm *cmn.FwRuleMod) (int, error) { } // NetFwRuleGet - Get a firewall rule from loxinet -func (*NetAPIStruct) NetFwRuleGet() ([]cmn.FwRuleMod, error) { +func (na *NetAPIStruct) NetFwRuleGet() ([]cmn.FwRuleMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } ret, err := mh.zr.Rules.GetFwRule() return ret, err } // NetEpHostAdd - Add a LB end-point in loxinet -func (*NetAPIStruct) NetEpHostAdd(em *cmn.EndPointMod) (int, error) { +func (na *NetAPIStruct) NetEpHostAdd(em *cmn.EndPointMod) (int, error) { + if na.BgpPeerMode { + return RuleErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -433,7 +549,10 @@ func (*NetAPIStruct) NetEpHostAdd(em *cmn.EndPointMod) (int, error) { } // NetEpHostDel - Delete a LB end-point in loxinet -func (*NetAPIStruct) NetEpHostDel(em *cmn.EndPointMod) (int, error) { +func (na *NetAPIStruct) NetEpHostDel(em *cmn.EndPointMod) (int, error) { + if na.BgpPeerMode { + return RuleErrBase, errors.New("running in bgp only mode") + } mh.mtx.Lock() defer mh.mtx.Unlock() @@ -442,19 +561,57 @@ func (*NetAPIStruct) NetEpHostDel(em *cmn.EndPointMod) (int, error) { } // NetEpHostGet - Get LB end-points from loxinet -func (*NetAPIStruct) NetEpHostGet() ([]cmn.EndPointMod, error) { +func (na *NetAPIStruct) NetEpHostGet() ([]cmn.EndPointMod, error) { + if na.BgpPeerMode { + return nil, errors.New("running in bgp only mode") + } ret, err := mh.zr.Rules.GetEpHosts() return ret, err } // NetParamSet - Set operational params of loxinet -func (*NetAPIStruct) NetParamSet(param cmn.ParamMod) (int, error) { +func (na *NetAPIStruct) NetParamSet(param cmn.ParamMod) (int, error) { + if na.BgpPeerMode { + return 0, errors.New("running in bgp only mode") + } ret, err := mh.ParamSet(param) return ret, err } // NetParamGet - Get operational params of loxinet -func (*NetAPIStruct) NetParamGet(param *cmn.ParamMod) (int, error) { +func (na *NetAPIStruct) NetParamGet(param *cmn.ParamMod) (int, error) { + if na.BgpPeerMode { + return 0, errors.New("running in bgp only mode") + } ret, err := mh.ParamGet(param) return ret, err } + +// NetGoBGPNeighAdd - Add bgp neigh to gobgp +func (na *NetAPIStruct) NetGoBGPNeighAdd(param *cmn.GoBGPNeighMod) (int, error) { + if mh.bgp != nil { + return mh.bgp.BGPNeighMod(true, param.Addr, param.RemoteAS) + } + tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n") + return 0, errors.New("loxilb BGP mode is disabled") + +} + +// NetGoBGPNeighDel - Del bgp neigh from gobgp +func (na *NetAPIStruct) NetGoBGPNeighDel(param *cmn.GoBGPNeighMod) (int, error) { + if mh.bgp != nil { + return mh.bgp.BGPNeighMod(false, param.Addr, param.RemoteAS) + } + tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n") + return 0, errors.New("loxilb BGP mode is disabled") +} + +// NetGoBGPGCAdd - Add bgp global config +func (na *NetAPIStruct) NetGoBGPGCAdd(param *cmn.GoBGPGlobalConfig) (int, error) { + if mh.bgp != nil { + return mh.bgp.BGPGlobalConfigAdd(*param) + } + tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n") + return 0, errors.New("loxilb BGP mode is disabled") + +} diff --git a/loxinet/cluster.go b/loxinet/cluster.go index 8cba3a822..3dd4e9bbb 100644 --- a/loxinet/cluster.go +++ b/loxinet/cluster.go @@ -44,12 +44,14 @@ const ( KAPidFile2 = "/var/run/vrrp.pid" ) +// ClusterInstance - Struct for Cluster Instance information type ClusterInstance struct { State int StateStr string Vip net.IP } +// ClusterNode - Struct for Cluster Node Information type ClusterNode struct { Addr net.IP Status DpStatusT @@ -67,7 +69,7 @@ type CIStateH struct { func kaSpawn() { url := fmt.Sprintf("http://127.0.0.1:%d/config/params", opts.Opts.Port) for true { - if IsLoxiAPIActive(url) == true { + if IsLoxiAPIActive(url) { break } tk.LogIt(tk.LogDebug, "KA - waiting for API server\n") @@ -110,7 +112,7 @@ func kaSpawn() { } } -func (ci *CIStateH) CISync() { +func (h *CIStateH) CISync() { var sm cmn.HASMod var ciState int var ok bool @@ -132,13 +134,13 @@ func (ci *CIStateH) CISync() { continue } - if ciState, ok = ci.StateMap[state]; !ok { + if ciState, ok = h.StateMap[state]; !ok { continue } notify := false - if eci, ok := ci.ClusterMap[inst]; !ok { + if eci, ok := h.ClusterMap[inst]; !ok { notify = true } else { if eci.State != ciState { @@ -151,7 +153,7 @@ func (ci *CIStateH) CISync() { sm.State = state sm.Vip = net.ParseIP(vip) tk.LogIt(tk.LogInfo, "ci-change instance %s - state %s vip %v\n", inst, state, sm.Vip) - ci.CIStateUpdate(sm) + h.CIStateUpdate(sm) } } @@ -160,15 +162,15 @@ func (ci *CIStateH) CISync() { } // CITicker - Periodic ticker for Cluster module -func (ci *CIStateH) CITicker() { +func (h *CIStateH) CITicker() { mh.mtx.Lock() - ci.CISync() + h.CISync() mh.mtx.Unlock() } // CISpawn - Spawn CI application -func (ci *CIStateH) CISpawn() { - if ci.SpawnKa { +func (h *CIStateH) CISpawn() { + if h.SpawnKa { go kaSpawn() } } @@ -208,7 +210,7 @@ func (h *CIStateH) CIStateGetInst(inst string) (string, error) { return ci.StateStr, nil } - return "NOT_DEFINED", errors.New("Not found") + return "NOT_DEFINED", errors.New("not found") } // CIStateGet - routine to get HA state @@ -273,14 +275,15 @@ func (h *CIStateH) CIStateUpdate(cm cmn.HASMod) (int, error) { mh.bgp.UpdateCIState(cm.Instance, ci.State, ci.Vip) } return ci.State, nil - } else { - tk.LogIt(tk.LogError, "[CLUSTER] Invalid State: %s\n", cm.State) - return ci.State, errors.New("Invalid Cluster state") } + + tk.LogIt(tk.LogError, "[CLUSTER] Invalid State: %s\n", cm.State) + return ci.State, errors.New("Invalid Cluster state") + } // ClusterNodeAdd - routine to update cluster nodes -func (h *CIStateH) ClusterNodeAdd(node cmn.CluserNodeMod) (int, error) { +func (h *CIStateH) ClusterNodeAdd(node cmn.ClusterNodeMod) (int, error) { cNode := h.NodeMap[node.Addr.String()] @@ -298,7 +301,7 @@ func (h *CIStateH) ClusterNodeAdd(node cmn.CluserNodeMod) (int, error) { } // ClusterNodeDelete - routine to delete cluster node -func (h *CIStateH) ClusterNodeDelete(node cmn.CluserNodeMod) (int, error) { +func (h *CIStateH) ClusterNodeDelete(node cmn.ClusterNodeMod) (int, error) { cNode := h.NodeMap[node.Addr.String()] diff --git a/loxinet/dpbroker.go b/loxinet/dpbroker.go index 99c23c229..ec00bf0b9 100644 --- a/loxinet/dpbroker.go +++ b/loxinet/dpbroker.go @@ -20,8 +20,6 @@ import ( "bufio" "errors" "fmt" - cmn "github.com/loxilb-io/loxilb/common" - tk "github.com/loxilb-io/loxilib" "io" "net" "net/http" @@ -29,6 +27,9 @@ import ( "runtime/debug" "sync" "time" + + cmn "github.com/loxilb-io/loxilb/common" + tk "github.com/loxilb-io/loxilib" ) // man names constants @@ -317,6 +318,7 @@ type DpCtInfo struct { BlockNum uint16 } +// XSync - Remote sync peer information type XSync struct { RemoteID int RPCState bool @@ -397,6 +399,7 @@ type DpHookInterface interface { DpCtGetAsync() } +// DpPeer - Remote DP Peer information type DpPeer struct { Peer net.IP Client *rpc.Client @@ -445,7 +448,8 @@ func dialHTTPPath(network, address, path string) (*rpc.Client, error) { } } -func (dp *DpH) DpXsyncRpcReset() int { +// DpXsyncRPCReset - Routine to reset Sunc RPC Client connections +func (dp *DpH) DpXsyncRPCReset() int { dp.SyncMtx.Lock() defer dp.SyncMtx.Unlock() for idx := range mh.dp.Peers { @@ -466,6 +470,7 @@ func (dp *DpH) DpXsyncRpcReset() int { return 0 } +// DpXsyncInSync - Routine to check if remote peer is in sync func (dp *DpH) DpXsyncInSync() bool { dp.SyncMtx.Lock() defer dp.SyncMtx.Unlock() @@ -476,6 +481,7 @@ func (dp *DpH) DpXsyncInSync() bool { return false } +// WaitXsyncReady - Routine to wait till it ready for syncing the peer entity func (dp *DpH) WaitXsyncReady(who string) { begin := time.Now() for { @@ -490,7 +496,8 @@ func (dp *DpH) WaitXsyncReady(who string) { } } -func (dp *DpH) DpXsyncRpc(op DpSyncOpT, cti *DpCtInfo) int { +// DpXsyncRPC - Routine for syncing connection information with peers +func (dp *DpH) DpXsyncRPC(op DpSyncOpT, cti *DpCtInfo) int { var reply int timeout := 2 * time.Second dp.SyncMtx.Lock() @@ -643,7 +650,7 @@ func (xs *XSync) DpWorkOnCtGet(async int, ret *int) error { } // Most likely need to reset reverse rpc channel - mh.dp.DpXsyncRpcReset() + mh.dp.DpXsyncRPCReset() tk.LogIt(tk.LogDebug, "RPC - CT Get %d\n", async) mh.dp.DpHooks.DpCtGetAsync() diff --git a/loxinet/dpebpf_linux.go b/loxinet/dpebpf_linux.go index 55dcf34f0..53c710ce5 100644 --- a/loxinet/dpebpf_linux.go +++ b/loxinet/dpebpf_linux.go @@ -191,7 +191,7 @@ func dpEbpfTicker() { // This means around 10s from start if !mh.dpEbpf.CtSync { tk.LogIt(tk.LogDebug, "Get xsync()\n") - ret := mh.dp.DpXsyncRpc(DpSyncGet, nil) + ret := mh.dp.DpXsyncRPC(DpSyncGet, nil) if ret == 0 { mh.dpEbpf.CtSync = true } @@ -202,6 +202,7 @@ func dpEbpfTicker() { } } +// DpEbpfDPLogLevel - Routine to set log level for DP func DpEbpfDPLogLevel(cfg *C.struct_ebpfcfg, debug tk.LogLevelT) { switch debug { case tk.LogAlert: @@ -1650,7 +1651,7 @@ func dpCTMapNotifierWorker(cti *DpCtInfo) { cti.XSync = true cti.NTs = time.Now() // Immediately notify for delete - ret := mh.dp.DpXsyncRpc(DpSyncDelete, cti) + ret := mh.dp.DpXsyncRPC(DpSyncDelete, cti) if ret == 0 { delete(mh.dpEbpf.ctMap, cti.Key()) // This is a strange fix - Sometimes loxilb runs as multiple docker @@ -1690,7 +1691,7 @@ func dpCTMapBcast() { for _, cti := range mh.dpEbpf.ctMap { if cti.Deleted <= 0 && cti.CState == "est" { tot++ - ret := mh.dp.DpXsyncRpc(DpSyncBcast, cti) + ret := mh.dp.DpXsyncRPC(DpSyncBcast, cti) if ret == 0 { rok++ cti.XSync = false @@ -1704,7 +1705,7 @@ func dpCTMapBcast() { cti := new(DpCtInfo) cti.Proto = "xsync" cti.Sport = uint16(mh.self) - mh.dp.DpXsyncRpc(DpSyncBcast, cti) + mh.dp.DpXsyncRPC(DpSyncBcast, cti) } } @@ -1797,10 +1798,10 @@ func dpCTMapChkUpdates() { ret := 0 if cti.Deleted > 0 { - ret = mh.dp.DpXsyncRpc(DpSyncDelete, cti) + ret = mh.dp.DpXsyncRPC(DpSyncDelete, cti) cti.Deleted++ } else { - ret = mh.dp.DpXsyncRpc(DpSyncAdd, cti) + ret = mh.dp.DpXsyncRPC(DpSyncAdd, cti) } if ret == 0 || cti.Deleted > ctiDeleteSyncRetries { cti.XSync = false @@ -1914,10 +1915,9 @@ func (e *DpEbpfH) DpCtDel(w *DpCtInfo) int { if cti == nil { tk.LogIt(tk.LogError, "ctInfo-key (%v) not present\n", mapKey) return EbpfErrCtDel - } else { - delete(mh.dpEbpf.ctMap, mapKey) } + delete(mh.dpEbpf.ctMap, mapKey) C.llb_del_map_elem(C.LL_DP_CT_MAP, unsafe.Pointer(&w.PKey[0])) return 0 diff --git a/loxinet/gobgpclient.go b/loxinet/gobgpclient.go index 8e76b75a9..5e7932f65 100644 --- a/loxinet/gobgpclient.go +++ b/loxinet/gobgpclient.go @@ -34,6 +34,7 @@ import ( "github.com/osrg/gobgp/v3/pkg/apiutil" "github.com/osrg/gobgp/v3/pkg/packet/bgp" nlp "github.com/vishvananda/netlink" + "golang.org/x/sys/unix" "google.golang.org/grpc" apb "google.golang.org/protobuf/types/known/anypb" ) @@ -52,7 +53,7 @@ type goBgpRouteInfo struct { nlri bgp.AddrPrefixInterface attrs []bgp.PathAttributeInterface withdraw bool - pathId uint32 + pathID uint32 } type goBgpEvent struct { @@ -139,7 +140,7 @@ func (gbh *GoBgpH) makeMonitorRouteArgs(p *goBgpRouteInfo, showIdentifier bgp.BG // NLRI // If Add-Path required, append Path Identifier. if showIdentifier != bgp.BGP_ADD_PATH_NONE { - pathStr = append(pathStr, p.pathId) + pathStr = append(pathStr, p.pathID) } pathStr = append(pathStr, p.nlri) @@ -202,12 +203,9 @@ func (gbh *GoBgpH) syncRoute(p *goBgpRouteInfo, showIdentifier bgp.BGPAddPathMod // Make netlink route and add route := &nlp.Route{ - Dst: dstIPN, - Gw: nexthop, - } - - if route.Gw.IsUnspecified() { - return nil + Dst: dstIPN, + Gw: nexthop, + Protocol: unix.RTPROT_BGP, } if p.withdraw { @@ -217,6 +215,10 @@ func (gbh *GoBgpH) syncRoute(p *goBgpRouteInfo, showIdentifier bgp.BGPAddPathMod return err } } else { + if nexthop == nil || nexthop.IsUnspecified() { + return nil + } + tk.LogIt(tk.LogDebug, "[GoBGP] ip route add %s via %s\n", route.Dst.String(), route.Gw.String()) if err := nlp.RouteAdd(route); err != nil { tk.LogIt(tk.LogError, "[GoBGP] failed to ip route add. err: %s\n", err.Error()) @@ -241,7 +243,7 @@ func (gbh *GoBgpH) processRoute(pathList []*api.Path) { return } - data := goBgpRouteInfo{nlri: nlri, attrs: attrs, withdraw: p.GetIsWithdraw(), pathId: p.GetIdentifier()} + data := goBgpRouteInfo{nlri: nlri, attrs: attrs, withdraw: p.GetIsWithdraw(), pathID: p.GetIdentifier()} gbh.eventCh <- goBgpEvent{ EventType: bgpRtRecvd, @@ -283,7 +285,7 @@ func (gbh *GoBgpH) GetRoutes(client api.GobgpApiClient) int { Table: &api.WatchEventRequest_Table{ Filters: []*api.WatchEventRequest_Table_Filter{ { - Type: api.WatchEventRequest_Table_Filter_BEST, + Type: api.WatchEventRequest_Table_Filter_ADJIN, }, }, }, @@ -320,7 +322,7 @@ func (gbh *GoBgpH) AdvertiseRoute(rtPrefix string, pLen int, nh string, pref uin LocalPref: pref, }) - if ipv4 == true { + if ipv4 { apiFamily = &api.Family{Afi: api.Family_AFI_IP, Safi: api.Family_SAFI_UNICAST} } else { apiFamily = &api.Family{Afi: api.Family_AFI_IP6, Safi: api.Family_SAFI_UNICAST} @@ -350,10 +352,10 @@ func (gbh *GoBgpH) AdvertiseRoute(rtPrefix string, pLen int, nh string, pref uin }) if err != nil { - tk.LogIt(tk.LogCritical, "Advertised Route add failed: %v\n", err) + tk.LogIt(tk.LogCritical, "[GoBGP] Advertised Route add %s/%d via %s failed: %v\n", rtPrefix, pLen, nh, err) return -1 } - tk.LogIt(tk.LogDebug, "Advertised Route [OK]: %s/%d\n", rtPrefix, pLen) + tk.LogIt(tk.LogDebug, "[GoBGP] Advertised Route [OK]: %s/%d via %s\n", rtPrefix, pLen, nh) return 0 } @@ -396,7 +398,7 @@ func (gbh *GoBgpH) DelAdvertiseRoute(rtPrefix string, pLen int, nh string, pref } // GoBgpInit - initialize goBGP client subsystem -func GoBgpInit() *GoBgpH { +func GoBgpInit(bgpPeerMode bool) *GoBgpH { //gbh = new(GoBgpH) gbh := new(GoBgpH) @@ -404,33 +406,39 @@ func GoBgpInit() *GoBgpH { gbh.host = "127.0.0.1:50051" gbh.ciMap = make(map[string]*goCI) gbh.state = BGPDisconnected - go gbh.goBgpSpawn() + go gbh.goBgpSpawn(bgpPeerMode) go gbh.goBgpConnect(gbh.host) go gbh.goBgpMonitor() return gbh } -func (gbh *GoBgpH) goBgpSpawn() { +func (gbh *GoBgpH) goBgpSpawn(bgpPeerMode bool) { command := "pkill gobgpd" cmd := exec.Command("bash", "-c", command) err := cmd.Run() if err != nil { tk.LogIt(tk.LogError, "Error in stopping gpbgp:%s\n", err) } - mh.dp.WaitXsyncReady("bgp") + if !bgpPeerMode { + mh.dp.WaitXsyncReady("bgp") + } // We need some cool-off period for loxilb to self sync-up in the cluster time.Sleep(GoBGPInitTiVal * time.Second) for { cfgOpts := "" - - if _, err := os.Stat("/etc/gobgp/gobgp.conf"); errors.Is(err, os.ErrNotExist) { - if _, err := os.Stat("/etc/gobgp/gobgp_loxilb.yaml"); errors.Is(err, os.ErrNotExist) { - time.Sleep(2000 * time.Millisecond) - continue + confFile := fmt.Sprintf("%s%s.conf", "/etc/gobgp/gobgp", os.Getenv("HOSTNAME")) + if _, err := os.Stat(confFile); errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat("/etc/gobgp/gobgp.conf"); errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat("/etc/gobgp/gobgp_loxilb.yaml"); errors.Is(err, os.ErrNotExist) { + tk.LogIt(tk.LogError, "No BGP conf file found\n") + } else { + cfgOpts = "-t yaml -f /etc/gobgp/gobgp_loxilb.yaml" + } + } else { + cfgOpts = "-f /etc/gobgp/gobgp.conf" } - cfgOpts = "-t yaml -f /etc/gobgp/gobgp_loxilb.yaml" } else { - cfgOpts = "-f /etc/gobgp/gobgp.conf" + cfgOpts = "-f " + confFile } command := fmt.Sprintf("gobgpd %s", cfgOpts) @@ -463,6 +471,13 @@ func (gbh *GoBgpH) goBgpConnect(host string) { time.Sleep(2000 * time.Millisecond) continue } + tk.LogIt(tk.LogNotice, "BGP server %s UP!\n", gbh.host) + if r.Global.Asn == 0 { + tk.LogIt(tk.LogInfo, "BGP Global Config %s not done. Will wait!\n", gbh.host) + gbh.mtx.Unlock() + time.Sleep(2000 * time.Millisecond) + continue + } tk.LogIt(tk.LogNotice, "BGP session %s ready! Attributes[%v]\n", gbh.host, r) gbh.mtx.Unlock() @@ -576,18 +591,22 @@ func (gbh *GoBgpH) AddCurrentBgpRoutesToIPRoute() error { for _, r := range rib { _, dstIPN, err := net.ParseCIDR(r.GetPrefix()) if err != nil { - return fmt.Errorf("%s is invalid prefix\n", r.GetPrefix()) + tk.LogIt(tk.LogError, "%s is invalid prefix\n", r.GetPrefix()) + return err } var nlpRoute *nlp.Route + var nexthopIP net.IP for _, p := range r.Paths { if !p.Best { continue } - - nexthopIP := net.ParseIP(p.GetNeighborIp()) - if nexthopIP == nil { - tk.LogIt(tk.LogDebug, "prefix %s neighbor_ip %s is invalid\n", r.GetPrefix(), p.GetNeighborIp()) + attrs, err := apiutil.GetNativePathAttributes(p) + if err != nil { + continue + } + if nexthopIP = gbh.getNextHopFromPathAttributes(attrs); nexthopIP == nil { + //tk.LogIt(tk.LogDebug, "prefix %s neighbor %s is invalid\n", r.GetPrefix(), p.GetNeighborIp()) continue } @@ -599,8 +618,9 @@ func (gbh *GoBgpH) AddCurrentBgpRoutesToIPRoute() error { if nlpRoute == nil && len(r.Paths) > 0 { nlpRoute = &nlp.Route{ - Dst: dstIPN, - Gw: net.ParseIP(r.Paths[0].GetNeighborIp()), + Dst: dstIPN, + Gw: net.ParseIP(r.Paths[0].GetNeighborIp()), + Protocol: unix.RTPROT_BGP, } } if nlpRoute.Gw.IsUnspecified() { @@ -657,6 +677,9 @@ func (gbh *GoBgpH) getGoBgpRoutes() { } } + /* Get local routes and advertise */ + //getRoutesAndAdvertise() + if err := gbh.AddCurrentBgpRoutesToIPRoute(); err != nil { tk.LogIt(tk.LogError, "[GoBGP] AddCurrentBgpRoutesToIpRoute() return err: %s\n", err.Error()) } @@ -680,7 +703,7 @@ func (gbh *GoBgpH) processBgpEvent(e goBgpEvent) { gbh.state = BGPConnected gbh.getGoBgpRoutes() case bgpRtRecvd: - gbh.processRouteSingle(&e.Data, bgp.BGP_ADD_PATH_NONE) + gbh.processRouteSingle(&e.Data, bgp.BGP_ADD_PATH_RECEIVE) } } @@ -699,6 +722,7 @@ func (gbh *GoBgpH) goBgpMonitor() { } } +// UpdateCIState - Routine to update CI state for this module and re-advertise with appropriate priority func (gbh *GoBgpH) UpdateCIState(instance string, state int, vip net.IP) { ci := gbh.ciMap[instance] if ci == nil { @@ -713,3 +737,172 @@ func (gbh *GoBgpH) UpdateCIState(instance string, state int, vip net.IP) { gbh.advertiseAllRoutes(instance) tk.LogIt(tk.LogNotice, "[BGP] Instance %s(%v) HA state updated : %d\n", instance, vip, state) } + +// BGPNeighMod - Routine to add BGP neigh to goBGP server +func (gbh *GoBgpH) BGPNeighMod(add bool, neigh net.IP, ras uint32) (int, error) { + var peer *api.Peer + var err error + + peer = &api.Peer{ + Conf: &api.PeerConf{}, + State: &api.PeerState{}, + RouteServer: &api.RouteServer{}, + RouteReflector: &api.RouteReflector{}, + } + peer.Conf.NeighborAddress = neigh.String() + peer.State.NeighborAddress = neigh.String() + peer.Conf.PeerAsn = ras + if add { + _, err = gbh.client.AddPeer(context.Background(), + &api.AddPeerRequest{ + Peer: peer, + }) + + } else { + _, err = gbh.client.DeletePeer(context.Background(), + &api.DeletePeerRequest{ + Address: neigh.String(), + }) + } + if err != nil { + return -1, err + } + return 0, nil +} + +// createSelfNHpolicy - Routine to create policy statement +func (gbh *GoBgpH) createNHpolicyStmt(name string, addr string) (int, error) { + st := &api.Statement{ + Name: name, + Actions: &api.Actions{}, + } + st.Actions.Nexthop = &api.NexthopAction{} + st.Actions.Nexthop.Address = addr + _, err := gbh.client.AddStatement(context.Background(), + &api.AddStatementRequest{ + Statement: st, + }) + return 0, err +} + +// addPolicy - Routine to apply global policy statement +func (gbh *GoBgpH) addPolicy(name string, stmt string) (int, error) { + stmts := make([]*api.Statement, 0, 1) + stmts = append(stmts, &api.Statement{Name: stmt}) + p := &api.Policy{ + Name: name, + Statements: stmts, + } + + _, err := gbh.client.AddPolicy(context.Background(), + &api.AddPolicyRequest{ + Policy: p, + ReferExistingStatements: true, + }) + return 0, err +} + +// addPolicy - Routine to apply global policy statement +func (gbh *GoBgpH) applyExportPolicy(remoteIP string, name string) (int, error) { + assign := &api.PolicyAssignment{Name: remoteIP} + assign.Direction = api.PolicyDirection_EXPORT + assign.DefaultAction = api.RouteAction_NONE + ps := make([]*api.Policy, 0, 1) + ps = append(ps, &api.Policy{Name: name}) + assign.Policies = ps + _, err := gbh.client.AddPolicyAssignment(context.Background(), + &api.AddPolicyAssignmentRequest{ + Assignment: assign, + }) + + return 0, err +} + +// BGPNeighMod - Routine to add BGP neigh to goBGP server +func (gbh *GoBgpH) BGPGlobalConfigAdd(config cmn.GoBGPGlobalConfig) (int, error) { + lalist := make([]string, 0, 1) + lalist = append(lalist, "0.0.0.0") + + _, err := gbh.client.StartBgp(context.Background(), &api.StartBgpRequest{ + Global: &api.Global{ + Asn: uint32(config.LocalAs), + RouterId: config.RouterID, + ListenAddresses: lalist, + }, + }) + + if err != nil { + return -1, err + } + + if config.SetNHSelf { + // Create the set-next-hop-self policy statement + if _, err := gbh.createNHpolicyStmt("set-next-hop-self-gstmt", "self"); err != nil { + tk.LogIt(tk.LogError, "[GoBGP] Error creating set-next-hop-self stmt %s\n", err.Error()) + return 0, err + } + + // Create the global policy + if _, err := gbh.addPolicy("set-next-hop-self-gpolicy", "set-next-hop-self-gstmt"); err != nil { + tk.LogIt(tk.LogError, "[GoBGP] Error creating set-next-hop-self policy%s\n", err.Error()) + return 0, err + } + + // Apply the global policy + if _, err := gbh.applyExportPolicy("global", "set-next-hop-self-gpolicy"); err != nil { + tk.LogIt(tk.LogError, "[GoBGP] Error applying set-next-hop-self policy%s\n", err.Error()) + return 0, err + } + } + + return 0, err +} + +func getRoutesAndAdvertise() { + + var ipNet net.IPNet + var nh string + + /* Get Routes and advertise */ + routes, err := nlp.RouteList(nil, nlp.FAMILY_ALL) + if err != nil { + tk.LogIt(tk.LogError, "[GoBGP] Error getting route list %v\n", err) + return + } + + if len(routes) != 0 { + for _, route := range routes { + /* Filter already added BGP routes */ + if route.Protocol == unix.RTPROT_BGP { + continue + } + + if route.Dst == nil { + r := net.IPv4(0, 0, 0, 0) + m := net.CIDRMask(0, 32) + r = r.Mask(m) + ipNet = net.IPNet{IP: r, Mask: m} + } else { + ipNet = *route.Dst + } + prefix := ipNet.IP.String() + plen, _ := ipNet.Mask.Size() + + if ipNet.IP.To4() != nil { + if route.Gw != nil { + nh = route.Gw.String() + } else { + nh = "0.0.0.0" + } + mh.bgp.AdvertiseRoute(prefix, plen, nh, cmn.HighLocalPref, true) + } else { + if route.Gw != nil { + nh = route.Gw.String() + } else { + nh = "0.0.0.0" + } + mh.bgp.AdvertiseRoute(prefix, plen, nh, cmn.HighLocalPref, false) + } + } + } +} diff --git a/loxinet/layer3.go b/loxinet/layer3.go index 828f1ae43..ecb060c1f 100644 --- a/loxinet/layer3.go +++ b/loxinet/layer3.go @@ -393,10 +393,10 @@ func (l3 *L3H) IfObjMkString(obj string, v4 bool) string { } // IfaGet - Get All of the IPv4Address in the Ifa -func (l3 *L3H) IfaGet() []cmn.IpAddrGet { - var ret []cmn.IpAddrGet +func (l3 *L3H) IfaGet() []cmn.IPAddrGet { + var ret []cmn.IPAddrGet for ifName, ifa := range l3.IfaMap { - var tmpIPa cmn.IpAddrGet + var tmpIPa cmn.IPAddrGet tmpIPa.Dev = ifName.Obj tmpIPa.Sync = cmn.DpStatusT(ifa.Sync) for _, ip := range ifa.Ifas { diff --git a/loxinet/loxinet.go b/loxinet/loxinet.go index 8d7164f4f..ad3f7f303 100644 --- a/loxinet/loxinet.go +++ b/loxinet/loxinet.go @@ -164,7 +164,7 @@ func (mh *loxiNetH) ParamGet(param *cmn.ParamMod) (int, error) { } // loxiNetTicker - this ticker routine runs every LOXINET_TIVAL seconds -func loxiNetTicker() { +func loxiNetTicker(bgpPeerMode bool) { for { select { case <-mh.tDone: @@ -184,14 +184,18 @@ func loxiNetTicker() { pprof.StopCPUProfile() } else if sig == syscall.SIGINT || sig == syscall.SIGTERM { tk.LogIt(tk.LogCritical, "Shutdown on sig %v\n", sig) - mh.dpEbpf.DpEbpfUnInit() + if !bgpPeerMode { + mh.dpEbpf.DpEbpfUnInit() + } apiserver.ApiServerShutOk() } case t := <-mh.ticker.C: tk.LogIt(-1, "Tick at %v\n", t) - // Do any housekeeping activities for security zones - mh.zn.ZoneTicker() - mh.has.CITicker() + if !bgpPeerMode { + // Do any housekeeping activities for security zones + mh.zn.ZoneTicker() + mh.has.CITicker() + } } } } @@ -219,7 +223,7 @@ func loxiNetInit() { // It is important to make sure loxilb's eBPF filesystem // is in place and mounted to make sure maps are pinned properly - if FileExists(BpfFsCheckFile) == false { + if !FileExists(BpfFsCheckFile) { if FileExists(MkfsScript) { RunCommand(MkfsScript, true) } @@ -248,67 +252,75 @@ func loxiNetInit() { } } - // Initialize the ebpf datapath subsystem - mh.dpEbpf = DpEbpfInit(clusterMode, mh.self, mh.rssEn, mh.eHooks, -1) - mh.dp = DpBrokerInit(mh.dpEbpf) + if !opts.Opts.BgpPeerMode { + // Initialize the ebpf datapath subsystem + mh.dpEbpf = DpEbpfInit(clusterMode, mh.self, mh.rssEn, mh.eHooks, -1) + mh.dp = DpBrokerInit(mh.dpEbpf) - // Initialize the security zone subsystem - mh.zn = ZoneInit() + // Initialize the security zone subsystem + mh.zn = ZoneInit() - // Add a root zone by default - mh.zn.ZoneAdd(RootZone) - mh.zr, _ = mh.zn.Zonefind(RootZone) - if mh.zr == nil { - tk.LogIt(tk.LogError, "root zone not found\n") - return - } + // Add a root zone by default + mh.zn.ZoneAdd(RootZone) + mh.zr, _ = mh.zn.Zonefind(RootZone) + if mh.zr == nil { + tk.LogIt(tk.LogError, "root zone not found\n") + return + } - // Initialize the clustering subsystem - mh.has = CIInit(spawnKa, kaMode) - if clusterMode { - // Add cluster nodes if specified - cNodes := strings.Split(opts.Opts.ClusterNodes, ",") - for _, cNode := range cNodes { - addr := net.ParseIP(cNode) - if addr == nil { - continue + // Initialize the clustering subsystem + mh.has = CIInit(spawnKa, kaMode) + if clusterMode { + // Add cluster nodes if specified + cNodes := strings.Split(opts.Opts.ClusterNodes, ",") + for _, cNode := range cNodes { + addr := net.ParseIP(cNode) + if addr == nil { + continue + } + mh.has.ClusterNodeAdd(cmn.ClusterNodeMod{Addr: addr}) } - mh.has.ClusterNodeAdd(cmn.CluserNodeMod{Addr: addr}) } + } else { + // If bgp peer mode is enable then bgp flag has to be set by default + opts.Opts.Bgp = true + //opts.Opts.NoNlp = true + opts.Opts.NoPrometheus = true } // Initialize goBgp client if opts.Opts.Bgp { - mh.bgp = GoBgpInit() + mh.bgp = GoBgpInit(opts.Opts.BgpPeerMode) } // Initialize and spawn the api server subsystem - if opts.Opts.NoApi == false { - apiserver.RegisterAPIHooks(NetAPIInit()) + if !opts.Opts.NoAPI { + apiserver.RegisterAPIHooks(NetAPIInit(opts.Opts.BgpPeerMode)) go apiserver.RunAPIServer() apiserver.WaitAPIServerReady() } // Initialize the nlp subsystem - if opts.Opts.NoNlp == false { - nlp.NlpRegister(NetAPIInit()) - nlp.NlpInit() + if !opts.Opts.NoNlp { + nlp.NlpRegister(NetAPIInit(opts.Opts.BgpPeerMode)) + nlp.NlpInit(opts.Opts.BgpPeerMode) } // Initialize the Prometheus subsystem - if opts.Opts.NoPrometheus == false { - prometheus.PrometheusRegister(NetAPIInit()) + if !opts.Opts.NoPrometheus { + prometheus.PrometheusRegister(NetAPIInit(opts.Opts.BgpPeerMode)) prometheus.Init() } - // Spawn CI maintenance application - mh.has.CISpawn() - + if !opts.Opts.BgpPeerMode { + // Spawn CI maintenance application + mh.has.CISpawn() + } // Initialize the loxinet global ticker(s) mh.tDone = make(chan bool) mh.ticker = time.NewTicker(LoxinetTiVal * time.Second) mh.wg.Add(1) - go loxiNetTicker() + go loxiNetTicker(opts.Opts.BgpPeerMode) mh.ready = true } diff --git a/loxinet/loxinettest.go b/loxinet/loxinettest.go index ae09c3bc8..16ee2f90a 100644 --- a/loxinet/loxinettest.go +++ b/loxinet/loxinettest.go @@ -28,7 +28,7 @@ import ( func TestLoxinet(t *testing.T) { opts.Opts.NoNlp = true - opts.Opts.NoApi = true + opts.Opts.NoAPI = true opts.Opts.CPUProfile = "none" opts.Opts.NoPrometheus = true diff --git a/loxinet/neighbor.go b/loxinet/neighbor.go index ab8af13fb..5560b14b8 100644 --- a/loxinet/neighbor.go +++ b/loxinet/neighbor.go @@ -517,6 +517,7 @@ func (n *NeighH) NeighDelete(Addr net.IP, Zone string) (int, error) { return 0, nil } +// NeighDeleteByPort - Routine to delete all the neigh on this port func (n *NeighH) NeighDeleteByPort(port string) { for _, ne := range n.NeighMap { if ne.OifPort.Name == port { diff --git a/loxinet/rules.go b/loxinet/rules.go index 20dfea2dd..1147ea93b 100644 --- a/loxinet/rules.go +++ b/loxinet/rules.go @@ -165,11 +165,11 @@ const ( // possible types of end-point probe const ( HostProbePing = "ping" - HostProbeConnectTcp = "tcp" - HostProbeConnectUdp = "udp" - HostProbeConnectSctp = "sctp" - HostProbeHttp = "http" - HostProbeHttps = "https" + HostProbeConnectTCP = "tcp" + HostProbeConnectUDP = "udp" + HostProbeConnectSCTP = "sctp" + HostProbeHTTP = "http" + HostProbeHTTPS = "https" HostProbeNone = "none" ) @@ -736,7 +736,7 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) { ret.Serv.ProbeResp = data.hChk.prbResp for _, sip := range data.secIP { - ret.SecIPs = append(ret.SecIPs, cmn.LbSecIpArg{SecIP: sip.sIP.String()}) + ret.SecIPs = append(ret.SecIPs, cmn.LbSecIPArg{SecIP: sip.sIP.String()}) } // Make Endpoints @@ -793,15 +793,15 @@ func (R *RuleH) modNatEpHost(r *ruleEnt, endpoints []ruleNatEp, doAddOp bool, li hopts.probeDuration = DflHostProbeTimeout for _, nep := range endpoints { if r.tuples.l4Prot.val == 6 { - pType = HostProbeConnectTcp + pType = HostProbeConnectTCP pPort = nep.xPort } else if r.tuples.l4Prot.val == 17 { - pType = HostProbeConnectUdp + pType = HostProbeConnectUDP pPort = nep.xPort } else if r.tuples.l4Prot.val == 1 { pType = HostProbePing } else if r.tuples.l4Prot.val == 132 { - pType = HostProbeConnectSctp + pType = HostProbeConnectSCTP pPort = nep.xPort } else { pType = HostProbePing @@ -917,13 +917,13 @@ func (R *RuleH) syncEPHostState2Rule(rule *ruleEnt, checkNow bool) bool { switch na := rule.act.action.(type) { case *ruleNatActs: if rule.tuples.l4Prot.val == 6 { - sType = HostProbeConnectTcp + sType = HostProbeConnectTCP } else if rule.tuples.l4Prot.val == 17 { - sType = HostProbeConnectUdp + sType = HostProbeConnectUDP } else if rule.tuples.l4Prot.val == 1 { sType = HostProbePing } else if rule.tuples.l4Prot.val == 132 { - sType = HostProbeConnectSctp + sType = HostProbeConnectSCTP } else { return rChg } @@ -956,7 +956,7 @@ func (R *RuleH) syncEPHostState2Rule(rule *ruleEnt, checkNow bool) bool { // AddNatLbRule - Add a service LB nat rule. The service details are passed in serv argument, // and end-point information is passed in the slice servEndPoints. On success, // it will return 0 and nil error, else appropriate return code and error string will be set -func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg, servEndPoints []cmn.LbEndPointArg) (int, error) { +func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg, servEndPoints []cmn.LbEndPointArg) (int, error) { var natActs ruleNatActs var nSecIP []ruleNatSIP var ipProto uint8 @@ -982,17 +982,17 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIpArg, // Validate liveness probetype and port if serv.ProbeType != "" { - if serv.ProbeType != HostProbeConnectSctp && - serv.ProbeType != HostProbeConnectTcp && - serv.ProbeType != HostProbeConnectUdp && + if serv.ProbeType != HostProbeConnectSCTP && + serv.ProbeType != HostProbeConnectTCP && + serv.ProbeType != HostProbeConnectUDP && serv.ProbeType != HostProbePing && serv.ProbeType != HostProbeNone { return RuleArgsErr, errors.New("malformed-service-ptype error") } - if (serv.ProbeType == HostProbeConnectSctp || - serv.ProbeType == HostProbeConnectTcp || - serv.ProbeType == HostProbeConnectUdp) && + if (serv.ProbeType == HostProbeConnectSCTP || + serv.ProbeType == HostProbeConnectTCP || + serv.ProbeType == HostProbeConnectUDP) && (serv.ProbePort == 0) { return RuleArgsErr, errors.New("malformed-service-pport error") } @@ -1547,18 +1547,18 @@ func validateEPHostOpts(hostName string, args epHostOpts) (int, error) { } if args.probeType != HostProbePing && - args.probeType != HostProbeConnectTcp && - args.probeType != HostProbeConnectUdp && - args.probeType != HostProbeConnectSctp && - args.probeType != HostProbeHttp && - args.probeType != HostProbeHttps && + args.probeType != HostProbeConnectTCP && + args.probeType != HostProbeConnectUDP && + args.probeType != HostProbeConnectSCTP && + args.probeType != HostProbeHTTP && + args.probeType != HostProbeHTTPS && args.probeType != HostProbeNone { return RuleArgsErr, errors.New("host-args unknown probe type") } - if (args.probeType == HostProbeConnectTcp || - args.probeType == HostProbeConnectUdp || - args.probeType == HostProbeConnectSctp) && + if (args.probeType == HostProbeConnectTCP || + args.probeType == HostProbeConnectUDP || + args.probeType == HostProbeConnectSCTP) && args.probePort == 0 { return RuleArgsErr, errors.New("host-args unknown probe port") } @@ -1590,18 +1590,17 @@ func (R *RuleH) AddEPHost(apiCall bool, hostName string, name string, args epHos return RuleArgsErr, err } // Load CA cert into pool - if args.probeType == HostProbeHttps { + if args.probeType == HostProbeHTTPS { // Check if there exist a CA certificate particularily for this EP rootCACertile := cmn.CertPath + hostName + "/" + cmn.CACertFileName if exists := FileExists(rootCACertile); exists { rootCA, err := ioutil.ReadFile(rootCACertile) if err != nil { tk.LogIt(tk.LogError, "RootCA cert load failed : %v", err) - return RuleArgsErr, errors.New("rootCA cert load failed\n") - } else { - R.rootCAPool.AppendCertsFromPEM(rootCA) - tk.LogIt(tk.LogDebug, "RootCA cert loaded for %s\n", hostName) + return RuleArgsErr, errors.New("rootca cert load failed") } + R.rootCAPool.AppendCertsFromPEM(rootCA) + tk.LogIt(tk.LogDebug, "RootCA cert loaded for %s\n", hostName) } } if name == "" { @@ -1727,12 +1726,12 @@ func (R *RuleH) epCheckNow(ep *epHost) { return } - if ep.opts.probeType == HostProbeConnectTcp || - ep.opts.probeType == HostProbeConnectUdp || - ep.opts.probeType == HostProbeConnectSctp { - if ep.opts.probeType == HostProbeConnectTcp { + if ep.opts.probeType == HostProbeConnectTCP || + ep.opts.probeType == HostProbeConnectUDP || + ep.opts.probeType == HostProbeConnectSCTP { + if ep.opts.probeType == HostProbeConnectTCP { sType = "tcp" - } else if ep.opts.probeType == HostProbeConnectUdp { + } else if ep.opts.probeType == HostProbeConnectUDP { sType = "udp" ret, sIP := R.zone.L3.IfaSelectAny(net.ParseIP(ep.hostName), true) if ret == 0 { @@ -1790,7 +1789,7 @@ func (R *RuleH) epCheckNow(ep *epHost) { ep.transitionEPState(false, 1) } pinger.Stop() - } else if ep.opts.probeType == HostProbeHttp { + } else if ep.opts.probeType == HostProbeHTTP { var addr net.IP if addr = net.ParseIP(ep.hostName); addr == nil { // This is already verified @@ -1800,7 +1799,7 @@ func (R *RuleH) epCheckNow(ep *epHost) { urlStr := fmt.Sprintf("http://%s:%d/%s", addr.String(), ep.opts.probePort, ep.opts.probeReq) sOk := tk.HTTPProber(urlStr) ep.transitionEPState(sOk, inActTryThr) - } else if ep.opts.probeType == HostProbeHttps { + } else if ep.opts.probeType == HostProbeHTTPS { var addr net.IP if addr = net.ParseIP(ep.hostName); addr == nil { // This is already verified diff --git a/loxinet/vlan.go b/loxinet/vlan.go index c5f87aac4..1a2807e55 100644 --- a/loxinet/vlan.go +++ b/loxinet/vlan.go @@ -88,6 +88,7 @@ func VlanValid(vlanID int) bool { return false } +// VlanGet - Routine to get vlan bridge details func (V *VlansH) VlanGet() ([]cmn.VlanGet, error) { ret := []cmn.VlanGet{} for k, v := range V.VlanMap { diff --git a/options/options.go b/options/options.go index ec94e937d..9d8eb364c 100644 --- a/options/options.go +++ b/options/options.go @@ -8,7 +8,7 @@ var Opts struct { Bgp bool `short:"b" long:"bgp" description:"Connect and Sync with GoBGP server"` Ka string `short:"k" long:"ka" description:"One of in,out"` Version bool `short:"v" long:"version" description:"Show loxilb version"` - NoApi bool `short:"a" long:"api" description:"Run Rest API server"` + NoAPI bool `short:"a" long:"api" description:"Run Rest API server"` NoNlp bool `short:"n" long:"nonlp" description:"Do not register with nlp"` Host string `long:"host" description:"the IP to listen on" default:"0.0.0.0" env:"HOST"` Port int `long:"port" description:"the port to listen on for insecure connections" default:"11111" env:"PORT"` @@ -25,4 +25,5 @@ var Opts struct { PassiveEPProbe bool `long:"passive-probe" description:"Enable passive liveness probes(experimental)"` RssEnable bool `long:"rss-enable" description:"Enable rss optimization(experimental)"` EgrHooks bool `long:"egr-hooks" description:"Enable eBPF egress hooks(experimental)"` + BgpPeerMode bool `short:"r" long:"peer" description:"Run loxilb with goBGP only, no Datapath"` }