close Warning: Can't synchronize with repository "(default)" (/common/SVN/wimax does not appear to be a Subversion repository.). Look in the Trac log for more information.

Changes between Version 6 and Version 7 of WiMAX/TeltonikaOmfDriver


Ignore:
Timestamp:
Mar 15, 2013, 3:31:00 AM (11 years ago)
Author:
ffund01
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • WiMAX/TeltonikaOmfDriver

    v6 v7  
    1414== Installing the driver ==
    1515
    16 === Patches to omf-resctl ===
     16=== Patches to omf-resctl (on the node) ===
    1717
    1818In /usr/share/omf-resctl-5.3/omf-resctl/omf_agent/nodeAgent.rb:
     
    5050#
    5151# This file defines the class TeltonikaDevice which is a sub-class of
     52# WimaxcuDevice.
    5253#
    5354require 'omf-resctl/omf_driver/wimax'
     
    7071 
    7172    clearIP = deconfig
    72     @mode = @chnnl = @frequency = @bandwidth = @ip = @subnet = @nm = @fnm = @gw = @routip = @oldroutip = @oldnetmask = nil;
    73     @deldef = false
     73    @mode = @chnnl = @frequency = @bandwidth = @ip = @dip = @subnet = @nm = @fnm = @gw = @routip = @oldroutip = @oldnetmask = nil;
     74    @deldef = false
     75    $chflag = 0
    7476  end
    7577 
     
    8284    host.cmd("export interface=icc0"){ |c| print c }
    8385    host.cmd("/etc/udhcpc.script deconfig"){ |c| print c }
     86    host.cmd("/bin/iptables -t nat -F") { |c| print c }
    8487    host.close
     88  end
     89 
     90  def telnet_dynamicIP
     91    debug "Configuring iptables for dynamic IP"
     92    host = Net::Telnet::new("Host" => "192.168.0.1",
     93                             "Timeout" => 10,
     94                             "Port" => 700,
     95                             "Prompt" => /[$%#>] \z/n)
     96    host.login("admin", "admin01") { |c| print c }
     97 
     98    begin
     99      str = host.cmd("ifconfig icc0") { |c| print c }
     100      #get the dynamic IP address:
     101      lines = str.split("\n")
     102      lines=lines.drop(2)
     103      lines=lines.reverse.drop(6).reverse
     104      vals=lines.collect { |row|
     105        column = row.split(" ")
     106        column[1]
     107      }
     108 
     109      addr=vals[0]
     110      addrAr=addr.split("\:")
     111      dynIP=addrAr[1]   
     112    end while "#{dynIP}" <= ""
     113    host.close
     114 
     115    debug "Dynamic IP is: #{dynIP} \n"
     116    #add the rules to the iptables:
     117    rule1 = "/bin/iptables -t nat -A PREROUTING -p udp -d #{dynIP} -j DNAT --to 192.168.0.8"
     118    rule2 = "/bin/iptables -t nat -A PREROUTING -p tcp -d #{dynIP} -j DNAT --to 192.168.0.8"
     119    debug "Running #{rule1} \n"
     120    debug "Running #{rule2} \n"
     121   #second telnet session to add the rules:
     122    host = Net::Telnet::new("Host" => "192.168.0.1",
     123                             "Timeout" => 10,
     124                             "Port" => 700,
     125                             "Prompt" => /[$%#>] \z/n)
     126    host.login("admin", "admin01") { |c| print c }
     127    begin
     128      host.cmd("#{rule1}") { |c| print c }
     129      host.cmd("#{rule2}") { |c| print c }
     130      rtrn = host.cmd("/bin/iptables -t nat -L") { |c| print c }
     131    end while !(rtrn.include? "192.168.0.8")
     132    host.close
     133    return dynIP
    85134  end
    86135 
     
    116165    host.cmd("export router=#{router}"){ |c| print c }
    117166    host.cmd("/etc/udhcpc.script bound"){ |c| print c }
     167    host.cmd("/bin/iptables -t nat -A PREROUTING -p udp -d #{ip} -j DNAT --to 192.168.0.8"){ |c| print c }
     168    host.cmd("/bin/iptables -t nat -A PREROUTING -p tcp -d #{ip} -j DNAT --to 192.168.0.8"){ |c| print c }
    118169    host.close
    119170 
    120171    @fnm = netmask #final netmask. This will be used in 'unload'
    121     return tlres   
     172    return tlres
     173 
    122174  end
    123175 
    124176  def initialize(logicalName, deviceName)
    125177    super(logicalName, deviceName)
    126     @mode = @ip = @subnet = @nm = @gw = nil
     178    @mode = @ip = @dip = @subnet = @nm = @gw = nil
    127179    @ifconfig = '/sbin/ifconfig'
    128180    @wget = '/usr/bin/wget'
    129181    @route = '/sbin/route'
    130182    @deldef = false
     183    $chflag = 0
    131184    IO.popen("#{@ifconfig} #{deviceName} 192.168.0.8 netmask 255.255.255.0")
    132185  end
     
    138191      when :channel
    139192        return nil if @chnnl.nil?
    140        cmd =  "#{@wget} --http-user admin --http-password admin -qO - 'http://192.168.0.1/cgi/cli?stopSs'; #{@wget} --http-user admin --http-password admin -qO - 'http://192.168.0.1/cgi/cli?addChannel frequency=#{@frequency} bandwidth=#{@bandwidth}'; #{@wget} --http-user admin --http-password admin -qO - 'http://192.168.0.1/cgi/cli?startSs'; #{@route} add default gw 192.168.0.1"
     193        cmd =  "#{@wget} --http-user admin --http-password admin -qO - 'http://192.168.0.1/cgi/cli?stopSs'; #{@wget} --http-user admin --http-password admin -qO - 'http://192.168.0.1/cgi/cli?addChannel frequency=#{@frequency} bandwidth=#{@bandwidth}'; #{@wget} --http-user admin --http-password admin -qO - 'http://192.168.0.1/cgi/cli?startSs'; #{@route} add default gw 192.168.0.1"
     194        $chflag = 1
    141195      when :ip
    142196        return nil if @ip.nil?
     
    151205        comRes = telnetIfConf
    152206        cmd = comRes unless comRes.nil?
     207      when :dynip
     208        return nil if @dip.nil?
     209        if $chflag == 1
     210          comRes = telnet_dynamicIP
     211        else
     212          raise "CONNECT THE DEVICE (setup the channel first!) BEFORE ASSIGNING AN IP..."
     213        end
     214        cmd = nil       
    153215    else
    154       raise "Unknown mode '#{@mode}'. Should be 'initiate', 'channel', 'mtu' or 'ip'"
    155     end
     216      raise "Unknown mode '#{@mode}'. Should be 'channel', 'mtu', gway, dynip, netmask, or 'ip'"
     217    end 
    156218    return cmd
    157219  end
    158 #
     220  #
    159221  # Return the specific command required to configure a given property of this
    160222  # device. When a property does not exist for this device, check if it does
     
    176238        @nm = value
    177239        @subnet = IPAddr.new("#{@nm}").to_i.to_s(2).count("1")
     240        return buildCmd
     241      when "dynip"
     242        @mode = :dynip
     243        @dip = value
    178244        return buildCmd
    179245      when "gway"