Jordan Flynn
Jordan Flynn

Reputation: 1

Trying to get H1 to ping h2

I'm trying to allow H1 to Ping H2 however when I run Pingalll I get X on every port. H1 is unable to ping H2. H1 is connect to s1 on port 1 to port 1, H2 is connected to s2 on port 1 to port 1,s1 is connected to s2 on port 2 to port 2 I don't understand why the code isn't allowing H2 to respond to H1 request

Here is my icmp code

import eventlet
eventlet.monkey_patch()

from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0
from ryu.ofproto import ether
from ryu.lib.packet import packet, arp, ethernet

class DataCentre(app_manager.RyuApp):
    OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]

    def __init__(self, *args, **kwargs):
        super(DataCentre, self).__init__(*args, **kwargs)
        self.switch_dps = {}  # Dictionary to store switch datapaths

    @set_ev_cls(ofp_event.EventOFPStateChange, [MAIN_DISPATCHER])
    def switch_join(self, ev):
        # Save the datapath when a switch joins
        dp = ev.datapath
        self.switch_dps[dp.id] = dp
        self.logger.info(f"Switch {dp.id} joined the topology.")

    def add_flow(self, dp, priority, match, actions):
        ofp = dp.ofproto
        ofp_parser = dp.ofproto_parser
        mod_msg = ofp_parser.OFPFlowMod(
            datapath=dp,
            match=match,
            command=ofp.OFPFC_ADD,
            actions=actions,
            priority=priority
        )
        dp.send_msg(mod_msg)

    def setup_icmp(self, dp, port, nw_src, nw_dst):
        ofp = dp.ofproto
        ofp_parser = dp.ofproto_parser

        # Allow ICMP from h1 to h2
        if nw_src == '10.1.1.1' and nw_dst == '10.1.1.2':
            match = ofp_parser.OFPMatch(
                dl_type=0x0800,
                nw_src='10.1.1.1',
                nw_dst='10.1.1.2',
                nw_proto=1
            )
            actions = [ofp_parser.OFPActionOutput(port)]
            self.add_flow(dp, 5, match, actions)

        # Block ICMP from h1 to h3, h4, h5
        elif nw_src == '10.1.1.1' and nw_dst in ['10.1.1.3', '10.1.1.4', '10.1.1.5']:
            match = ofp_parser.OFPMatch(
                dl_type=0x0800,
                nw_src='10.1.1.1',
                nw_dst=nw_dst,
                nw_proto=1
            )
            self.add_flow(dp, 10, match, [])

    @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
    def packet_in_handler(self, ev):
        # ARP resolution implementation
        msg = ev.msg
        dp = msg.datapath
        ofp = dp.ofproto
        ofp_parser = dp.ofproto_parser
       

I've changed every part of this and have copied example code form online and it doesn't allow any pinging from any host.

Upvotes: 0

Views: 41

Answers (0)

Related Questions