1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

python-nlamanger: importing vxlan creation support commit

Ticket: CM-8035
Reviewed By: CCR-4896
Testing Done: ifupdown smoke, -t vxlan tests

julien@hydra-01:~$ time runtests.sh -d cel-redxp-06 -r result_vxlan_all.txt -f . -T vxlan_all.log -l INFO -k $VM_BASE_KERNEL -i $VM_BASE_IMG $TESTS_HOME/tests/ -t vxlan

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
This commit is contained in:
Julien Fortin
2016-07-05 14:40:19 +02:00
parent 4a41d24b35
commit 3696839d82
2 changed files with 98 additions and 1 deletions

View File

@ -587,3 +587,42 @@ class NetlinkManager(object):
nbr.add_attribute(Neighbor.NDA_LLADDR, mac)
nbr.build_message(self.sequence.next(), self.pid)
return self.tx_nlpacket(nbr)
def link_add_vxlan(self, ifname, vxlanid, dstport=None, local=None,
group=None, learning='on', ageing=None):
debug = RTM_NEWLINK in self.debug
info_data = {Link.IFLA_VXLAN_ID: int(vxlanid)}
if dstport:
info_data[Link.IFLA_VXLAN_PORT] = int(dstport)
if local:
info_data[Link.IFLA_VXLAN_LOCAL] = local
if group:
info_data[Link.IFLA_VXLAN_GROUP] = group
learning = 0 if learning == 'off' else 1
info_data[Link.IFLA_VXLAN_LEARNING] = learning
ifindex = self.get_iface_index(ifname)
if ifindex:
info_data[Link.IFLA_VXLAN_LINK] = ifindex
if ageing:
info_data[Link.IFLA_VXLAN_AGEING] = int(ageing)
link = Link(RTM_NEWLINK, debug)
link.flags = NLM_F_CREATE | NLM_F_REQUEST
link.body = pack('Bxxxiii', socket.AF_UNSPEC, 0, 0, 0)
link.add_attribute(Link.IFLA_IFNAME, ifname)
if ifindex:
link.add_attribute(Link.IFLA_LINK, ifindex)
link.add_attribute(Link.IFLA_LINKINFO, {
Link.IFLA_INFO_KIND: "vxlan",
Link.IFLA_INFO_DATA: info_data
})
link.build_message(self.sequence.next(), self.pid)
return self.tx_nlpacket(link)

View File

@ -718,7 +718,7 @@ class AttributeIFLA_LINKINFO(Attribute):
kind = self.value[Link.IFLA_INFO_KIND]
if kind not in ('vlan', 'macvlan'):
if kind not in ('vlan', 'macvlan', 'vxlan'):
raise Exception('Unsupported IFLA_INFO_KIND %s' % kind)
# For now this assumes that all data will be packed in the native endian
@ -770,6 +770,64 @@ class AttributeIFLA_LINKINFO(Attribute):
else:
self.log.debug('Add support for encoding IFLA_INFO_DATA macvlan sub-attribute type %d' % info_data_type)
elif kind == 'vxlan':
if info_data_type in (Link.IFLA_VXLAN_ID,
Link.IFLA_VXLAN_LINK,
Link.IFLA_VXLAN_AGEING,
Link.IFLA_VXLAN_LIMIT,
Link.IFLA_VXLAN_PORT_RANGE):
sub_attr_pack_layout.append('HH')
sub_attr_payload.append(8) # length
sub_attr_payload.append(info_data_type)
sub_attr_pack_layout.append('L')
sub_attr_payload.append(info_data_value)
elif info_data_type in (Link.IFLA_VXLAN_GROUP,
Link.IFLA_VXLAN_LOCAL):
sub_attr_pack_layout.append('HH')
sub_attr_payload.append(8) # length
sub_attr_payload.append(info_data_type)
sub_attr_pack_layout.append('L')
reorder = unpack('<L', IPv4Address(info_data_value).packed)[0]
sub_attr_payload.append(IPv4Address(reorder))
elif info_data_type in (Link.IFLA_VXLAN_PORT,):
sub_attr_pack_layout.append('HH')
sub_attr_payload.append(6)
sub_attr_payload.append(info_data_type)
sub_attr_pack_layout.append('H')
sub_attr_payload.append(info_data_value)
sub_attr_pack_layout.extend('xx')
elif info_data_type in (Link.IFLA_VXLAN_TTL,
Link.IFLA_VXLAN_TOS,
Link.IFLA_VXLAN_LEARNING,
Link.IFLA_VXLAN_PROXY,
Link.IFLA_VXLAN_RSC,
Link.IFLA_VXLAN_L2MISS,
Link.IFLA_VXLAN_L3MISS,
Link.IFLA_VXLAN_UDP_CSUM,
Link.IFLA_VXLAN_UDP_ZERO_CSUM6_TX,
Link.IFLA_VXLAN_UDP_ZERO_CSUM6_RX,
Link.IFLA_VXLAN_REMCSUM_TX,
Link.IFLA_VXLAN_REMCSUM_RX,
Link.IFLA_VXLAN_REPLICATION_TYPE):
sub_attr_pack_layout.append('HH')
sub_attr_payload.append(6)
sub_attr_payload.append(info_data_type)
sub_attr_pack_layout.append('B')
sub_attr_payload.append(info_data_value)
sub_attr_pack_layout.extend('xxx')
else:
self.log.debug('Add support for encoding IFLA_INFO_DATA vxlan sub-attribute type %d' % info_data_type)
else:
self.log.debug('Add support for encoding IFLA_LINKINFO sub-attribute type %d' % sub_attr_type)
continue