Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0ee4e39
updated BUILD.md instructions
Mar 2, 2016
e94c19d
add cmakelist, getdeps
Mar 2, 2016
651775a
first version of Sai*.* files
Mar 2, 2016
dc9610d
update build.md text
Mar 2, 2016
5d2014e
added platform files
Mar 2, 2016
074b1e4
fix cmakelist.txt for SaiPlatform.cpp
Mar 2, 2016
6062195
update CMakeLists.txt for SAI in fboss/github/* dir
Mar 2, 2016
0deed53
update build instructions and steps for SAI compilation
Mar 2, 2016
2ef1f47
update CMakeLists.txt for sai compilation
Mar 2, 2016
3e53fae
reverting Cmake to only support default wedge-agent. tbd: will work …
Mar 3, 2016
b523449
revert BUILD instructions to make SAI compile , tbd: will work with …
Mar 3, 2016
5122ae6
remove Sai*Tests.* files
Mar 3, 2016
057fe3e
Update BUILD.md with SAI instructions
Mar 3, 2016
1b60687
Merge branch 'fboss-sai-93' of https://github.com/zubinshah/fboss int…
Mar 2, 2016
516638a
Fixed log message in SaiPortTable.cpp
Apr 11, 2016
26ae30b
Add resolution of Hosts, Next Hops and Routes when ARP is resolved.
Apr 11, 2016
c349130
Fixed Vlan and Route update in SaiSwitch
Apr 11, 2016
14a079f
Append trapped packet to 64 bytes.
Apr 11, 2016
f2f526f
Fixed issue with port admin mode enable/disable
Apr 11, 2016
c113044
Updated function header for removeSaiHost
Apr 11, 2016
544a123
Convert some for loops to C++11 style nad use more appropriate variab…
Apr 14, 2016
2eee581
Removed hungarian notation sprinklings
Apr 14, 2016
1caea1d
Converted FBOSS SAI adapter APIs to lower case style
Apr 14, 2016
cd43044
Merge pull request #1 from vitaliy-senchyshyn/fboss-sai-93
Jun 30, 2016
bceb906
Updated getdeps.sh for SAI needs
Jul 1, 2016
049dde0
Added default getters for service method table
Jul 4, 2016
f61f5d5
Merge pull request #2 from vitaliy-senchyshyn/fboss-sai-93
Jul 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ If you want to build them manually, the dependencies are as follows:
* iproute2-3.19.0: download from
[here](https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-3.19.0.tar.xz)
* Broadcom's [OpenNSL](https://github.com/Broadcom-Switch/OpenNSL)
* [OCP-SAI](https://github.com/opencomputeproject/SAI.git), download only.

Once the prerequisites are available, take the following steps.

Expand All @@ -26,7 +27,11 @@ git clone https://github.com/facebook/fboss.git

If you installed dependencies manually, CMAKE_INCLUDE_PATH and
CMAKE_LIBRARY_PATH must be modified to include the paths to the dependencies.
If you use `getdeps.sh`, then this should work out of the box.
If you use `getdeps.sh`, then this should work out of the box.

If you build with SAI there are two additional steps: (1) copy and rename the
SAI adapter library as external/SAI/lib/libSaiAdapter.so (2) copy and rename
./fboss/github/CMakeLists_SAI.txt as ./CMakeLists_SAI.txt.

Build as follows:

Expand All @@ -36,5 +41,4 @@ cd fboss/build
cmake ..
make
```

The produced executables are `sim_agent` and `wedge_agent` in the build directory.
The produced executables are `sim_agent` and `wedge_agent` (or `sai_agent`) in the build directory.
18 changes: 18 additions & 0 deletions fboss/agent/hw/sai/SaiError.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* Copyright (c) 2016, Cavium, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "SaiError.h"

#include <stdlib.h>
#include <sstream>

namespace facebook { namespace fboss {

}} // facebook::fboss
37 changes: 37 additions & 0 deletions fboss/agent/hw/sai/SaiError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* Copyright (c) 2016, Cavium, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once

#include "fboss/agent/FbossError.h"

namespace facebook { namespace fboss {

class SaiError : public FbossError {
public:
template<typename... Args>
explicit SaiError(Args&&... args)
: FbossError("SAI-agent: ", std::forward<Args>(args)...){
}

~SaiError() throw() {}
};

class SaiFatal : public FbossError {
public:
template<typename... Args>
explicit SaiFatal(Args&&... args)
: FbossError("SAI-agent: ", std::forward<Args>(args)...){
}

~SaiFatal() throw() {}
};

}} // facebook::fboss
143 changes: 143 additions & 0 deletions fboss/agent/hw/sai/SaiHost.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* Copyright (c) 2016, Cavium, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include "SaiHost.h"
#include "SaiVrfTable.h"
#include "SaiVrf.h"
#include "SaiIntfTable.h"
#include "SaiIntf.h"
#include "SaiSwitch.h"
#include "SaiError.h"

using folly::IPAddress;
using folly::MacAddress;

namespace facebook { namespace fboss {

SaiHost::SaiHost(const SaiSwitch *hw, InterfaceID intf,
const IPAddress &ip, const folly::MacAddress &mac)
: hw_(hw)
, intf_(intf)
, ip_(ip)
, mac_(mac) {

VLOG(4) << "Entering " << __FUNCTION__;

saiNeighborApi_ = hw_->getSaiNeighborApi();
}

SaiHost::~SaiHost() {
VLOG(4) << "Entering " << __FUNCTION__;

if (!added_) {
return;
}

saiNeighborApi_->remove_neighbor_entry(&neighborEntry_);
VLOG(3) << "Deleted L3 host object for " << ip_;
}

void SaiHost::program(sai_packet_action_t action, const folly::MacAddress &mac) {
VLOG(4) << "Entering " << __FUNCTION__;

if (!added_) {

if (ip_.empty() || ip_.isZero()) {
throw SaiError("Wrong IP address ", ip_, " specified");
}

// fill neighborEntry_
neighborEntry_.rif_id = hw_->getIntfTable()->getIntf(intf_)->getIfId();

if (ip_.isV4()) {
// IPv4
neighborEntry_.ip_address.addr_family = SAI_IP_ADDR_FAMILY_IPV4;

memcpy(&neighborEntry_.ip_address.addr.ip4, ip_.bytes(),
sizeof(neighborEntry_.ip_address.addr.ip4));
} else {
// IPv6
neighborEntry_.ip_address.addr_family = SAI_IP_ADDR_FAMILY_IPV6;

memcpy(neighborEntry_.ip_address.addr.ip6, ip_.bytes(),
sizeof(neighborEntry_.ip_address.addr.ip6));
}

// fill neighbor attributes
std::vector<sai_attribute_t> attrList;
sai_attribute_t attr {0};

// MAC
attr.id = SAI_NEIGHBOR_ATTR_DST_MAC_ADDRESS;
memcpy(attr.value.mac, mac_.bytes(), sizeof(attr.value.mac));
attrList.push_back(attr);

// packet action
attr.id = SAI_NEIGHBOR_ATTR_PACKET_ACTION;
attr.value.u32 = action;
attrList.push_back(attr);

// create neighbor
sai_status_t saiRetVal = saiNeighborApi_->create_neighbor_entry(&neighborEntry_,
attrList.size(),
attrList.data());
if (saiRetVal != SAI_STATUS_SUCCESS) {
throw SaiError("Could not create SAI neighbor with IP addr: ", ip_,
" MAC: ", mac_, " router interface ID: ", intf_,
" Error: ", saiRetVal);
}

added_ = true;
action_ = action;

return;
}

if (mac != mac_) {
// fill neighbor MAC attribute
sai_attribute_t macAttr {0};
macAttr.id = SAI_NEIGHBOR_ATTR_DST_MAC_ADDRESS;
memcpy(macAttr.value.mac, mac.bytes(), sizeof(macAttr.value.mac));

// set action attribute
sai_status_t saiRetVal = saiNeighborApi_->set_neighbor_attribute(&neighborEntry_,
&macAttr);
if (saiRetVal != SAI_STATUS_SUCCESS) {
throw SaiError("Could not set MAC: ", mac,
"to SAI neighbor with IP addr: ", ip_,
" router interface ID: ", intf_,
" Error: ", saiRetVal);
}

mac_ = mac;
}

if (action != action_) {

// fill neighbor packet action attribute
sai_attribute_t actionAttr {0};
actionAttr.id = SAI_NEIGHBOR_ATTR_PACKET_ACTION;
actionAttr.value.u32 = action;

// set action attribute
sai_status_t saiRetVal = saiNeighborApi_->set_neighbor_attribute(&neighborEntry_,
&actionAttr);
if (saiRetVal != SAI_STATUS_SUCCESS) {
throw SaiError("Could not set packet action attribute: ", action,
" to SAI neighbor with IP addr: ", ip_,
" MAC: ", mac_, " router interface ID: ", intf_,
" Error: ", saiRetVal);
}

action_ = action;
}
}

}} // facebook::fboss
83 changes: 83 additions & 0 deletions fboss/agent/hw/sai/SaiHost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2004-present, Facebook, Inc.
* Copyright (c) 2016, Cavium, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once

#include <folly/IPAddress.h>
#include <folly/MacAddress.h>

#include "fboss/agent/types.h"

extern "C" {
#include "saitypes.h"
#include "saineighbor.h"
#include "saiswitch.h"
}

namespace facebook { namespace fboss {

class SaiSwitch;

class SaiHost {
public:
/**
* Constructs the SaiHost object.
*
* This method doesn't make any calls to the SAI to program host there.
* program() will be called soon after construction, and any
* actual initialization logic will be performed there.
*/
SaiHost(const SaiSwitch *hw,
InterfaceID intf,
const folly::IPAddress &ip,
const folly::MacAddress &mac);
/**
* Destructs the SaiHost object.
*
* This method removes the host from the HW as well.
*/
virtual ~SaiHost();

/**
* Gets Sai Host action.
*
* @return Host action of sai_packet_action_t type.
*/
sai_packet_action_t getSaiAction() const {
return action_;
}

/**
* Programs host in HW and stores sai_neighbor_entry_t instance
* which holds SAI host data needed.
*
* If one of SAI HW calls fails it throws an exception;
*
* @return none
*/
void program(sai_packet_action_t action, const folly::MacAddress &mac);

private:
// no copy or assignment
SaiHost(SaiHost const &) = delete;
SaiHost &operator=(SaiHost const &) = delete;

const SaiSwitch *hw_;
const InterfaceID intf_;
const folly::IPAddress ip_;
folly::MacAddress mac_;
sai_packet_action_t action_ {SAI_PACKET_ACTION_DROP};
bool added_ {false}; // if added to the HW host table or not

sai_neighbor_entry_t neighborEntry_;
sai_neighbor_api_t *saiNeighborApi_ { nullptr };
};

}} // facebook::fboss
Loading