Line data Source code
1 : /* 2 : * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #include <pkt/flow_mgmt/flow_mgmt_key.h> 7 : #include <pkt/flow_mgmt.h> 8 : #include <oper/health_check.h> 9 : 10 3494 : FlowEvent::Event FlowMgmtKey::FreeDBEntryEvent() const { 11 3494 : FlowEvent::Event event = FlowEvent::INVALID; 12 : 13 3494 : switch (type_) { 14 3494 : case INTERFACE: 15 : case ACL: 16 : case VN: 17 : case INET4: 18 : case INET6: 19 : case BRIDGE: 20 : case NH: 21 : case VRF: 22 3494 : event = FlowEvent::FREE_DBENTRY; 23 3494 : break; 24 : 25 0 : case ACE_ID: 26 : case VM: 27 0 : event = FlowEvent::INVALID; 28 0 : break; 29 0 : case BGPASASERVICE: 30 0 : event = FlowEvent::INVALID; 31 : 32 0 : default: 33 0 : assert(0); 34 : } 35 : 36 3494 : return event; 37 : } 38 : 39 0 : void BgpAsAServiceFlowMgmtKey::StartHealthCheck( 40 : Agent *agent, FlowEntry *flow, const boost::uuids::uuid &hc_uuid) { 41 0 : if (bgp_health_check_instance_ != NULL) { 42 0 : bgp_health_check_instance_->UpdateInstanceTask(); 43 0 : return; 44 : } 45 : 46 0 : bgp_health_check_service_ = agent->health_check_table()->Find(hc_uuid); 47 0 : if (bgp_health_check_service_ == NULL) { 48 0 : LOG(DEBUG, "Unable to start BFD health check " << hc_uuid << " on flow " 49 : " destination = " << flow->key().dst_addr << 50 : " source = " << flow->key().src_addr); 51 0 : return; 52 : } 53 : 54 : const VmInterface *vm_interface = 55 0 : static_cast<const VmInterface *>(flow->intf_entry()); 56 0 : bgp_health_check_instance_ = 57 0 : bgp_health_check_service_->StartHealthCheckService( 58 : const_cast<VmInterface *>(vm_interface), 59 0 : flow->key().dst_addr, flow->key().src_addr); 60 : 61 0 : HealthCheckInstanceService *bfd_instance = 62 : static_cast<HealthCheckInstanceService *>( 63 : bgp_health_check_instance_); 64 : FlowMgmtManager *flow_mgmt_manager = 65 0 : agent->pkt()->flow_mgmt_manager(flow->flow_table()->table_index()); 66 0 : bfd_instance->SetBfdDownCallback( 67 : boost::bind(&FlowMgmtManager::BgpAsAServiceNotify, 68 : flow_mgmt_manager, uuid_, source_port_)); 69 : 70 0 : bgp_health_check_instance_->SetService(bgp_health_check_service_); 71 : } 72 : 73 0 : void BgpAsAServiceFlowMgmtKey::StopHealthCheck(FlowEntry *flow) { 74 0 : if (bgp_health_check_service_ && bgp_health_check_instance_) { 75 0 : bgp_health_check_service_->StopHealthCheckService( 76 : bgp_health_check_instance_); 77 0 : bgp_health_check_instance_ = NULL; 78 0 : bgp_health_check_service_ = NULL; 79 : } 80 0 : } 81 : 82 0 : bool InetRouteFlowMgmtKey::NeedsReCompute(const FlowEntry *flow) { 83 0 : if (Match(flow->key().src_addr)) { 84 0 : return true; 85 : } 86 : 87 0 : if (Match(flow->key().dst_addr)) { 88 0 : return true; 89 : } 90 : 91 0 : const FlowEntry *rflow = flow->reverse_flow_entry(); 92 0 : if (rflow == NULL) { 93 0 : return true; 94 : } 95 : 96 0 : if (Match(rflow->key().src_addr)) { 97 0 : return true; 98 : } 99 : 100 0 : if (Match(rflow->key().dst_addr)) { 101 0 : return true; 102 : } 103 : 104 0 : return false; 105 : }