Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef vnsw_agent_inet_interface_hpp 7 : #define vnsw_agent_inet_interface_hpp 8 : 9 : struct InetInterfaceData; 10 : 11 : ///////////////////////////////////////////////////////////////////////////// 12 : // Implementation of inet interfaces created in host-os. 13 : // 14 : // Example interfaces: 15 : // vhost0 : A L3 interface between host-os and vrouter. Used in KVM mode 16 : // xenbr : A L3 interface between host-os and vrouter. Used in XEN mode 17 : // xapi0 : A L3 interface for link-local subnets. Used in XEN mode 18 : // vgw : A un-numbered L3 interface for simple gateway 19 : ///////////////////////////////////////////////////////////////////////////// 20 : class InetInterface : public Interface { 21 : public: 22 : enum SubType { 23 : VHOST, 24 : LINK_LOCAL, 25 : SIMPLE_GATEWAY 26 : }; 27 : 28 : InetInterface(const std::string &name); 29 : InetInterface(const std::string &name, SubType sub_type, VrfEntry *vrf, 30 : const Ip4Address &ip_addr, int plen, const Ip4Address &gw, 31 : Interface *xconnect, const std::string &vn_name); 32 20 : virtual ~InetInterface() { } 33 : 34 : // DBTable virtual functions 35 : KeyPtr GetDBRequestKey() const; 36 0 : std::string ToString() const { return "INET <" + name() + ">"; } 37 : 38 : // The interfaces are keyed by name. No UUID is allocated for them 39 : virtual bool CmpInterface(const DBEntry &rhs) const; 40 4 : SubType sub_type() const { return sub_type_; } 41 4 : const Ip4Address &ip_addr() const { return ip_addr_; } 42 0 : Interface *xconnect() const { return xconnect_.get(); } 43 : 44 : void PostAdd(); 45 : bool OnChange(InetInterfaceData *data); 46 : bool Delete(const DBRequest *req); 47 : void Activate(); 48 : void DeActivate(); 49 : 50 : void ActivateSimpleGateway(); 51 : void DeActivateSimpleGateway(); 52 : void ActivateHostInterface(); 53 : void DeActivateHostInterface(); 54 : void AddHostMulticastRoutes(); 55 : void DelHostMulticastRoutes(); 56 : 57 : // Helper functions 58 : static void Create(InterfaceTable *table, const std::string &ifname, 59 : SubType sub_type, const std::string &vrf_name, 60 : const Ip4Address &addr, int plen, 61 : const Ip4Address &gw, const std::string &xconnect, 62 : const std::string &vn_name, 63 : Interface::Transport transport); 64 : static void CreateReq(InterfaceTable *table, const std::string &ifname, 65 : SubType sub_type, const std::string &vrf_name, 66 : const Ip4Address &addr, int plen, 67 : const Ip4Address &gw, const std::string &xconnect, 68 : const std::string &vn_name, 69 : Interface::Transport transport); 70 : static void Delete(InterfaceTable *table, const std::string &ifname); 71 : static void DeleteReq(InterfaceTable *table, const std::string &ifname); 72 : private: 73 : SubType sub_type_; 74 : Ip4Address ip_addr_; 75 : int plen_; 76 : Ip4Address gw_; 77 : InterfaceRef xconnect_; // Physical interface for VHOST 78 : std::string vn_name_; 79 : DISALLOW_COPY_AND_ASSIGN(InetInterface); 80 : }; 81 : 82 : struct InetInterfaceKey : public InterfaceKey { 83 : InetInterfaceKey(const std::string &name); 84 19 : virtual ~InetInterfaceKey() { } 85 : 86 : Interface *AllocEntry(const InterfaceTable *table) const; 87 : Interface *AllocEntry(const InterfaceTable *table, 88 : const InterfaceData *data) const; 89 : InterfaceKey *Clone() const; 90 : }; 91 : 92 : struct InetInterfaceData : public InterfaceData { 93 : InetInterfaceData(InetInterface::SubType sub_type, 94 : const std::string &vrf_name, const Ip4Address &addr, 95 : int plen, const Ip4Address &gw, 96 : const std::string &xconnect, const std::string vn_name, 97 : Interface::Transport transport); 98 2 : virtual ~InetInterfaceData() { } 99 : 100 : InetInterface::SubType sub_type_; 101 : Ip4Address ip_addr_; 102 : int plen_; 103 : Ip4Address gw_; 104 : std::string xconnect_; 105 : std::string vn_name_; 106 : }; 107 : 108 : #endif // vnsw_agent_inet_interface_hpp