Skip to content

Commit

Permalink
intel_app: add ifTable MIB related counters.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Jun 2, 2016
1 parent 793c394 commit 2b9ef2c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 39 deletions.
47 changes: 27 additions & 20 deletions model.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
RFC7223 Snabb
======= ======
RFC7223 Snabb ifTable MIB
======= ===== ===========
name
description?
type type (~= identity)
enabled?
link-up-down-trap-enable?
admin-status
oper-status status (= enum)
oper-status status (= enum) ifOperStatus
last-change?
if-index
phys-address? macaddr (uint64)
phys-address? macaddr (uint64) ifPhysAddress
higher-layer-if*
lower-layer-if*
speed? =
discontinuity-time dtime (seconds since epoch)
in-octets? rxbytes
speed? speed ifSpeed
discontinuity-time dtime (seconds since epoch) ifCounterDiscontinuityTime
in-octets? rxbytes ifInOctets
rxpackets
in-unicast-pkts?
in-broadcast-pkts? rxbcast
in-multicast-pkts?
in-discards?
in-errors?
in-broadcast-pkts? rxbcast ifInBroadcastPkts
rxmcast
in-multicast-pkts? ifInMulticastPkts
in-discards? rxdrop ifInDiscards
in-errors? rxerrors ifInErrors
in-unknown-protos?
out-octets? txbytes
out-octets? txbytes ifOutOctets
txpackets
out-unicast-pkts?
out-broadcast-pkts? txbcast
out-multicast-pkts?
out-discards?
out-errors?

out-broadcast-pkts? txbcast ifOutBroadcastPkts
txmcast
out-multicast-pkts? ifOutMulticastPkts
out-discards? txdrop ifOutDiscards
out-errors? txerrors ifOutErrors
rxpackets
txpackets
rxmcast
txmcast
mtu ifMtu
promisc ifPromiscuousMode

snabb/type:

0x1000 Hardware interface
0x1001 Virtual interface

snabb/stats:
snabb/bcast, mcast, packets:

(tx/rx) - bcast ⊆ mcast ⊆ packets

(tx/rx) - drop (all dropped packets)
69 changes: 50 additions & 19 deletions src/apps/intel/intel_app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ local function firsthole(t)
end
end

local provided_counters = {
'type', 'dtime', 'mtu', 'speed', 'status', 'promisc', 'macaddr',
'rxbytes', 'rxpackets', 'rxmcast', 'rxbcast', 'rxdrop', 'rxerrors',
'txbytes', 'txpackets', 'txmcast', 'txbcast', 'txdrop', 'txerrors'
}

-- Create an Intel82599 App for the device with 'pciaddress'.
function Intel82599:new (arg)
Expand All @@ -43,7 +48,9 @@ function Intel82599:new (arg)
if conf.vmdq then
if devices[conf.pciaddr] == nil then
local pf = intel10g.new_pf(conf):open()
devices[conf.pciaddr] = {pf=pf, vflist={}, stats={register=pf.s}}
devices[conf.pciaddr] = { pf = pf,
vflist = {},
stats = { s = pf.s, r = pf.r, qs = pf.qs } }
end
local dev = devices[conf.pciaddr]
local poolnum = firsthole(dev.vflist)-1
Expand All @@ -53,23 +60,22 @@ function Intel82599:new (arg)
self.stats = devices[conf.pciaddr].stats
else
self.dev = assert(intel10g.new_sf(conf):open(), "Can not open device.")
self.stats = { register = self.dev.s }
self.stats = { s = self.dev.s, r = self.dev.r, qs = self.dev.qs }
self.zone = "intel"
end
if not self.stats.counters then
self.stats.path = "/counters/"..conf.pciaddr.."/"
self.stats.sync_timer = lib.timer(0.001, 'repeating', engine.now)
self.stats.counters = {}
for _, name in ipairs(
{'type', 'dtime',
'rxbytes', 'rxpackets', 'rxmcast', 'rxbcast', 'rxdrop',
'txbytes', 'txpackets', 'txmcast', 'txbcast', 'txdrop'}) do
for _, name in ipairs(provided_counters) do
self.stats.counters[name] = counter.open(self.stats.path..name)
end
counter.set(self.stats.counters.type, 0x1000) -- Hardware interface
counter.set(self.stats.counters.dtime, C.get_unix_time())
counter.set(self.stats.counters.mtu, self.dev.mtu)
counter.set(self.stats.counters.speed, 10000000) -- 10 Gbits
counter.set(self.stats.counters.status, 2) -- down
if not conf.vmdq and conf.macaddr then
self.stats.counters.macaddr = counter.open(self.stats.path..'macaddr')
counter.set(self.stats.counters.macaddr,
macaddress:new(conf.macaddr):int())
end
Expand Down Expand Up @@ -143,26 +149,51 @@ function Intel82599:add_receive_buffers ()
end
end

-- Synchronize self.stats.register a and self.stats.counters.
-- Synchronize self.stats.s/r a and self.stats.counters.
local link_up_mask = lib.bits{Link_up=30}
local promisc_mask = lib.bits{UPE=9}
function Intel82599:sync_stats ()
local counters, register = self.stats.counters, self.stats.register
counter.set(counters.rxbytes, register.GORC64())
counter.set(counters.rxpackets, register.GPRC())
counter.set(counters.rxmcast, register.MPRC())
counter.set(counters.rxbcast, register.BPRC())
counter.set(counters.rxdrop, register.TPR() - register.GPRC())
counter.set(counters.txbytes, register.GOTC64())
counter.set(counters.txpackets, register.GPTC())
counter.set(counters.txmcast, register.MPTC())
counter.set(counters.txbcast, register.BPTC())
counter.set(counters.txdrop, register.TPT() - register.GPTC())
local counters = self.stats.counters
local s, r, qs = self.stats.s, self.stats.r, self.stats.qs
counter.set(counters.rxbytes, s.GORC64())
counter.set(counters.rxpackets, s.GPRC())
local mprc, bprc = s.MPRC(), s.BPRC()
counter.set(counters.rxmcast, mprc + bprc)
counter.set(counters.rxbcast, bprc)
-- The RX receive drop counts are only available through the RX stats
-- register. We only read stats register #0 here.
counter.set(counters.rxdrop, qs.QPRDC[0]())
counter.set(counters.rxerrors, s.TPR() - s.GPRC())
counter.set(counters.txbytes, s.GOTC64())
counter.set(counters.txpackets, s.GPTC())
local mptc, bptc = s.MPTC(), s.BPTC()
counter.set(counters.txmcast, mptc + bptc)
counter.set(counters.txbcast, bptc)
counter.set(counters.txerrors, s.TPT() - s.GPTC())
if bit.band(r.LINKS(), link_up_mask) == link_up_mask then
counter.set(counters.status, 1) -- Up
else
counter.set(counters.status, 2) -- Down
end
if bit.band(r.FCTRL(), promisc_mask) ~= 0ULL then
counter.set(counters.promisc, 1) -- True
else
counter.set(counters.promisc, 2) -- False
end
end

-- Push packets from our 'rx' link onto the network.
function Intel82599:push ()
local l = self.input.rx
if l == nil then return end
while not empty(l) and self.dev:can_transmit() do
-- We must not send packets that are bigger than the MTU. This
-- check is currently disabled to satisfy some selftests until
-- agreement on this strategy is reached.
-- if p.length > self.dev.mtu then
-- counter.add(self.stats.counters.txdrop)
-- packet.free(p)
-- else
do local p = receive(l)
self.dev:transmit(p)
--packet.deref(p)
Expand Down

0 comments on commit 2b9ef2c

Please sign in to comment.