DMTF / Redfish-Mockup-Server

A simple Python 3.4 program that can be copied into a folder at the top of any Redfish mockup and can serve Redfish requests on the specified IP/port.
Other
87 stars 38 forks source link

SSDP does not work #94

Closed andremarcondesteixeira closed 1 year ago

andremarcondesteixeira commented 1 year ago

I have a local instance of the Redfish Mockup Server. I am running it on Windows 11, my firewall is disabled and I tried it with the Windows' SSDP Service on and off.

This is my client code:

// file Program.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddHostedService<RedfishServerDiscoveryService>();

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseStaticFiles();
app.UseRouting();
app.MapRazorPages();
app.Run();

public class RedfishServerDiscoveryService : BackgroundService
{
    private readonly ILogger<RedfishServerDiscoveryService> _logger;

    public RedfishServerDiscoveryService(ILogger<RedfishServerDiscoveryService> logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        // Send an SSDP search message to the network to discover Redfish servers
        var ssdpMessage = "M-SEARCH * HTTP/1.1\r\n" +
                          "HOST: 239.255.255.250:1900\r\n" +
                          "MAN: \"ssdp:discover\"\r\n" +
                          "ST: urn:dmtf-org:service:redfish-rest:1\r\n" +
                          "MX: 5\r\n" +
                          "\r\n";
        var ssdpBytes = Encoding.UTF8.GetBytes(ssdpMessage);
        var ssdpEndpoint = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);

        using (var udpClient = new UdpClient())
        {
            udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            udpClient.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));

            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    await udpClient.SendAsync(ssdpBytes, ssdpBytes.Length, ssdpEndpoint);
                    _logger.LogInformation("Sent SSDP search message to discover Redfish servers.");

                    var receiveTask = udpClient.ReceiveAsync();
                    if (await Task.WhenAny(receiveTask, Task.Delay(TimeSpan.FromSeconds(10))) == receiveTask)
                    {
                        var response = receiveTask.Result;
                        var responseMessage = Encoding.UTF8.GetString(response.Buffer);
                        _logger.LogInformation($"Received SSDP response from {response.RemoteEndPoint}: {responseMessage}");
                    }
                    else
                    {
                        _logger.LogInformation("No SSDP response received from Redfish servers.");
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error discovering Redfish servers using SSDP.");
                }
            }
        }
    }
}

expected behavior: The Mockup Server should respond to the SSDP messages actual behavior: The Mockup Server does not respond the messages

mraineri commented 1 year ago

Just to confirm, are you running your mockup server and your SSDP client both on the same Windows 11 system?

Are you also supplying arguments for the mockup server to bind to an interface, or are you leaving it running at the default setting where it's only visible at 127.0.0.1?

andremarcondesteixeira commented 1 year ago

Yes, they are running on the same system. I am starting the Mockup Server using this command: python ./redfishMockupServer.py -P

mraineri commented 1 year ago

Great, thanks for confirming; we'll check it out!

andremarcondesteixeira commented 1 year ago

Pull Request https://github.com/DMTF/Redfish-Mockup-Server/pull/95 by @mraineri fixes this. Thank you!