Skip to content

Commit 3737175

Browse files
authored
Merge pull request #90 from DMTF/Fix88-SSDP-IPv6
SSDP updates
2 parents e3cb194 + b19b261 commit 3737175

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

redfish_protocol_validator/service_details.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ def test_event_error_on_bad_request(sut: SystemUnderTest):
106106

107107
def pre_ssdp(sut: SystemUnderTest):
108108
"""Perform prerequisite SSDP steps"""
109-
# discover using the redfish search target
110-
services = utils.discover_ssdp(search_target=SSDP_REDFISH)
111-
sut.add_ssdp_services(SSDP_REDFISH, services)
109+
# try to discover with both IPv4 and IPv6
110+
for protocol in ['ipv4', 'ipv6']:
111+
# discover using the redfish search target
112+
services = utils.discover_ssdp(search_target=SSDP_REDFISH, protocol=protocol)
113+
sut.add_ssdp_services(SSDP_REDFISH, services)
112114

113-
# discover using the ssdp:all search target
114-
services = utils.discover_ssdp(search_target=SSDP_ALL)
115-
sut.add_ssdp_services(SSDP_ALL, services)
115+
# discover using the ssdp:all search target
116+
services = utils.discover_ssdp(search_target=SSDP_ALL, protocol=protocol)
117+
sut.add_ssdp_services(SSDP_ALL, services)
116118

117119
# determine SSDP enabled/disabled state
118120
if sut.mgr_net_proto_uri:
@@ -317,20 +319,26 @@ def test_ssdp_st_header_format(sut: SystemUnderTest):
317319
Assertion.SERV_SSDP_ST_HEADER_FORMAT, msg)
318320
return
319321

320-
st_minor = 0
321-
msg_minor = 'missing'
322322
if m.group(1):
323323
st_minor = int(m.group(1).lstrip(':'))
324324
msg_minor = str(st_minor)
325-
# if the service minor ver is non-zero, must be included in the ST header
326-
if sut.version_tuple.minor != 0 and sut.version_tuple.minor != st_minor:
327-
# FAIL minor version incorrectly specified in ST header
328-
msg = ('The Redfish protocol minor version from the Service Root is '
329-
'%s, but the minor version in the ST header is %s'
330-
% (sut.version_tuple.minor, msg_minor))
331-
sut.log(Result.FAIL, '', '', st_header,
332-
Assertion.SERV_SSDP_ST_HEADER_FORMAT, msg)
333-
return
325+
# only test the minor version if provided in the header
326+
# returning the minor version is not required
327+
if sut.version_tuple.minor != st_minor:
328+
# FAIL minor version incorrectly specified in ST header
329+
msg = ('The Redfish protocol minor version from the service root is '
330+
'%s, but the minor version in the ST header is %s'
331+
% (sut.version_tuple.minor, msg_minor))
332+
sut.log(Result.FAIL, '', '', st_header,
333+
Assertion.SERV_SSDP_ST_HEADER_FORMAT, msg)
334+
return
335+
if sut.version_tuple.minor == 0:
336+
# FAIL minor version is not allowed if its 0
337+
msg = ('The Redfish protocol minor version from the service root is '
338+
'0, but the ST header contained a minor version')
339+
sut.log(Result.FAIL, '', '', st_header,
340+
Assertion.SERV_SSDP_ST_HEADER_FORMAT, msg)
341+
return
334342

335343
# PASS if we have not already logged a result and returned
336344
sut.log(Result.PASS, '', '', st_header,

redfish_protocol_validator/system_under_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ def mgr_net_proto_uri(self):
190190
return self._mgr_net_proto_uri
191191

192192
def add_ssdp_services(self, search_target, services):
193-
self._ssdp_services[search_target] = services
193+
if search_target not in self._ssdp_services:
194+
self._ssdp_services[search_target] = {}
195+
self._ssdp_services[search_target].update(services)
194196

195197
def get_ssdp_services(self, search_target):
196198
return self._ssdp_services.get(search_target, {})

redfish_protocol_validator/utils.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,18 @@ def discover_ssdp(port=1900, ttl=2, response_time=3, iface=None,
363363
socket.setdefaulttimeout(response_time + 2)
364364

365365
# Set up the socket and send the request
366-
sock = socket.socket(af_type, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
367-
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
368-
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
369-
if iface:
370-
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE,
371-
str(iface+'\0').encode('utf-8'))
372-
sock.sendto(bytearray(msearch_str, 'utf-8'), mcast_connection)
366+
try:
367+
sock = socket.socket(af_type, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
368+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
369+
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
370+
if iface:
371+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE,
372+
str(iface+'\0').encode('utf-8'))
373+
sock.sendto(bytearray(msearch_str, 'utf-8'), mcast_connection)
374+
except:
375+
# Covers cases where the system may not support IPv6
376+
sock.close()
377+
return {}
373378

374379
# On the same socket, wait for responses
375380
discovered_services = {}

unittests/test_service_details.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ def test_test_ssdp_st_header_format_fail2(self):
505505

506506
def test_test_ssdp_st_header_format_fail3(self):
507507
self.sut.set_service_uuid(self.uuid)
508-
self.sut.set_version('1.6.0')
509-
st = 'urn:dmtf-org:service:redfish-rest:1' # missing minor version
508+
self.sut.set_version('1.0.0')
509+
st = 'urn:dmtf-org:service:redfish-rest:1:0' # minor version is 0
510510
services = {
511511
self.uuid: {
512512
'USN': 'abc',
@@ -520,7 +520,7 @@ def test_test_ssdp_st_header_format_fail3(self):
520520
'', st)
521521
self.assertIsNotNone(result)
522522
self.assertEqual(Result.FAIL, result['result'])
523-
self.assertIn('6, but the minor version in the ST header is missing',
523+
self.assertIn('0, but the ST header contained a minor version',
524524
result['msg'])
525525

526526
def test_test_ssdp_st_header_format_fail4(self):

0 commit comments

Comments
 (0)