Security in CPS/Networking

Ryu_manager Openflow1.0 -> Openflow1.3 변경

mjune.kim 2020. 8. 4. 23:28

SDN Controller 로 Ryu_manager 를 사용중인데 최근 여러가지 이슈들로 인해 Openflow1.3으로 변경하여 실험을 진행해 보았다.

Openflow1.0에선 Version negotiation 이후 스위치에 매칭되는 flow rule이 존재하지 않을 경우 자동으로 Controller 로 패킷을 포워딩하는 기능이 내재되어 있었다. 하지만 Openflow1.3에서는 이를 명시적으로 rule 을 추가해야만 컨트롤러에서 스위치로 부터 패킷을 전달받을 수 있다. 이는 Simple_switch_13.py에 이미 포함되어 있으나 Openflow1.0만을 사용하던 나로써는 당황스러울 수밖에 없었다.

다음은 Simple_switch_13.py에서 해당하는 코드 snippet이다.

@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
    def switch_features_handler(self, ev):
        datapath = ev.msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        # install table-miss flow entry
        #
        # We specify NO BUFFER to max_len of the output action due to
        # OVS bug. At this moment, if we specify a lesser number, e.g.,
        # 128, OVS will send Packet-In with invalid buffer_id and
        # truncated packet data. In that case, we cannot output packets
        # correctly.  The bug has been fixed in OVS v2.1.0.
        match = parser.OFPMatch()
        actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
                                          ofproto.OFPCML_NO_BUFFER)]
        self.add_flow(datapath, 0, match, actions)

    def add_flow(self, datapath, priority, match, actions, buffer_id=None):
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
                                             actions)]
        if buffer_id:
            mod = parser.OFPFlowMod(datapath=datapath, buffer_id=buffer_id,
                                    priority=priority, match=match,
                                    instructions=inst)
        else:
            mod = parser.OFPFlowMod(datapath=datapath, priority=priority, table_id = 100,
                                    match=match, instructions=inst)
        datapath.send_msg(mod)

 이 때 주의할 것은 table_id 항목이다. 샘플 코드에서는 포함되어 있지 않지만 그냥 실행시 다음과 같은 에러를 만나게 된다. 링크도 첨부했지만 table_id 가 설정하지 않을 경우 default 값인 0 으로 설정이 되는데 Controller 로 패킷을 전달해야 하는 경우 HW:100, SW:200 으로 설정해야만 에러가 발생하지 않게 된다. (샘플코드만 믿고 따라하다가 맘고생만 했다.ㅠ.ㅠ)

2020-08-04 23:01:05,657 OFPErrorMsg(type=0x3, code=0x1, data=b'\x04\x0e\x00\x50\x69\x68\x62\xee\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x04\x00\x00\x00\x00\x00\x04\x00\x18\x00\x00\x00\x00')
 |-- type: OFPET_BAD_INSTRUCTION(3)
 |-- code: OFPBIC_UNSUP_INST(1)
 `-- data: version=0x4, msg_type=0xe, msg_len=0x50, xid=0x696862ee
     `-- msg_type: OFPT_FLOW_MOD(14)
2020-08-04 23:01:05,657  `-- data: version=0x4, msg_type=0xe, msg_len=0x50, xid=0x696862ee
     `-- msg_type: OFPT_FLOW_MOD(14)

community.hpe.com/t5/software-defined-networking/bad-instruction-error-when-using-aruba-3810-switching-with/m-p/6988434#M2243