model

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector interface {
	ID() string
	SelectNodeByIP(ip, vrf string) (Node, Port, error)
	SelectPortsByNetwork(net network.AbbrNet, vrf string) []Port
	HitByNetwork(net network.AbbrNet, vrf string) bool
	HitByIp(ip, vrf string) bool
}

Connector 连接器接口

type NextHopInfo

type NextHopInfo struct {
	Interface string
	NextHopIP string
	Connected bool
	Weight    int // 路径权重(用于ECMP)
}

NextHopInfo 下一跳信息

func NewNextHopInfo

func NewNextHopInfo(interfaceName, nextHopIP string, connected bool) *NextHopInfo

NewNextHopInfo 创建下一跳信息

type Node

type Node interface {
	ID() string
	Name() string
	Type() NodeType

	// 路由表管理
	GetRouteTable(vrf string, ipFamily network.IPFamily) (*RouteTable, error)
	SetRouteTable(vrf string, ipFamily network.IPFamily, table *RouteTable) error

	// 路由查询
	QueryRoute(dst network.NetworkList, inPort, vrf string, ipFamily network.IPFamily) (*RouteResult, error)

	// 端口管理
	GetPort(portID string) (Port, error)
	GetPortByName(name string) (Port, error)
	ListPorts() []Port
}

Node 节点接口(抽象,不依赖具体设备类型)

type NodeType

type NodeType string

NodeType 节点类型

const (
	NodeTypeRouter   NodeType = "router"
	NodeTypeFirewall NodeType = "firewall"
	NodeTypeLB       NodeType = "lb"
	NodeTypeSwitch   NodeType = "switch"
)

type PathHop

type PathHop struct {
	Node        string
	InPort      string
	OutPort     string
	VRF         string
	NextHopIP   string
	IsConnected bool
	IsECMP      bool
	HopIndex    int // 跳索引(从0开始)
}

PathHop 路径跳

type PathResult

type PathResult struct {
	PathID    string
	Success   bool
	Hops      []*PathHop
	TotalHops int
	IsECMP    bool
	Error     error
	Metadata  map[string]interface{}
	StartTime time.Time
	EndTime   time.Time
}

PathResult 路径查询结果

func NewPathResult

func NewPathResult(pathID string) *PathResult

NewPathResult 创建路径结果

func (*PathResult) AddHop

func (pr *PathResult) AddHop(hop *PathHop)

AddHop 添加路径跳

func (*PathResult) Complete

func (pr *PathResult) Complete(success bool, err error)

Complete 完成路径

func (*PathResult) PathString

func (pr *PathResult) PathString() string

PathString 返回路径字符串表示

type Port

type Port interface {
	ID() string
	Name() string
	VRF() string
	Node() Node
	IPAddresses(ipFamily network.IPFamily) []string
	ConnectorID() string
}

Port 端口接口

type RouteEntry

type RouteEntry struct {
	Network   *network.IPNet
	NextHops  []*NextHopInfo
	VRF       string
	Connected bool
	DefaultGw bool
}

RouteEntry 路由条目

type RouteMatchResult

type RouteMatchResult struct {
	Match   *tools.Table
	Unmatch *tools.Table
}

RouteMatchResult 路由匹配结果

type RouteResult

type RouteResult struct {
	Matched     bool
	Routes      []*RouteEntry
	OutPorts    []string
	NextHops    []*NextHopInfo
	IsConnected bool // 是否为直连路由
	IsECMP      bool // 是否为ECMP路由
}

RouteResult 路由查询结果

type RouteTable

type RouteTable struct {
	VRF      string
	IPFamily network.IPFamily
	// contains filtered or unexported fields
}

RouteTable 路由表

func NewRouteTable

func NewRouteTable(vrf string, ipFamily network.IPFamily) *RouteTable

NewRouteTable 创建路由表

func NewRouteTableFromAddressTable

func NewRouteTableFromAddressTable(vrf string, ipFamily network.IPFamily, table *network.AddressTable) *RouteTable

NewRouteTableFromAddressTable 从AddressTable创建RouteTable

func (*RouteTable) AddRoute

func (rt *RouteTable) AddRoute(net *network.IPNet, nextHop *network.NextHop) error

AddRoute 添加路由

func (*RouteTable) GetAddressTable

func (rt *RouteTable) GetAddressTable() *network.AddressTable

GetAddressTable 获取AddressTable

func (*RouteTable) GetDefaultGateway

func (rt *RouteTable) GetDefaultGateway() *network.NextHop

GetDefaultGateway 获取默认网关

func (*RouteTable) QueryRoute

func (rt *RouteTable) QueryRoute(dst network.NetworkList) (*RouteMatchResult, error)

QueryRoute 查询路由

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL