Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BFD session config with yaml file #22

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/create/create_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,14 @@ func VxlanBridgeCreateWithFile(restOptions *api.RESTOptions, byteBuf []byte) err
}
return nil
}

func BFDCreateWithFile(restOptions *api.RESTOptions, byteBuf []byte) error {
var c api.ConfigurationBFDFile
if err := yaml.Unmarshal(byteBuf, &c); err != nil {
return err
}
if _, err := CreateBFDAPICall(restOptions, c.Spec); err != nil {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion cmd/delete/delete_bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ex) loxicmd delete bfd 32.32.32.2 --instance=default"

resp, err := client.BFDSession().SubResources(subResources).Query(qmap).Delete(ctx)
if err != nil {
fmt.Printf("Error: Failed to delete Firewall")
fmt.Printf("Error: Failed to delete bfd session")
return
}
defer resp.Body.Close()
Expand Down
28 changes: 28 additions & 0 deletions cmd/delete/delete_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func DeleteFileConfig(file string, restOptions *api.RESTOptions) error {
err = VxlanPeerDeleteWithFile(restOptions, byteBuf)
case "Vxlan", "vxlan":
err = VxlanDeleteWithFile(restOptions, byteBuf)
case "bfd", "BFD":
err = BFDDeleteWithFile(restOptions, byteBuf)
default:
fmt.Printf("Not Supported\n")
}
Expand Down Expand Up @@ -432,3 +434,29 @@ func VxlanPeerDeleteWithFile(restOptions *api.RESTOptions, byteBuf []byte) error
}
return nil
}

func BFDDeleteWithFile(restOptions *api.RESTOptions, byteBuf []byte) error {
var c api.ConfigurationBFDFile
if err := yaml.Unmarshal(byteBuf, &c); err != nil {
return err
}
client, ctx, cancel := GetClientWithCtx(restOptions)
if restOptions.Timeout > 0 {
defer cancel()
}

subResources := []string{
"remoteIP", c.Spec.RemoteIP,
}

qmap := map[string]string{}
qmap["instance"] = c.Spec.Instance

resp, err := client.BFDSession().SubResources(subResources).Query(qmap).Delete(ctx)
if err != nil {
fmt.Printf("Error: Failed to delete bfd session")
return nil
}
defer resp.Body.Close()
return nil
}
4 changes: 4 additions & 0 deletions cmd/dump/apply_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package dump

import (
"errors"
"fmt"
"loxicmd/cmd/create"
"loxicmd/pkg/api"
Expand Down Expand Up @@ -71,8 +72,11 @@ func ApplyFileConfig(file string, restOptions *api.RESTOptions) error {
err = create.VxlanPeerCreateWithFile(restOptions, byteBuf)
case "Vxlan", "vxlan":
err = create.VxlanBridgeCreateWithFile(restOptions, byteBuf)
case "BFD", "bfd":
err = create.BFDCreateWithFile(restOptions, byteBuf)
default:
fmt.Printf("Not Supported\n")
return errors.New("not supported")
}
if err != nil {
fmt.Println(err.Error())
Expand Down
5 changes: 2 additions & 3 deletions cmd/set/set_bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewSetBFDCmd(restOptions *api.RESTOptions) *cobra.Command {

Aliases: []string{"bfd-session"},
Run: func(cmd *cobra.Command, args []string) {

// Make bfdMod
if err := ReadSetBfdOptions(&o, args); err != nil {
fmt.Printf("Error: %s\n", err.Error())
Expand All @@ -60,7 +60,7 @@ func NewSetBFDCmd(restOptions *api.RESTOptions) *cobra.Command {
}
SetBFDCmd.Flags().StringVarP(&o.Instance, "instance", "", "default", "Specify the cluster instance name")
SetBFDCmd.Flags().Uint64VarP(&o.Interval, "interval", "", 0, "Specify the BFD packet tx interval (in microseconds)")
SetBFDCmd.Flags().Uint8VarP(&o.RetryCount, "retryCount", "", 0, "Specify the number of reties")
SetBFDCmd.Flags().Uint8VarP(&o.RetryCount, "retryCount", "", 0, "Specify the number of retries")

return SetBFDCmd
}
Expand All @@ -81,7 +81,6 @@ func ReadSetBfdOptions(o *api.BFDSessionInfo, args []string) error {
return nil
}


func SetBFDAPICall(restOptions *api.RESTOptions, bfdModel api.BFDSessionInfo) (*http.Response, error) {
client := api.NewLoxiClient(restOptions)
ctx := context.TODO()
Expand Down
19 changes: 12 additions & 7 deletions pkg/api/bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,29 @@ type BFDSessionGet struct {

type BFDSessionInfo struct {
// Instance name
Instance string `json:"instance,omitempty"`
Instance string `json:"instance" yaml:"instance"`

// RemoteIP - Remote IP for BFD session
RemoteIP string `json:"remoteIp,omitempty"`
RemoteIP string `json:"remoteIp" yaml:"remoteIp"`

// Interval - Tx Interval between BFD packets
SourceIP string `json:"sourceIp,omitempty"`
SourceIP string `json:"sourceIp" yaml:"sourceIp"`

// Port - BFD session port
Port uint16 `json:"port,omitempty"`
Port uint16 `json:"port" yaml:"port"`

// Interval - Tx Interval between BFD packets
Interval uint64 `json:"interval,omitempty"`
Interval uint64 `json:"interval" yaml:"interval"`

// RetryCount - Retry Count for detecting failure
RetryCount uint8 `json:"retryCount,omitempty"`
RetryCount uint8 `json:"retryCount" yaml:"retryCount"`

// Current BFD State
State string `json:"state,omitempty"`
State string `json:"state" yaml:"state"`
}

type ConfigurationBFDFile struct {
TypeMeta `yaml:",inline"`
ObjectMeta `yaml:"metadata,omitempty"`
Spec BFDSessionInfo `yaml:"spec"`
}