Use interface details to populate the ifmib, on startup and after each event
This commit is contained in:
@ -77,19 +77,21 @@ type VPPInterface struct {
|
||||
}
|
||||
|
||||
type InterfaceMIB struct {
|
||||
mutex sync.RWMutex
|
||||
handler *agentx.ListHandler
|
||||
ifEntrySession *agentx.Session
|
||||
ifXTableSession *agentx.Session
|
||||
stats map[uint32]*api.InterfaceCounters // indexed by interface index
|
||||
descriptions map[string]string // interface name -> description mapping
|
||||
mutex sync.RWMutex
|
||||
handler *agentx.ListHandler
|
||||
ifEntrySession *agentx.Session
|
||||
ifXTableSession *agentx.Session
|
||||
stats map[uint32]*api.InterfaceCounters // indexed by interface index
|
||||
descriptions map[string]string // interface name -> description mapping
|
||||
interfaceDetails map[uint32]*vpp.InterfaceDetails // indexed by interface index
|
||||
}
|
||||
|
||||
func NewInterfaceMIB() *InterfaceMIB {
|
||||
return &InterfaceMIB{
|
||||
handler: &agentx.ListHandler{},
|
||||
stats: make(map[uint32]*api.InterfaceCounters),
|
||||
descriptions: make(map[string]string),
|
||||
handler: &agentx.ListHandler{},
|
||||
stats: make(map[uint32]*api.InterfaceCounters),
|
||||
descriptions: make(map[string]string),
|
||||
interfaceDetails: make(map[uint32]*vpp.InterfaceDetails),
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,6 +144,22 @@ func (m *InterfaceMIB) LoadVPPConfig(configPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *InterfaceMIB) UpdateInterfaceDetails(details []vpp.InterfaceDetails) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
logger.Debugf("Updating interface details for %d interfaces", len(details))
|
||||
|
||||
// Update interface details map
|
||||
for _, detail := range details {
|
||||
m.interfaceDetails[uint32(detail.SwIfIndex)] = &detail
|
||||
logger.Debugf("Updated details for interface %d (%s): MAC=%x, Speed=%d",
|
||||
detail.SwIfIndex, detail.InterfaceName, detail.MacAddress, detail.Speed)
|
||||
}
|
||||
|
||||
logger.Debugf("Interface details updated for %d interfaces", len(details))
|
||||
}
|
||||
|
||||
func (m *InterfaceMIB) UpdateStats(interfaceStats *api.InterfaceStats) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
@ -186,6 +204,9 @@ func (m *InterfaceMIB) addInterfaceToMIB(iface *api.InterfaceCounters) {
|
||||
func (m *InterfaceMIB) addIfEntry(iface *api.InterfaceCounters, idx int) {
|
||||
var item *agentx.ListItem
|
||||
|
||||
// Get interface details if available
|
||||
details := m.interfaceDetails[iface.InterfaceIndex]
|
||||
|
||||
// ifIndex (.1)
|
||||
item = m.handler.Add(fmt.Sprintf("%s.1.%d", ifEntryOID, idx))
|
||||
item.Type = pdu.VariableTypeInteger
|
||||
@ -201,30 +222,58 @@ func (m *InterfaceMIB) addIfEntry(iface *api.InterfaceCounters, idx int) {
|
||||
item.Type = pdu.VariableTypeInteger
|
||||
item.Value = int32(6)
|
||||
|
||||
// ifMtu (.4) - Default MTU 1500
|
||||
// ifMtu (.4) - Use real MTU if available, otherwise default to 1500
|
||||
mtu := int32(1500)
|
||||
if details != nil {
|
||||
mtu = int32(details.MTU)
|
||||
}
|
||||
item = m.handler.Add(fmt.Sprintf("%s.4.%d", ifEntryOID, idx))
|
||||
item.Type = pdu.VariableTypeInteger
|
||||
item.Value = int32(1500)
|
||||
item.Value = mtu
|
||||
|
||||
// ifSpeed (.5) - Default to 1Gbps (1000000000 bits/sec)
|
||||
// ifSpeed (.5) - Use real speed if available, otherwise default to 1Gbps
|
||||
speed := uint32(1000000000)
|
||||
if details != nil && details.Speed > 0 {
|
||||
speed = uint32(details.Speed)
|
||||
}
|
||||
item = m.handler.Add(fmt.Sprintf("%s.5.%d", ifEntryOID, idx))
|
||||
item.Type = pdu.VariableTypeGauge32
|
||||
item.Value = uint32(1000000000)
|
||||
item.Value = speed
|
||||
|
||||
// ifPhysAddress (.6) - Empty for now
|
||||
// ifPhysAddress (.6) - Use real MAC address if available
|
||||
macAddr := ""
|
||||
if details != nil && len(details.MacAddress) > 0 {
|
||||
macAddr = string(details.MacAddress)
|
||||
}
|
||||
item = m.handler.Add(fmt.Sprintf("%s.6.%d", ifEntryOID, idx))
|
||||
item.Type = pdu.VariableTypeOctetString
|
||||
item.Value = ""
|
||||
item.Value = macAddr
|
||||
|
||||
// ifAdminStatus (.7) - up(1)
|
||||
// ifAdminStatus (.7) - Use real admin status if available
|
||||
adminStatus := int32(1) // default up
|
||||
if details != nil {
|
||||
if details.AdminStatus {
|
||||
adminStatus = 1 // up
|
||||
} else {
|
||||
adminStatus = 2 // down
|
||||
}
|
||||
}
|
||||
item = m.handler.Add(fmt.Sprintf("%s.7.%d", ifEntryOID, idx))
|
||||
item.Type = pdu.VariableTypeInteger
|
||||
item.Value = int32(1)
|
||||
item.Value = adminStatus
|
||||
|
||||
// ifOperStatus (.8) - up(1)
|
||||
// ifOperStatus (.8) - Use real operational status if available
|
||||
operStatus := int32(1) // default up
|
||||
if details != nil {
|
||||
if details.OperStatus {
|
||||
operStatus = 1 // up
|
||||
} else {
|
||||
operStatus = 2 // down
|
||||
}
|
||||
}
|
||||
item = m.handler.Add(fmt.Sprintf("%s.8.%d", ifEntryOID, idx))
|
||||
item.Type = pdu.VariableTypeInteger
|
||||
item.Value = int32(1)
|
||||
item.Value = operStatus
|
||||
|
||||
// ifLastChange (.9) - 0 (unknown)
|
||||
item = m.handler.Add(fmt.Sprintf("%s.9.%d", ifEntryOID, idx))
|
||||
|
Reference in New Issue
Block a user