Module: CSD::Application::Minisip::Component::Network

Defined in:
lib/csd/application/minisip/component/network.rb

Overview

This module updates the network firmware of the system.

Constant Summary collapse

OPTIMUM_BUFFERS =

These IP stack buffer values have been identified as optimal by the Master Thesis students. Feel free to experiment around with other values. Erik suspects that they might have to be higher than this.

{
  'net.core.rmem_max'     => '131071',
  'net.core.wmem_max'     => '131071',
  'net.core.rmem_default' => '114688',
  'net.core.wmem_default' => '114688',
  'net.ipv4.udp_mem'      => '81120 108160 162240',
  'net.ipv4.udp_rmem_min' => '4096',
  'net.ipv4.udp_wmem_min' => '4096'
}

Class Method Summary collapse

Class Method Details

.checkout_intelObject

This method check out intel firmware from git repository



98
99
100
# File 'lib/csd/application/minisip/component/network.rb', line 98

def checkout_intel
  Cmd.git_clone 'Intel firmware', 'http://github.com/csd/intel.git', Path.intel_firmware
end

.checkout_realtekObject

This method check out realtek firmware from git repository



92
93
94
# File 'lib/csd/application/minisip/component/network.rb', line 92

def checkout_realtek
  Cmd.git_clone 'Realtek firmware', 'http://github.com/csd/realtek.git', Path.realtek_firmware
end

.compileObject

This method fixes the udp buffer size and updates the suitable network firmware after auto detection. AI will first use the optimum buffer parameters, which have been tested and identified, to update the system and then make them permanent in the system. AI will also detect the system for its network card, and initiate the corresponding method to update it.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/csd/application/minisip/component/network.rb', line 31

def compile
  UI.debug "#{self}.compile was called"
  fix_udp_buffer
  permanent_udp_buffer
  lsmod = Cmd.run 'lsmod', :die_on_failure => false, :internal => true
  lspci = Cmd.run 'lspci -v | grep Ethernet', :die_on_failure => false, :internal => true
  UI.debug "#{self}.compile had this lsmod output: #{lsmod.output}"
  UI.debug "#{self}.compile had this lspci output: #{lspci.output}"
  update_realtek if (lsmod.success? and lsmod.output !~ /r8168/ and lspci.output =~ /RTL8111\/8168B/) or Options.reveal
  update_intel if (lspci.success? and lspci.output =~ /82572EI/) or Options.reveal
end

.compile_intelObject

This method compile intel firmware by make install command. It also gives a UI information the users about the following operation.



114
115
116
117
118
# File 'lib/csd/application/minisip/component/network.rb', line 114

def compile_intel
  UI.info 'Compiling Intel firmware'.green.bold
  Cmd.cd Path.intel_firmware_src, :internal => true
  Cmd.run 'sudo make install'
end

.compile_realtekObject

This method compile realtek firmware by running the downloaded autorun shell script. It also gives a UI information the users about the following operation.



105
106
107
108
109
# File 'lib/csd/application/minisip/component/network.rb', line 105

def compile_realtek
  UI.info 'Compiling Realtek firmware'.green.bold
  Cmd.cd Path.realtek_firmware, :internal => true
  Cmd.run 'sudo ./autorun.sh'
end

.fix_udp_bufferObject

This method uses the optimum UDP buffer parameters for MiniSIP to update the system.



45
46
47
48
49
50
51
# File 'lib/csd/application/minisip/component/network.rb', line 45

def fix_udp_buffer
  return unless Gem::Platform.local.debian? or Options.reveal
  UI.info 'Fixing UDP buffer size'.green.bold
  OPTIMUM_BUFFERS.each do |key, value|
    Cmd.run %{sudo sysctl -w #{key}="#{value}"}, :announce_pwd => false
  end
end

.introductionObject

There is no actual operation for this introduction method.



122
123
# File 'lib/csd/application/minisip/component/network.rb', line 122

def introduction
end

.permanent_udp_bufferObject

This method makes the UDP buffer modification permanent. AI modifies the sysctl.conf file with the updated values and creates a backup file for it. But before that, AI will first look for the backup file, if it already exists, AI will consider the UDP buffer size parameters have been made permanent and do not touch any thing.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/csd/application/minisip/component/network.rb', line 58

def permanent_udp_buffer
  if Path.sysctl_conf_backup.file? and !Options.reveal
    UI.warn "The UDP buffer modifications seems to be permanent already. Delete #{Path.sysctl_conf_backup.enquote} to enforce it."
  else
    UI.info 'Making the UDP buffer modifications permanent'.green.bold
    content = Path.sysctl_conf.file? ? File.read(Path.sysctl_conf) : ''
    Cmd.copy Path.sysctl_conf, Path.new_sysctl_conf
    UI.info "Adding modifications to #{Path.new_sysctl_conf}".cyan
    modifications = ['# Changes made by the AI'] + OPTIMUM_BUFFERS.map { |key, value| %{#{key} = #{value}} }
    modifications = content + "\n" + modifications.join("\n")
    Cmd.touch_and_replace_content Path.new_sysctl_conf, modifications, :internal => true
    # We cannot use Cmd.copy here, because Cmd.copy has no superuser privileges.
    # And since we are for sure on Ubuntu, these commands will work.
    Cmd.run "sudo cp #{Path.sysctl_conf} #{Path.sysctl_conf_backup}", :announce_pwd => false
    Cmd.run "sudo cp #{Path.new_sysctl_conf} #{Path.sysctl_conf}", :announce_pwd => false
  end
end

.update_intelObject

This method update intel firmware by checking out and compiling it.



85
86
87
88
# File 'lib/csd/application/minisip/component/network.rb', line 85

def update_intel
  checkout_intel
  compile_intel
end

.update_realtekObject

This method update realtek firmware by checking out and compiling it.



78
79
80
81
# File 'lib/csd/application/minisip/component/network.rb', line 78

def update_realtek
  checkout_realtek
  compile_realtek
end