Line data Source code
1 : /*
2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3 : */
4 : #ifndef src_vnsw_agent_oper_physical_interface_hpp
5 : #define src_vnsw_agent_oper_physical_interface_hpp
6 :
7 : struct PhysicalInterfaceData;
8 : struct PhysicalInterfaceOsOperStateData;
9 :
10 : /////////////////////////////////////////////////////////////////////////////
11 : // Implementation of Physical Ports local to the device
12 : // Does not have reference to physical-device since they are local devices
13 : // Can be Ethernet Ports or LAG Ports
14 : // Name of port is used as key
15 : /////////////////////////////////////////////////////////////////////////////
16 : class PhysicalInterface : public Interface {
17 : public:
18 : enum SubType {
19 : FABRIC, // Physical port connecting to fabric network
20 : VMWARE, // For vmware, port connecting to contrail-vm-portgroup
21 : CONFIG, // Interface created from config
22 : INVALID
23 : };
24 :
25 : enum EncapType {
26 : ETHERNET, // Ethernet with ARP
27 : RAW_IP // No L2 header. Packets sent as raw-ip
28 : };
29 :
30 : struct Bond_ChildIntf {
31 : string intf_name;
32 : string intf_drv_name;
33 : bool intf_status;
34 : };
35 :
36 : typedef std::map<const std::string, Bond_ChildIntf> BondChildIntfMap;
37 : typedef BondChildIntfMap::const_iterator BondChildIntfMapIterator;
38 :
39 :
40 : PhysicalInterface(const std::string &name,
41 : const boost::uuids::uuid &logical_router_uuid);
42 : virtual ~PhysicalInterface();
43 :
44 : virtual bool CmpInterface(const DBEntry &rhs) const;
45 : virtual std::string ToString() const;
46 : virtual KeyPtr GetDBRequestKey() const;
47 :
48 : virtual void PostAdd();
49 : virtual bool Delete(const DBRequest *req);
50 : virtual bool OnChange(const InterfaceTable *table,
51 : const PhysicalInterfaceData *data);
52 26 : SubType subtype() const { return subtype_; }
53 : PhysicalDevice *physical_device() const;
54 91 : const std::string& display_name() const {
55 91 : return display_name_;
56 : }
57 :
58 : // Lets kernel know if physical interface is to be kept after agent exits or
59 : // dies. If its true keep the interface, else remove it.
60 : // Currently only vnware physical interface is persistent.
61 : // By default every physical interface is non-persistent.
62 9 : bool persistent() const {return persistent_;}
63 91 : EncapType encap_type() const { return encap_type_; }
64 91 : bool no_arp() const { return no_arp_; }
65 91 : Ip4Address ip_addr() const { return ip_;}
66 :
67 : // Helper functions
68 : static void CreateReq(InterfaceTable *table, const std::string &ifname,
69 : const std::string &vrf_name, SubType subtype,
70 : EncapType encap, bool no_arp,
71 : const boost::uuids::uuid &device_uuid,
72 : const Ip4Address &ip,
73 : Interface::Transport transport);
74 : static void Create(InterfaceTable *table, const std::string &ifname,
75 : const std::string &vrf_name, SubType subtype,
76 : EncapType encap, bool no_arp,
77 : const boost::uuids::uuid &device_uuid,
78 : const Ip4Address &ip,
79 : Interface::Transport transport_);
80 : static void DeleteReq(InterfaceTable *table, const std::string &ifname);
81 : static void Delete(InterfaceTable *table, const std::string &ifname);
82 : bool OnChange(PhysicalInterfaceData *data);
83 : virtual void ObtainOsSpecificParams(const std::string &name, Agent *agent);
84 : friend struct PhysicalInterfaceKey;
85 : friend struct PhysicalInterfaceOsOperStateData;
86 : friend class TestVnswIf;
87 :
88 2 : const BondChildIntfMap& getBondChildIntfMap() const {
89 2 : return bond_childIntf_map_;
90 : }
91 0 : void setBondChildIntfMap(const BondChildIntfMap bondChildIntfMap) {
92 0 : bond_childIntf_map_ = bondChildIntfMap;
93 0 : }
94 :
95 : private:
96 : std::string GetPhysicalInterfaceName() const;
97 :
98 : bool persistent_;
99 : SubType subtype_;
100 : EncapType encap_type_;
101 : bool no_arp_;
102 : PhysicalDeviceRef physical_device_;
103 : std::string display_name_;
104 : Ip4Address ip_;
105 : DISALLOW_COPY_AND_ASSIGN(PhysicalInterface);
106 : BondChildIntfMap bond_childIntf_map_;
107 : };
108 :
109 : struct PhysicalInterfaceData : public InterfaceData {
110 : PhysicalInterfaceData(Agent *agent, IFMapNode *node,
111 : const std::string &vrf_name,
112 : PhysicalInterface::SubType subtype,
113 : PhysicalInterface::EncapType encap,
114 : bool no_arp,
115 : const boost::uuids::uuid &device_uuid,
116 : const std::string &display_name,
117 : const Ip4Address &ip,
118 : Interface::Transport transport);
119 6 : virtual ~PhysicalInterfaceData() { }
120 : PhysicalInterface::SubType subtype_;
121 : PhysicalInterface::EncapType encap_type_;
122 : bool no_arp_;
123 : boost::uuids::uuid device_uuid_;
124 : std::string display_name_;
125 : Ip4Address ip_;
126 : };
127 :
128 : struct PhysicalInterfaceKey : public InterfaceKey {
129 : PhysicalInterfaceKey(const std::string &name);
130 : virtual ~PhysicalInterfaceKey();
131 :
132 : Interface *AllocEntry(const InterfaceTable *table) const;
133 : Interface *AllocEntry(const InterfaceTable *table,
134 : const InterfaceData *data) const;
135 : InterfaceKey *Clone() const;
136 : };
137 :
138 : struct PhysicalInterfaceOsOperStateData : public PhysicalInterfaceData {
139 : enum bond_intf_type {
140 : VR_FABRIC = 1,
141 : VR_BOND_SLAVES,
142 : };
143 :
144 0 : PhysicalInterfaceOsOperStateData(unsigned short int type_,
145 0 : std::string intf_name, std::string intf_drv_name, bool status):
146 : PhysicalInterfaceData(NULL, NULL, "", PhysicalInterface::INVALID,
147 0 : PhysicalInterface::ETHERNET, false, boost::uuids::nil_uuid(),
148 0 : "", Ip4Address(0), Interface::TRANSPORT_INVALID),
149 0 : type_(type_), intf_name(intf_name), intf_drv_name(intf_drv_name),
150 0 : oper_state_(status) { }
151 0 : virtual ~PhysicalInterfaceOsOperStateData() { }
152 : virtual bool OnResync(PhysicalInterface *phy_intf) const;
153 :
154 : unsigned short int type_;
155 : string intf_name;
156 : string intf_drv_name;
157 : bool oper_state_;
158 : };
159 :
160 : #endif // src_vnsw_agent_oper_physical_interface_hpp
|