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