Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IPXE LLDP and type casting
2019-06-28, 22:17
Post: #1
IPXE LLDP and type casting
Hi Guys,
I have made sosme changes to support LLDP protocol in ipxe.
https://github.com/andrei4ka/ipxe/commit...1c640846a4

The code itself working as expected. But I can not make ipxe to set ip-address on interface. There is a mess with a type.

I have a string 010.001.001.034 which is IP-address, and i want to set this ip on interface but for some reason can't.

Can you please help me with a type casting?

Code:
#!ipxe

ifopen

:start
set intf netX
set timeout 60

set tab:int8 9
set src ${${intf}.lldp/lldpsource}
echo -- Waiting for an LLDP packet to arrive...
set count:int32 0
:retry_poll_lldp
iseq ${${intf}.lldp/lldpsource} ${src} || goto mgmtaddr
sleep 1
inc count
iseq ${count} ${timeout} || goto retry_poll_lldp
clear count

# You may handle timeout here
echo -- Timed out waiting for an LLDP packet
exit 1

:mgmtaddr

echo -- Got an LLDP packet from ${${intf}.lldp/lldpsource}
echo --

# Set the maximum length of portname like Gi1/0/34 = 8
set loop:int32 16
# Lets count the length on the string to find the right ofset number
:get_len_tlv2
  echo -- len of ${${intf}.lldp/2} now eq=${loop}
  inc loop -1
  isset ${${intf}.lldp/${loop}.1.0.2} || goto get_len_tlv2

  echo -- The length of porname ${${intf}.lldp/2} = ${loop}
  echo -- Let's get 1 or 2 digits right after the slash symbol
  # Let's identify how much symbols in portnumber
  # For exmple 34 = 2 symbols
  #             7 = 1 symbol
set num:int8 0
:right_position
  inc loop -1
  inc num
  # Let's try to find the slash before the digits
  echo -- Is it slash with hex(2f): ${${intf}.lldp/${loop}.1.0.2:hex} = 2f on ${loop} position?
  iseq ${${intf}.lldp/${loop}.1.0.2:hex} 2f ||  goto right_position

:portnum
  inc loop
  isset ${${intf}.lldp/${loop}.1.0.2} || goto exit_portnum
  set portnum ${portnum}${${intf}.lldp/${loop}.1.0.2}
  echo ${portnum}
  iseq num 0 || goto portnum

:exit_portnum
  echo -- Portnum : ${portnum}

:count_net
set loop:int32 255
:get_len_tlv5
  echo -- len of ${${intf}.lldp/5} now eq=${loop}
  inc loop -1
  isset ${${intf}.lldp/${loop}.1.0.5} || goto get_len_tlv5

  echo -- The length of tlv5 ${${intf}.lldp/5} = ${loop}
  echo -- The l of tlv 5 ${${intf}.lldp/5:strlen}
  inc loop -19
  set ip_addr ${ip_addr}${${intf}.lldp/${loop}.3.0.5}
  inc loop 3
  set ip_addr ${ip_addr}.${${intf}.lldp/${loop}.3.0.5}
  inc loop 3
  set ip_addr ${ip_addr}.${${intf}.lldp/${loop}.3.0.5}
  set gw ${ip_addr}.1
  set ip_addr ${ip_addr}.0${portnum}
  echo ${loop}
  echo ${ip_addr}

  echo -- ip_addr = ${ip_addr}
  ifclose net0
  set net0/ip ${ip_addr}
  set net0/netmask 255.255.255.0
  set net0/gateway ${gw}
  ifopen net0

  ifstat net0

echo Starting Ubuntu x64 installer for ${hostname}
set base-url http://${gw}
kernel ${base-url}/linux
initrd ${base-url}/initrd.gz
boot ||

# If everything failed, give the user some options
echo Boot from ${base-url} failed
prompt --key 0x197e --timeout 2000 Press F12 to investigate || exit
shell
Find all posts by this user
Quote this message in a reply
2019-07-03, 00:59
Post: #2
RE: IPXE LLDP and type casting
count the length on the string to find the right ofset number?

so basically you invented two string manipulating methods: len(str) and substr(str)?

sounds good
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)