diff --git a/Changelog b/Changelog index 0d7d2c9..b5abeac 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,12 @@ +Version 1.3.0 +- import into asomers/ruby-ifconfig on Github +- bug fixes, mostly in the tests +- added support for fibs, media type, and lagg devices on FreeBSD + +Version 1.2.4 +- import into langhorst/ruby-ifconfig on Github +- bug fixes, mostly in the tests + Version 1.2.3 - added addrs_with_mask method in NetworkAdapter (Alex Peuchert) diff --git a/README b/README index 2cc7f07..b8264b5 100644 --- a/README +++ b/README @@ -2,10 +2,11 @@ This is a Ruby wrapper around the ifconfig command. The goal is to make getting any information that ifconfig provides easy to access. -It was developed on Linux 2.6 with ifconfig from net-tools 1.60. It also has -support for SunOS, Darwin and Open, Free, Net, and DragonflyBSD. These have -not been thoroughly tested. Non Linux platforms call netstat for interface -packet information +It was developed on Linux 2.6 with ifconfig from net-tools 1.60. The FreeBSD +support has been tested on FreBSD 9.2 amd64. The package also has support for +SunOS, Darwin, OSX and Open, Net, and DragonflyBSD. These have not been +thoroughly tested. Non Linux platforms call netstat for interface packet +information. Please send me ifconfig / netstat output for platforms that don't work. @@ -29,7 +30,7 @@ Prerequisites You must have a working ifconfig binary in your path. The output format of you particular version of ifconfig must be supported. -Currently this has only been tested with net-tool 1.6 on Linux +Currently this has only been tested with FreeBSD 9.2 and net-tool 1.6 on Linux. Example ------ diff --git a/Rakefile b/Rakefile index b7aa106..7f0cf70 100644 --- a/Rakefile +++ b/Rakefile @@ -3,18 +3,33 @@ require 'rake/testtask' $VERBOSE = true -desc "Run all unit tests" +desc "Default Task" task :default => [ :test ] -desc "Run all unit tests together" +desc "Run all unit tests." +task :test => ["test:bsd", "test:linux", "test:sunos"] + +# The different os-specific files cannot be required in the same process, since +# the redefine the same symbols. So we can't test them in a single test/unit +# process. Instead, we'll split them up into the minimum possible number of +# processes, each with its own rake task. Rake::TestTask.new do |t| - t.test_files = FileList['test/unit/tc_*.rb'] + t.name = "test:bsd" + t.test_files = %w(darwin dragonflybsd freebsd netbsd openbsd osx).collect do |os| + "test/unit/tc_#{os}.rb" + end end -desc "Run the unit tests in test/" -task :test_units do - Dir.glob('test/unit/*').each do |t| - puts `/usr/bin/env ruby #{t}` +Rake::TestTask.new do |t| + t.name = "test:linux" + t.test_files = %w(linux).collect do |os| + "test/unit/tc_#{os}.rb" end end +Rake::TestTask.new do |t| + t.name = "test:sunos" + t.test_files = %w(sunos).collect do |os| + "test/unit/tc_#{os}.rb" + end +end diff --git a/ifconfig_examples/dragonflybsd.txt b/ifconfig_examples/dragonflybsd.txt index 23f887a..a0ac4ba 100644 --- a/ifconfig_examples/dragonflybsd.txt +++ b/ifconfig_examples/dragonflybsd.txt @@ -1,4 +1,5 @@ rl0: flags=8843 mtu 1500 + options=1b inet6 fe80::202:44ff:fe8f:bb15%rl0 prefixlen 64 scopeid 0x2 inet 192.168.1.24 netmask 0xffffff00 broadcast 192.168.1.255 ether 00:02:44:8f:bb:15 diff --git a/ifconfig_examples/freebsd.txt b/ifconfig_examples/freebsd.txt index b3fd865..96bf0e0 100644 --- a/ifconfig_examples/freebsd.txt +++ b/ifconfig_examples/freebsd.txt @@ -1,17 +1,52 @@ -xl0: flags=8843 mtu 1500 - options=3 - inet 192.168.0.2 netmask 0xffffff00 broadcast 192.168.0.255 - inet6 fe80::201:2ff:fec6:4bea%xl0 prefixlen 64 scopeid 0x1 - ether 00:01:02:c6:4b:ea - media: Ethernet autoselect (100baseTX ) +igb0: flags=8843 metric 0 mtu 1500 + options=401bb + ether 00:11:22:33:44:55 + inet6 fe80::225:90ff:fe95:c98c%igb0 prefixlen 64 scopeid 0x1 + inet 10.1.3.176 netmask 0xfffff000 broadcast 10.1.15.255 + nd6 options=29 + media: Ethernet autoselect (1000baseT ) + status: active +igb1: flags=8843 metric 0 mtu 1500 + options=401bb + ether 00:11:22:33:44:66 + nd6 options=29 + media: Ethernet autoselect (1000baseT ) + status: active + fib: 1 +igb2: flags=8843 metric 0 mtu 1500 + options=401bb + ether 00:11:22:33:44:66 + nd6 options=29 + media: Ethernet autoselect (1000baseT ) + status: active +igb3: flags=8843 metric 0 mtu 1500 + options=401bb + ether 00:11:22:33:44:66 + nd6 options=29 + media: Ethernet autoselect (1000baseT ) + status: active +cxgbe0: flags=8843 metric 0 mtu 1500 + options=6c07bb + ether 22:33:44:55:66:77 + inet 10.1.0.11 netmask 0xfffff000 broadcast 10.1.15.255 + nd6 options=29 + media: Ethernet 10Gbase-Twinax status: active -rl0: flags=8943 mtu 1500 - inet 10.0.0.10 netmask 0xffffff00 broadcast 10.0.0.255 - inet6 fe80::200:21ff:fe03:8e1%rl0 prefixlen 64 scopeid 0x1 - ether 00:00:21:03:08:e1 - media: Ethernet autoselect (100baseTX ) - status: active -lo0: flags=8049 mtu 16384 - inet6 ::1 prefixlen 128 - inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 - inet 127.0.0.1 netmask 0xff000000 +lo0: flags=8049 metric 0 mtu 16384 + options=600003 + inet6 ::1 prefixlen 128 + inet6 fe80::1%lo0 prefixlen 64 scopeid 0x7 + inet 127.0.0.1 netmask 0xff000000 + nd6 options=21 +lagg0: flags=8843 metric 0 mtu 1500 + options=401bb + ether 00:11:22:33:44:66 + inet 10.1.19.176 netmask 0xfffff000 broadcast 10.1.31.255 + nd6 options=29 + media: Ethernet autoselect + status: active + fib: 1 + laggproto lacp lagghash l2,l3,l4 + laggport: igb3 flags=1c + laggport: igb2 flags=1c + laggport: igb1 flags=1c diff --git a/ifconfig_examples/freebsd_netstat.txt b/ifconfig_examples/freebsd_netstat.txt index 1f1add2..c76f52a 100644 --- a/ifconfig_examples/freebsd_netstat.txt +++ b/ifconfig_examples/freebsd_netstat.txt @@ -1,24 +1,15 @@ -Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Time Drop -xl0 1500 00:01:02:c6:4b:ea 7878752 2 404325088 5502452 0 1276760877 0 0 0 - 33:33:46:5d:24:5a - 33:33:00:00:00:01 - 33:33:ff:c6:4b:ea - 01:00:5e:00:00:01 -xl0 1500 192.168.0 beleriand 7865045 - 287935758 5496244 - 1199565347 - - - - ALL-SYSTEMS.MCAST.NET -xl0 1500 fe80:1::201 fe80:1::201:2ff:f 0 - 0 0 - 0 - - - - ff02:1::2:465d:245a(refs: 1) - ff02:1::1 (refs: 1) - ff02:1::1:ffc6:4bea(refs: 1) -lo0 16384 574 0 118916 574 0 118916 0 0 0 -lo0 16384 localhost ::1 0 - 0 0 - 0 - - - - ff01::1 (refs: 1) - ff02:2::1 (refs: 1) - ff02:2::1:ff00:1 (refs: 2) -lo0 16384 fe80:2::1 fe80:2::1 0 - 0 0 - 0 - - - - ff01::1 (refs: 1) - ff02:2::1 (refs: 1) - ff02:2::1:ff00:1 (refs: 2) -lo0 16384 your-net localhost 574 - 118916 574 - 118916 - - - - ALL-SYSTEMS.MCAST.NET - +Name Mtu Network Address Ipkts Ierrs Idrop Opkts Oerrs Coll +igb0 1500 00:11:22:33:44:55 5748766 0 0 1591506 0 0 +igb0 1500 fe80::225:90f fe80::225:90ff:fe 0 - - 2 - - +igb0 1500 10.1.0.0/20 10.1.3.176 1683211 - - 1480094 - - +igb1 1500 00:11:22:33:44:66 6369236 0 0 36130 0 0 +igb2 1500 00:11:22:33:44:66 57591 0 0 35355 0 0 +igb3 1500 00:11:22:33:44:66 53758 0 0 37262 0 0 +cxgbe0 1500 22:33:44:55:66:77 1234567 0 0 2345678 0 0 +cxgbe0 1500 10.1.0.0/20 10.1.0.11 1234568 - - 2345679 - - +lo0 16384 7486204 0 0 7486201 0 0 +lo0 16384 ::1/128 ::1 6628 - - 6628 - - +lo0 16384 fe80::1%lo0/6 fe80::1 0 - - 0 - - +lo0 16384 127.0.0.0/8 127.0.0.1 7479584 - - 7479582 - - +lagg0 1500 00:11:22:33:44:66 6294267 0 0 11768 2 0 +lagg0 1500 10.1.16.0/20 10.1.19.176 334619 - - 9436 - - diff --git a/ifconfig_examples/netbsd.txt b/ifconfig_examples/netbsd.txt index 544ef44..bccc3c5 100644 --- a/ifconfig_examples/netbsd.txt +++ b/ifconfig_examples/netbsd.txt @@ -1,4 +1,6 @@ cs0: flags=8863 mtu 1500 + capabilities=2bf80 + enabled=3000 address: 08:00:2b:81:62:ca media: Ethernet 10baseT status: active diff --git a/ifconfig_examples/netbsd_netstat.txt b/ifconfig_examples/netbsd_netstat.txt new file mode 100644 index 0000000..995eb7e --- /dev/null +++ b/ifconfig_examples/netbsd_netstat.txt @@ -0,0 +1,8 @@ +Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Colls +cs0 1500 08:00:2b:81:62:ca 42320 0 131 0 0 +cs0 1500 fe80::/64 fe80::a00:2bff:fe 42320 0 131 0 0 +cs0 1500 192.168.0/24 192.168.6.156 42320 0 131 0 0 +lo0 33648 0 0 0 0 0 +lo0 33648 127/8 127.0.0.1 0 0 0 0 0 +lo0 33648 ::1/128 ::1 0 0 0 0 0 +lo0 33648 fe80::/64 fe80::1 0 0 0 0 0 diff --git a/ifconfig_examples/sunos.txt b/ifconfig_examples/sunos.txt index 39321e4..2f105ed 100644 --- a/ifconfig_examples/sunos.txt +++ b/ifconfig_examples/sunos.txt @@ -1,10 +1,12 @@ lo0: flags=1000849 mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 inet6 ::1/128 -bge0: flags=1000843 mtu 1500 index 2 +bge0: flags=1000843 mtu 1500 index 2 inet 10.32.4.138 netmask ffffff00 broadcast 10.32.4.255 ether 0:3:ba:42:9d:ef inet6 fe80::a00:20ff:fe72:9724/10 -le1: flags=1000843 mtu 1500 index 3 +bge0:1: flags=1000843 mtu 1500 index 2 + inet 10.32.4.139 netmask ffffff00 broadcast 10.32.4.255 +le1: flags=1000843 mtu 1500 index 3 inet 172.16.254.99 netmask ffff0000 broadcast 172.16.255.255 ether 8:0:20:1d:71:eb diff --git a/ifconfig_examples/sunos_netstat.txt b/ifconfig_examples/sunos_netstat.txt new file mode 100644 index 0000000..9a16d45 --- /dev/null +++ b/ifconfig_examples/sunos_netstat.txt @@ -0,0 +1,8 @@ +Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue +lo0 8232 127.0.0.0 127.0.0.1 162 0 162 0 0 0 +bge0 1500 10.32.4.0 10.32.4.137 3460 0 114 0 0 0 +le1 1500 172.16.0.0 172.16.254.99 1000 0 500 0 0 0 + +Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis +lo0 8252 ::1 ::1 162 0 162 0 0 +bge0 1500 fe80:: fe80::a00:20ff:fe72:9724 2000 0 1100 0 0 diff --git a/lib/ifconfig/bsd/ifconfig.rb b/lib/ifconfig/bsd/ifconfig.rb index 11c1f74..ed22b02 100644 --- a/lib/ifconfig/bsd/ifconfig.rb +++ b/lib/ifconfig/bsd/ifconfig.rb @@ -9,6 +9,10 @@ class Ifconfig # ifconfig = user provided ifconifg output # netstat = same, but for netstat -in # + # XXX On FreeBSD, "netstat -inb" will show byte _and_ packet statistics, but + # on NetBSD and OpenBSD, it will show byte statistics only. We use "-in" + # instead of "-inb" for cross-platform compatibility. + # @@ifcfg_cmd = "/usr/bin/env ifconfig -a" @@netstat_cmd = "/usr/bin/env netstat -in" def initialize(ifconfig=nil,netstat=nil,verbose=nil) @@ -27,6 +31,12 @@ def initialize(ifconfig=nil,netstat=nil,verbose=nil) when /^lo\d\:/im @ifaces[iface_name] = LoopbackInterface.new(iface_name,iface) parse_activity(iface_name) + when /^lagg[0-9]:/ + # This clause is only matched on FreeBSD. Other OSes have similar + # drivers, for example agr(4) on NetBSD, but ruby-ifconfig does not + # yet support them. + @ifaces[iface_name] = LinkAggregation.new(iface_name,iface) + parse_activity(iface_name) when /\s+media\:\s+Ethernet\s+/im @ifaces[iface_name] = EthernetAdapter.new(iface_name,iface) parse_activity(iface_name) @@ -49,17 +59,21 @@ def initialize(ifconfig=nil,netstat=nil,verbose=nil) # def parse_activity(iface) mtu = rxpackets = rxerrors = txpackets = txerrors = 0 + fields = {} @netstat.split("\n").each { |line| line.strip! - if line =~ /^#{iface}/ + if line =~/^Name/ + headers = line.split(" ") + headers.each_index {|i| fields[headers[i]] = i} + elsif line =~ /^#{iface}/ next if line.split[2] =~ /\/ puts "matched line for "+iface if @verbose toks = line.split mtu = toks[1] - rxpackets += toks[4].to_i - rxerrors += toks[5].to_i - txpackets += toks[6].to_i - txerrors += toks[7].to_i + rxpackets += toks[fields["Ipkts"]].to_i + rxerrors += toks[fields["Ierrs"]].to_i + txpackets += toks[fields["Opkts"]].to_i + txerrors += toks[fields["Oerrs"]].to_i @ifaces[iface].mtu = mtu.to_i @ifaces[iface].rx = { 'packets' => rxpackets, 'errors' => rxerrors } diff --git a/lib/ifconfig/bsd/interface_types.rb b/lib/ifconfig/bsd/interface_types.rb index b21b1bb..9589943 100644 --- a/lib/ifconfig/bsd/interface_types.rb +++ b/lib/ifconfig/bsd/interface_types.rb @@ -10,17 +10,39 @@ class NetworkAdapter # iterate line by line and dispatch to helper functions # for lines that match a pattern # - def parse_ifconfig + def parse_ifconfig(netstattxt=nil) @ifconfig.split("\n").each { |line| case line when /^\s+#{@protos}/ add_network(line) - when /flags\=/i + when /\s*flags\=/i parse_flags(line) + when /^\s*fib:/ + parse_fib(line) + when /^\s*media:/ + parse_media(line) + when /^\s*options=/ + # FreeBSD and DragonFlyBSD use "options=" + parse_capabilities(line) + when /^\s*enabled=/ + # NetBSD uses "enabled=" + parse_capabilities(line) end } end + # parses the "fib: 1" line + def parse_fib(line) + @fib = line.split()[1].to_i + end + + # parses the "options=1b" line + # + def parse_capabilities(line) + caps = line.match(/\<(\S+)\>/i)[1] + @capabilities = caps.strip.split(',') + end + # parses the "UP LOOPBACK RUNNING MTU:3924 Metric:1" line # def parse_flags(line) @@ -35,8 +57,8 @@ def parse_flags(line) def add_network(line) case line when /^\s+inet\s/ - addr,mask = line.match(/\s+([\d\d?\d?\.]{4,})\s+netmask\s+(\S+)/i)[1..2] - bcast = line.match(/\s+broadcast\s([\d\d?\d?\.]{4,})/i) + addr,mask = line.match(/\s+((\d{1,3}\.){3,}\d{1,3})\s+netmask\s+(\S+)/i)[1..2] + bcast = line.match(/\s+broadcast\s([{1,3}d?\.]{4,})/i) bcast = bcast[1] unless bcast.nil? @networks['inet'] = Ipv4Network.new(addr, mask, bcast) when /^\s+inet6\s/ @@ -55,11 +77,19 @@ def add_network(line) class EthernetAdapter + # Parses the "media: Ethernet autoselect (1000baseT )" line + def parse_media(line) + match = line.match(/Ethernet (autoselect )?(\()?(\S+?)[ )]/) + if match + @media = match[3] + end + end + def set_mac begin match=@ifconfig.match(/\s+ether\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})/im) return match[1] unless match.nil? - # Openbsd + # OpenBSD and NetBSD match = @ifconfig.match(/\s+address\:\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})/im) return match[1] unless match.nil? rescue NoMethodError @@ -67,3 +97,25 @@ def set_mac end end end + + +class LinkAggregation + def parse_ifconfig(netstattxt=nil) + if @lagg_children.nil? + @lagg_children = [] + end + super(netstattxt) + @ifconfig.split("\n").each { |line| + proto_match = line.match( /^\s*laggproto\s*(\S+)\s*/ ) + if proto_match + @laggproto = proto_match[1] + next + end + port_match = line.match( /^\s*laggport:\s*(\S+)\s*/ ) + if port_match + @lagg_children << port_match[1] + next + end + } + end +end diff --git a/lib/ifconfig/common/interface_types.rb b/lib/ifconfig/common/interface_types.rb index 7da3ede..dcb9e44 100644 --- a/lib/ifconfig/common/interface_types.rb +++ b/lib/ifconfig/common/interface_types.rb @@ -1,7 +1,7 @@ # $Id: interface_types.rb,v 1.1.1.1 2005/07/02 19:10:58 hobe Exp $ # class NetworkAdapter - def initialize(name, ifacetxt) + def initialize(name, ifacetxt, netstattxt=nil) @name = name @ifconfig = ifacetxt @status = false @@ -12,12 +12,18 @@ def initialize(name, ifacetxt) 'EtherTalk Phase 2'].join("|") @networks = {} @flags = [] + @media = nil + @laggproto = nil + @lagg_children = nil + @capabilities = [] @mtu = nil @metric = nil @rx = @tx = {} - parse_ifconfig + @fib = 0 + parse_ifconfig(netstattxt) end - attr_reader :status, :name, :flags, :mtu + attr_reader :status, :name, :fib, :flags, :mtu, :lagg_children, :laggproto + attr_reader :capabilities attr_accessor :tx, :rx # take array and turn each two entries into @@ -91,6 +97,9 @@ def has_addr?(addr) return self.addresses.include?(addr) end + def parse_media + end + def to_s s = @name+":"+self.ifacetype.to_s+"\n" @networks.keys.sort.each { |network| @@ -102,9 +111,14 @@ def to_s s += " RX packets: #{self.rx['packets']}, TX packets: #{self.tx['packets']}\n" end + s += " Capabilities: #{@capabilities.join(',')}\n" s += " MTU: #{@mtu}\n" + s += " Media: #{@media}\n" s += " Metric: #{@metric}\n" s += " Flags: #{@flags.join(',')}\n" + s += " Fib: #{@fib}\n" if @fib != 0 + s += " Lagg Proto: #{@laggproto}\n" if @laggproto + s += " Lagg Children: #{@lagg_children}\n" if @lagg_children s += " Status: UP" if self.status return s end @@ -114,12 +128,12 @@ def to_s # function to get the mac address # class EthernetAdapter < NetworkAdapter - def initialize(name,ifconfigtxt) - super(name,ifconfigtxt) + def initialize(name,ifconfigtxt,netstattxt=nil) + super(name,ifconfigtxt,netstattxt) @mac = set_mac end - attr_reader :mac, :interrupt, :rxbytes, :txbytes, :rxpackets, + attr_reader :mac, :media, :interrupt, :rxbytes, :txbytes, :rxpackets, :txpackets def to_s @@ -139,3 +153,13 @@ class IPv6_in_IPv4 < NetworkAdapter class SerialLineIP < NetworkAdapter end + +# Represents combinations of network interfaces. Variously known as lagg, +# bond, teaming, trunking, etc. +class LinkAggregation < EthernetAdapter + def initialize(name,ifconfigtxt,netstattxt=nil) + @lagg_children = [] + @laggproto = nil + super(name,ifconfigtxt,netstattxt) + end +end diff --git a/lib/ifconfig/linux/interface_types.rb b/lib/ifconfig/linux/interface_types.rb index ac8e6e7..cbd51e2 100644 --- a/lib/ifconfig/linux/interface_types.rb +++ b/lib/ifconfig/linux/interface_types.rb @@ -32,7 +32,7 @@ def parse_activity(line) # iterate line by line and dispatch to helper functions # for lines that match a pattern # - def parse_ifconfig + def parse_ifconfig(netstattxt=nil) @ifconfig.split("\n").each { |line| case line when /^\s+#{@protos}/ diff --git a/lib/ifconfig/sunos/ifconfig.rb b/lib/ifconfig/sunos/ifconfig.rb index b205f52..4bee92d 100644 --- a/lib/ifconfig/sunos/ifconfig.rb +++ b/lib/ifconfig/sunos/ifconfig.rb @@ -8,7 +8,7 @@ class Ifconfig # Can manually specify the platform (should be output of the 'uname' command) # and the ifconfig input # - def initialize(input=nil,verbose=nil) + def initialize(input=nil,netstat=nil,verbose=nil) if input.nil? cmd = IO.popen('which ifconfig'){ |f| f.readlines[0] } exit unless !cmd.nil? @@ -27,11 +27,12 @@ def initialize(input=nil,verbose=nil) iface_name = get_iface_name(iface) case iface when /^lo\d\:/im - @ifaces[iface_name] = LoopbackInterface.new(iface_name,iface) + @ifaces[iface_name] = LoopbackInterface.new(iface_name,iface,netstat) when /\s+ether\s+/im - @ifaces[iface_name] = EthernetAdapter.new(iface_name,iface) + @ifaces[iface_name] = EthernetAdapter.new(iface_name,iface,netstat) else - puts "Unknown Adapter Type: #{iface}" if @verbose + # fallback for virtual nics like bge:0 + @ifaces[iface_name] = NetworkAdapter.new(iface_name,iface,netstat) end end end diff --git a/lib/ifconfig/sunos/interface_types.rb b/lib/ifconfig/sunos/interface_types.rb index 7644e3d..19f1245 100644 --- a/lib/ifconfig/sunos/interface_types.rb +++ b/lib/ifconfig/sunos/interface_types.rb @@ -7,23 +7,26 @@ class NetworkAdapter # Parse activity on interface # - def parse_activity + def parse_activity(netstattxt) #imaptest1# netstat -in #Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue #lo0 8232 0.0.0.0 0.0.0.4 267824 0 267824 0 0 0 #bge0 1500 10.0.0.0 10.32.4.138 10935939 0 7741167 0 0 0 - cmd = "netstat -in | grep #{@name}" - line = IO.popen(cmd).gets - return if line.nil? - name,@mtu,dfgw,addr,@rx['packets'],@rx['errors'], - @tx['packets'],@tx['errors'],collisions,queue = line.split - @mtu = @mtu.to_i + cmd = "netstat -in" + txt = netstattxt || IO.popen(cmd) + txt.each_line do |line| + next if line.nil? + next unless line =~ /#{@name}/ + name,@mtu,dfgw,addr,@rx['packets'],@rx['errors'], + @tx['packets'],@tx['errors'],collisions,queue = line.split + @mtu = @mtu.to_i + end end # iterate line by line and dispatch to helper functions # for lines that match a pattern # - def parse_ifconfig + def parse_ifconfig(netstattxt=nil) @ifconfig.split("\n").each { |line| case line when /^\s+#{@protos}/ @@ -32,7 +35,7 @@ def parse_ifconfig parse_flags(line) end } - parse_activity + parse_activity(netstattxt) end # parses the "UP LOOPBACK RUNNING MTU:3924 Metric:1" line diff --git a/ruby-ifconfig.gemspec b/ruby-ifconfig.gemspec old mode 100644 new mode 100755 index 1d0fe99..83613a7 --- a/ruby-ifconfig.gemspec +++ b/ruby-ifconfig.gemspec @@ -2,12 +2,11 @@ Gem::Specification.new do |s| s.name = %q{ruby-ifconfig} - s.version = "1.2.4" - s.date = %q{2011-09-19} - s.authors = ["Daniel Hobe", "Alex Peuchert", "Ali Jelveh"] - s.email = %q{daniel@nightrunner.com} - s.homepage = %q{http://github.com/dudemeister/ruby-ifconfig} - s.rubyforge_project = %q{ruby-ifconfig} + s.version = "1.3.0" + s.date = %q{2014-01-01} + s.authors = ["Daniel Hobe", "Alex Peuchert", "Ali Jelveh", "Alan Somers"] + s.email = %q{asomers@freebsd.org} + s.homepage = %q{http://github.com/asomers/ruby-ifconfig} s.description = %q{Ruby wrapper around the ifconfig command.} s.summary = %q{This is a Ruby wrapper around the ifconfig command. The goal is to make getting any information that ifconfig provides easy to access.} @@ -37,11 +36,8 @@ Gem::Specification.new do |s| ] s.test_files = %w[ - test/test_dragonflybsd.rb - test/test_openbsd.rb - test/test_darwin.rb - test/test_bsd.rb - test/test_sunos.rb + test/selftest.rb + test/test_helper.rb test/unit/tc_openbsd.rb test/unit/tc_dragonflybsd.rb test/unit/tc_linux.rb @@ -50,20 +46,18 @@ Gem::Specification.new do |s| test/unit/tc_darwin.rb test/unit/tc_sunos.rb test/unit/tc_osx.rb - test/test_helper.rb - test/test_netbsd.rb - test/test_linux.rb - test/test_osx.rb ifconfig_examples/darwin.txt ifconfig_examples/dragonflybsd.txt ifconfig_examples/dragonflybsd_netstat.txt ifconfig_examples/netbsd.txt + ifconfig_examples/netbsd_netstat.txt ifconfig_examples/freebsd_netstat.txt ifconfig_examples/linux.txt ifconfig_examples/linux_ethernet.txt ifconfig_examples/freebsd.txt ifconfig_examples/openbsd.txt ifconfig_examples/sunos.txt + ifconfig_examples/sunos_netstat.txt ifconfig_examples/osx.txt ] diff --git a/test/selftest.rb b/test/selftest.rb new file mode 100644 index 0000000..49d3a8a --- /dev/null +++ b/test/selftest.rb @@ -0,0 +1,9 @@ +#!/usr/bin/ruby -w + +$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) + +require 'ifconfig' + +cfg = IfconfigWrapper.new().parse + +puts cfg diff --git a/test/test_bsd.rb b/test/test_bsd.rb deleted file mode 100755 index 08e5457..0000000 --- a/test/test_bsd.rb +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -require 'ifconfig' -require 'pp' - -ifcfg = IO.readlines(File.expand_path('../../ifconfig_examples/freebsd.txt', __FILE__)).join -netstat = IO.readlines(File.expand_path('../../ifconfig_examples/freebsd_netstat.txt', __FILE__)).join - -ifconfig = IfconfigWrapper.new('BSD',ifcfg,netstat).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\nrl0 mac address: (ifconfig['rl0'].mac)" -pp ifconfig['rl0'].mac - -puts "\nIpV4 addresses on rl0: (ifconfig['rl0'].addresses('inet'))" -pp ifconfig['rl0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\nList of address types for rl0: (ifconfig['rl0'].addr_types)" -pp ifconfig['rl0'].addr_types - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/test_darwin.rb b/test/test_darwin.rb deleted file mode 100755 index 72e6435..0000000 --- a/test/test_darwin.rb +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -require 'ifconfig' -require 'pp' - -sample = IO.readlines(File.expand_path('../../ifconfig_examples/darwin.txt', __FILE__)).join -ifconfig = IfconfigWrapper.new('BSD',sample).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\nen0 mac address: (ifconfig['en0'].mac)" -pp ifconfig['en0'].mac - -puts "\nIpV4 addresses on en0: (ifconfig['en0'].addresses('inet'))" -pp ifconfig['en0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\nList of address types for en0: (ifconfig['en0'].addr_types)" -pp ifconfig['en0'].addr_types - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/test_dragonflybsd.rb b/test/test_dragonflybsd.rb deleted file mode 100755 index 66e0ece..0000000 --- a/test/test_dragonflybsd.rb +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -require 'ifconfig' -require 'pp' - -ifcfg = IO.readlines(File.expand_path('../../ifconfig_examples/dragonflybsd.txt', __FILE__)).join -netstat = IO.readlines(File.expand_path('../../ifconfig_examples/dragonflybsd_netstat.txt', __FILE__)).join - -ifconfig = IfconfigWrapper.new('BSD',ifcfg,netstat).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\nrl0 mac address: (ifconfig['rl0'].mac)" -pp ifconfig['rl0'].mac - -puts "\nIpV4 addresses on rl0: (ifconfig['rl0'].addresses('inet'))" -pp ifconfig['rl0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\nList of address types for rl0: (ifconfig['rl0'].addr_types)" -pp ifconfig['rl0'].addr_types - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/test_linux.rb b/test/test_linux.rb deleted file mode 100755 index 02833b7..0000000 --- a/test/test_linux.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -require 'ifconfig' -require 'pp' - -sample = IO.readlines(File.expand_path('../../ifconfig_examples/linux.txt', __FILE__)).join -ifconfig = IfconfigWrapper.new('Linux',sample).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\neth0 mac address: (ifconfig['eth0'].mac)" -pp ifconfig['eth0'].mac - -puts "\nIpV4 addresses on eth0: (ifconfig['eth0'].addresses('inet'))" -pp ifconfig['eth0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/test_netbsd.rb b/test/test_netbsd.rb deleted file mode 100755 index 1429178..0000000 --- a/test/test_netbsd.rb +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -require 'ifconfig' -require 'pp' - -sample = IO.readlines(File.expand_path('../../ifconfig_examples/netbsd.txt', __FILE__)).join -ifconfig = IfconfigWrapper.new('BSD',sample).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\ncs0 mac address: (ifconfig['cs0'].mac)" -pp ifconfig['cs0'].mac - -puts "\nIpV4 addresses on cs0: (ifconfig['cs0'].addresses('inet'))" -pp ifconfig['cs0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\nList of address types for cs0: (ifconfig['cs0'].addr_types)" -pp ifconfig['cs0'].addr_types - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/test_openbsd.rb b/test/test_openbsd.rb deleted file mode 100755 index 10eb5e2..0000000 --- a/test/test_openbsd.rb +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -require 'ifconfig' -require 'pp' - -sample = IO.readlines(File.expand_path('../../ifconfig_examples/openbsd.txt', __FILE__)).join -ifconfig = IfconfigWrapper.new('BSD',sample).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\nxl0 mac address: (ifconfig['xl0'].mac)" -pp ifconfig['xl0'].mac - -puts "\nIpV4 addresses on xl0: (ifconfig['xl0'].addresses('inet'))" -pp ifconfig['xl0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\nList of address types for xl0: (ifconfig['xl0'].addr_types)" -pp ifconfig['xl0'].addr_types - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/test_osx.rb b/test/test_osx.rb deleted file mode 100755 index 4b9b265..0000000 --- a/test/test_osx.rb +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -require 'ifconfig' -require 'pp' - -sample = IO.readlines(File.expand_path('../../ifconfig_examples/osx.txt', __FILE__)).join -ifconfig = IfconfigWrapper.new('BSD',sample).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\nen0 mac address: (ifconfig['en0'].mac)" -pp ifconfig['en0'].mac - -puts "\nIpV4 addresses on en0: (ifconfig['en0'].addresses('inet'))" -pp ifconfig['en0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\nList of address types for en0: (ifconfig['en0'].addr_types)" -pp ifconfig['en0'].addr_types - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/test_sunos.rb b/test/test_sunos.rb deleted file mode 100755 index dc3c2e7..0000000 --- a/test/test_sunos.rb +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/ruby -w - -$:.unshift File.expand_path('../lib', File.dirname(__FILE__)) - -# -#imaptest1# netstat -in -#Name Mtu Net/Dest Address Ipkts Ierrs Opkts Oerrs Collis Queue -#lo0 8232 0.0.0.0 0.0.0.4 267824 0 267824 0 0 0 -#bge0 1500 10.0.0.0 10.32.4.138 10935939 0 7741167 0 0 0 -require 'ifconfig' -require 'pp' - -sample = IO.readlines(File.expand_path('../../ifconfig_examples/sunos.txt', __FILE__)).join -ifconfig = IfconfigWrapper.new('SunOS',sample).parse - -puts "Interfaces: (ifconfig.interfaces)" -pp ifconfig.interfaces - -puts "\nbge0 mac address: (ifconfig['bge0'].mac)" -pp ifconfig['bge0'].mac - -puts "\nIpV4 addresses on bge0: (ifconfig['bge0'].addresses('inet'))" -pp ifconfig['bge0'].addresses('inet') - -puts "\nAll addresses reported by ifconfig: (ifconfig.addresses)" -pp ifconfig.addrs_with_type - -puts "\niconfig.each { block }" -ifconfig.each do |iface| - pp iface.name if iface.up? -end - -puts -s = ifconfig.to_s -puts s diff --git a/test/unit/tc_darwin.rb b/test/unit/tc_darwin.rb index 46c9ba8..bc449ec 100644 --- a/test/unit/tc_darwin.rb +++ b/test/unit/tc_darwin.rb @@ -4,7 +4,8 @@ class TC_DarwinTest < Test::Unit::TestCase def setup sample = IO.readlines("#{File.dirname(__FILE__)}"+ "/../../ifconfig_examples/darwin.txt").join - @cfg = IfconfigWrapper.new('BSD',sample).parse + netstat_sample = "" + @cfg = IfconfigWrapper.new('BSD',sample, netstat_sample).parse end def test_interface_list diff --git a/test/unit/tc_dragonflybsd.rb b/test/unit/tc_dragonflybsd.rb index 5bc859f..3ad3492 100644 --- a/test/unit/tc_dragonflybsd.rb +++ b/test/unit/tc_dragonflybsd.rb @@ -4,12 +4,14 @@ class TC_DragonFlyBSDTest < Test::Unit::TestCase def setup sample = IO.readlines("#{File.dirname(__FILE__)}"+ "/../../ifconfig_examples/dragonflybsd.txt").join - @cfg = IfconfigWrapper.new('BSD',sample).parse + netstat_sample = IO.readlines("#{File.dirname(__FILE__)}"+ + "/../../ifconfig_examples/dragonflybsd_netstat.txt").join + @cfg = IfconfigWrapper.new('BSD',sample, netstat_sample).parse end def test_interface_list - assert(@cfg.interfaces == ["rl0", "lo0"], - "Fauled to parse all interfaces") + assert(@cfg.interfaces.sort == ["rl0", "lo0"].sort, + "Failed to parse all interfaces") end def test_mac_parse @@ -37,4 +39,9 @@ def test_attribs end + def test_capabilities + expected = %w(RXCSUM TXCSUM VLAN_MTU VLAN_HWTAGGING) + assert_equal(expected.sort, @cfg['rl0'].capabilities.sort) + end + end diff --git a/test/unit/tc_freebsd.rb b/test/unit/tc_freebsd.rb index 138dbd0..3da25c0 100644 --- a/test/unit/tc_freebsd.rb +++ b/test/unit/tc_freebsd.rb @@ -2,39 +2,82 @@ class TC_FreeBSDTest < Test::Unit::TestCase def setup - sample = IO.readlines("#{File.dirname(__FILE__)}"+ - "/../../ifconfig_examples/freebsd.txt").join - @cfg = IfconfigWrapper.new('BSD',sample).parse + ifconfig_sample = IO.readlines("#{File.dirname(__FILE__)}"+ + "/../../ifconfig_examples/freebsd.txt").join + netstat_sample = IO.readlines("#{File.dirname(__FILE__)}"+ + "/../../ifconfig_examples/freebsd_netstat.txt").join + @cfg = IfconfigWrapper.new('BSD',ifconfig_sample, netstat_sample).parse end def test_interface_list - assert(@cfg.interfaces.sort == ["rl0", "lo0", "xl0"].sort, + assert(@cfg.interfaces.sort == ["igb0", "igb1", "igb2", "igb3", + "cxgbe0", "lo0", "lagg0"].sort, "Failed to parse all interfaces") end def test_mac_parse - assert(@cfg['rl0'].mac == "00:00:21:03:08:e1", - "Failed to parse MAC address: "+@cfg['rl0'].mac) + assert(@cfg['igb0'].mac == "00:11:22:33:44:55", + "Failed to parse MAC address: "+@cfg['igb0'].mac) end def test_flags - assert(@cfg['rl0'].flags.include?('BROADCAST') && - @cfg['rl0'].flags.include?('RUNNING') && - @cfg['rl0'].flags.include?('MULTICAST') && - @cfg['rl0'].up?, - "FLAG Parsing failed: #{@cfg['rl0'].flags}") + assert(@cfg['igb0'].flags.include?('BROADCAST') && + @cfg['igb0'].flags.include?('RUNNING') && + @cfg['igb0'].flags.include?('MULTICAST') && + @cfg['igb0'].up?, + "FLAG Parsing failed: #{@cfg['igb0'].flags}") end def test_addr_types - assert(@cfg['rl0'].addr_types.include?('inet') && - @cfg['rl0'].addr_types.include?('inet6'), + assert(@cfg['igb0'].addr_types.include?('inet') && + @cfg['igb0'].addr_types.include?('inet6'), "Failed to parse all address types") end def test_attribs - assert(@cfg['rl0'].rx['bytes'].class == Fixnum || NilClass && - @cfg['rl0'].tx['bytes'].class == Fixnum || NilClass, "Wrong class") + assert(@cfg['igb0'].rx['bytes'].class == Fixnum || NilClass && + @cfg['igb0'].tx['bytes'].class == Fixnum || NilClass, "Wrong class") + assert_equal(1683211, @cfg['igb0'].rx['packets']) + assert_equal(0, @cfg['igb0'].rx['errors']) + assert_equal(1480096, @cfg['igb0'].tx['packets']) + assert_equal(0, @cfg['igb0'].tx['errors']) + end + + def test_fib + assert_equal(0, @cfg['lo0'].fib) + assert_equal(0, @cfg['igb0'].fib) + assert_equal(1, @cfg['lagg0'].fib) + assert_equal(0, @cfg['cxgbe0'].fib) + end + + def test_media + assert_equal("1000baseT", @cfg['igb0'].media) + assert_equal("1000baseT", @cfg['igb0'].media) + assert_equal("1000baseT", @cfg['igb0'].media) + assert_equal("1000baseT", @cfg['igb0'].media) + assert_equal("10Gbase-Twinax", @cfg['cxgbe0'].media) + assert_equal(nil, @cfg['lagg0'].media) + end + + def test_mtu + assert_equal(1500, @cfg['igb0'].mtu) + assert_equal(1500, @cfg['lagg0'].mtu) + assert_equal(16384, @cfg['lo0'].mtu) + end + + def test_laggproto + assert_equal("lacp", @cfg['lagg0'].laggproto) + end + + def test_lagg_children + assert_equal(['igb1', 'igb2', 'igb3'].sort, + @cfg['lagg0'].lagg_children.sort) + end + def test_capabilities + expected = %w(RXCSUM TXCSUM VLAN_MTU VLAN_HWTAGGING JUMBO_MTU VLAN_HWCSUM + TSO4 VLAN_HWTSO) + assert_equal(expected.sort, @cfg['igb0'].capabilities.sort) end end diff --git a/test/unit/tc_netbsd.rb b/test/unit/tc_netbsd.rb index 4e9c56a..e759bdd 100644 --- a/test/unit/tc_netbsd.rb +++ b/test/unit/tc_netbsd.rb @@ -4,7 +4,9 @@ class TC_NetBSDTest < Test::Unit::TestCase def setup sample = IO.readlines("#{File.dirname(__FILE__)}"+ '/../../ifconfig_examples/netbsd.txt').join - @cfg = IfconfigWrapper.new('BSD',sample).parse + netstat_sample = IO.readlines("#{File.dirname(__FILE__)}"+ + "/../../ifconfig_examples/netbsd_netstat.txt").join + @cfg = IfconfigWrapper.new('BSD',sample, netstat_sample).parse end def test_interface_list @@ -37,4 +39,9 @@ def test_attribs end + def test_capabilities + expected = %w(UDP4CSUM_Rx UDP4CSUM_Tx) + assert_equal(expected.sort, @cfg['cs0'].capabilities.sort) + end + end diff --git a/test/unit/tc_openbsd.rb b/test/unit/tc_openbsd.rb index c474755..ec91805 100644 --- a/test/unit/tc_openbsd.rb +++ b/test/unit/tc_openbsd.rb @@ -4,7 +4,8 @@ class TC_OpenBSDTest < Test::Unit::TestCase def setup sample = IO.readlines("#{File.dirname(__FILE__)}"+ '/../../ifconfig_examples/openbsd.txt').join - @cfg = IfconfigWrapper.new('BSD',sample).parse + netstat_sample = "" + @cfg = IfconfigWrapper.new('BSD',sample,netstat_sample).parse end def test_interface_list diff --git a/test/unit/tc_osx.rb b/test/unit/tc_osx.rb index 5c352db..93a72ee 100644 --- a/test/unit/tc_osx.rb +++ b/test/unit/tc_osx.rb @@ -4,7 +4,8 @@ class TC_OsxTest < Test::Unit::TestCase def setup sample = IO.readlines("#{File.dirname(__FILE__)}"+ "/../../ifconfig_examples/osx.txt").join - @cfg = IfconfigWrapper.new('BSD',sample).parse + netstat_sample = "" + @cfg = IfconfigWrapper.new('BSD',sample,netstat_sample).parse end def test_interface_list diff --git a/test/unit/tc_sunos.rb b/test/unit/tc_sunos.rb index 711da48..eaec40f 100644 --- a/test/unit/tc_sunos.rb +++ b/test/unit/tc_sunos.rb @@ -4,42 +4,45 @@ class TC_SunOSTest < Test::Unit::TestCase def setup sample = IO.readlines("#{File.dirname(__FILE__)}"+ '/../../ifconfig_examples/sunos.txt').join - @@cfg = IfconfigWrapper.new('SunOS',sample).parse + netstat_sample = IO.readlines("#{File.dirname(__FILE__)}"+ + "/../../ifconfig_examples/sunos_netstat.txt").join + @cfg = IfconfigWrapper.new('SunOS',sample,netstat_sample).parse end def test_interface_list - assert(@@cfg.interfaces.sort == ["le1", "lo0", "bge0"].sort, - "Fauled to parse all interfaces") + assert(@cfg.interfaces.sort == ["le1", "lo0", "bge0", "bge0:1"].sort, + "Failed to parse all interfaces") end def test_mac_parse - assert(@@cfg['bge0'].mac == "0:3:ba:42:9d:ef", - "Failed to parse MAC address: "+@@cfg['bge0'].mac) + assert(@cfg['bge0'].mac == "0:3:ba:42:9d:ef", + "Failed to parse MAC address: "+@cfg['bge0'].mac) end def test_flags - assert(@@cfg['bge0'].flags.include?('BROADCAST') && - @@cfg['bge0'].flags.include?('RUNNING') && - @@cfg['bge0'].flags.include?('MULTICAST') && - @@cfg['bge0'].up?, - "FLAG Parsing failed: #{@@cfg['bge0'].flags}") + assert(@cfg['bge0'].flags.include?('BROADCAST') && + @cfg['bge0'].flags.include?('RUNNING') && + @cfg['bge0'].flags.include?('MULTICAST') && + @cfg['bge0'].flags.include?('ROUTER') && + @cfg['bge0'].up?, + "FLAG Parsing failed: #{@cfg['bge0'].flags}") end def test_addr_types - assert(@@cfg['bge0'].addr_types.include?('inet') && - @@cfg['bge0'].addr_types.include?('inet6'), + assert(@cfg['bge0'].addr_types.include?('inet') && + @cfg['bge0'].addr_types.include?('inet6'), "Failed to parse all address types") end def test_networks - assert(@@cfg['bge0'].addr_types.include?('inet') && - @@cfg['bge0'].addr_types.include?('inet6'), - "Missing Address Types: #{@@cfg['bge0'].addr_types}") + assert(@cfg['bge0'].addr_types.include?('inet') && + @cfg['bge0'].addr_types.include?('inet6'), + "Missing Address Types: #{@cfg['bge0'].addr_types}") end def test_attribs - assert(@@cfg['bge0'].rx['bytes'].class == Fixnum || NilClass&& - @@cfg['bge0'].tx['bytes'].class == Fixnum || NilClass, "Wrong class") + assert(@cfg['bge0'].rx['bytes'].class == Fixnum || NilClass && + @cfg['bge0'].tx['bytes'].class == Fixnum || NilClass, "Wrong class") end end