Java源码示例:org.onosproject.net.pi.model.PiMatchFieldId
示例1
/**
* Creates a routing flow rule that matches on the given IPv6 prefix and
* executes the given group ID (created before).
*
* @param deviceId the device where flow rule will be installed
* @param ip6Prefix the IPv6 prefix
* @param groupId the group ID
* @return a flow rule
*/
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
int groupId) {
final String tableId = "IngressPipeImpl.routing_v6_table";
final PiCriterion match = PiCriterion.builder()
.matchLpm(
PiMatchFieldId.of("hdr.ipv6.dst_addr"),
ip6Prefix.address().toOctets(),
ip6Prefix.prefixLength())
.build();
final PiTableAction action = PiActionProfileGroupId.of(groupId);
return Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
}
示例2
/**
* Creates a flow rule for the L2 table mapping the given next hop MAC to
* the given output port.
* <p>
* This is called by the routing policy methods below to establish L2-based
* forwarding inside the fabric, e.g., when deviceId is a leaf switch and
* nextHopMac is the one of a spine switch.
*
* @param deviceId the device
* @param nexthopMac the next hop (destination) mac
* @param outPort the output port
*/
private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac,
PortNumber outPort) {
final String tableId = "IngressPipeImpl.l2_exact_table";
final PiCriterion match = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"),
nexthopMac.toBytes())
.build();
final PiAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.set_egress_port"))
.withParameter(new PiActionParam(
PiActionParamId.of("port_num"),
outPort.toLong()))
.build();
return Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
}
示例3
/**
* Creates a routing flow rule that matches on the given IPv6 prefix and
* executes the given group ID (created before).
*
* @param deviceId the device where flow rule will be installed
* @param ip6Prefix the IPv6 prefix
* @param groupId the group ID
* @return a flow rule
*/
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
int groupId) {
// TODO EXERCISE 3
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "IngressPipeImpl.l3_table";
final PiCriterion match = PiCriterion.builder()
.matchLpm(
PiMatchFieldId.of("hdr.ipv6.dst_addr"),
ip6Prefix.address().toOctets(),
ip6Prefix.prefixLength())
.build();
final PiTableAction action = PiActionProfileGroupId.of(groupId);
// ---- END SOLUTION ----
return Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
}
示例4
/**
* Creates a flow rule for the L2 table mapping the given next hop MAC to
* the given output port.
* <p>
* This is called by the routing policy methods below to establish L2-based
* forwarding inside the fabric, e.g., when deviceId is a leaf switch and
* nextHopMac is the one of a spine switch.
*
* @param deviceId the device
* @param nexthopMac the next hop (destination) mac
* @param outPort the output port
*/
private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac,
PortNumber outPort) {
// TODO EXERCISE 3
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "IngressPipeImpl.l2_exact_table";
final PiCriterion match = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"),
nexthopMac.toBytes())
.build();
final PiAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.set_output_port"))
.withParameter(new PiActionParam(
PiActionParamId.of("port_num"),
outPort.toLong()))
.build();
// ---- END SOLUTION ----
return Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
}
示例5
/**
* Creates a routing flow rule that matches on the given IPv6 prefix and
* executes the given group ID (created before).
*
* @param deviceId the device where flow rule will be installed
* @param ip6Prefix the IPv6 prefix
* @param groupId the group ID
* @return a flow rule
*/
private FlowRule createRoutingRule(DeviceId deviceId, Ip6Prefix ip6Prefix,
int groupId) {
// TODO EXERCISE 3
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "MODIFY ME";
final PiCriterion match = PiCriterion.builder()
.matchLpm(
PiMatchFieldId.of("MODIFY ME"),
ip6Prefix.address().toOctets(),
ip6Prefix.prefixLength())
.build();
final PiTableAction action = PiActionProfileGroupId.of(groupId);
// ---- END SOLUTION ----
return Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
}
示例6
/**
* Creates a flow rule for the L2 table mapping the given next hop MAC to
* the given output port.
* <p>
* This is called by the routing policy methods below to establish L2-based
* forwarding inside the fabric, e.g., when deviceId is a leaf switch and
* nextHopMac is the one of a spine switch.
*
* @param deviceId the device
* @param nexthopMac the next hop (destination) mac
* @param outPort the output port
*/
private FlowRule createL2NextHopRule(DeviceId deviceId, MacAddress nexthopMac,
PortNumber outPort) {
// TODO EXERCISE 3
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "MODIFY ME";
final PiCriterion match = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("MODIFY ME"),
nexthopMac.toBytes())
.build();
final PiAction action = PiAction.builder()
.withId(PiActionId.of("MODIFY ME"))
.withParameter(new PiActionParam(
PiActionParamId.of("MODIFY ME"),
outPort.toLong()))
.build();
// ---- END SOLUTION ----
return Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
}
示例7
P4TableModel(PiTableId id, PiTableType tableType,
PiActionProfileModel actionProfile, long maxSize,
ImmutableMap<PiCounterId, PiCounterModel> counters,
ImmutableMap<PiMeterId, PiMeterModel> meters, boolean supportAging,
ImmutableMap<PiMatchFieldId, PiMatchFieldModel> matchFields,
ImmutableMap<PiActionId, PiActionModel> actions,
PiActionModel constDefaultAction,
boolean isConstTable) {
this.id = id;
this.tableType = tableType;
this.actionProfile = actionProfile;
this.maxSize = maxSize;
this.counters = counters;
this.meters = meters;
this.supportAging = supportAging;
this.matchFields = matchFields;
this.actions = actions;
this.constDefaultAction = constDefaultAction;
this.isConstTable = isConstTable;
}
示例8
/**
* Build a flow rule for the NDP reply table on the given device, for the
* given target IPv6 address and MAC address.
*
* @param deviceId device ID where to install the flow rules
* @param targetIpv6Address target IPv6 address
* @param targetMac target MAC address
* @return flow rule object
*/
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId,
Ip6Address targetIpv6Address,
MacAddress targetMac) {
// ** TODO EXERCISE 4
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
// Build match.
final PiCriterion match = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ndp.target_ipv6_addr"), targetIpv6Address.toOctets())
.build();
// Build action.
final PiActionParam targetMacParam = new PiActionParam(
PiActionParamId.of("target_mac"), targetMac.toBytes());
final PiAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na"))
.withParameter(targetMacParam)
.build();
// Table ID.
final String tableId = "IngressPipeImpl.ndp_reply_table";
// ---- END SOLUTION ----
// Build flow rule.
final FlowRule rule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
return rule;
}
示例9
@Override
public Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type) {
if (CRITERION_MAP.containsKey(type)) {
return Optional.of(PiMatchFieldId.of(CRITERION_MAP.get(type)));
} else {
return Optional.empty();
}
}
示例10
@Override
public Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type) {
if (CRITERION_MAP.containsKey(type)) {
return Optional.of(PiMatchFieldId.of(CRITERION_MAP.get(type)));
} else {
return Optional.empty();
}
}
示例11
/**
* Build a flow rule for the NDP reply table on the given device, for the
* given target IPv6 address and MAC address.
*
* @param deviceId device ID where to install the flow rules
* @param targetIpv6Address target IPv6 address
* @param targetMac target MAC address
* @return flow rule object
*/
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId,
Ip6Address targetIpv6Address,
MacAddress targetMac) {
// ** TODO EXERCISE 4
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
// Build match.
final PiCriterion match = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ndp.target_ipv6_addr"), targetIpv6Address.toOctets())
.build();
// Build action.
final PiActionParam targetMacParam = new PiActionParam(
PiActionParamId.of("target_mac"), targetMac.toBytes());
final PiAction action = PiAction.builder()
.withId(PiActionId.of("<PUT HERE NAME OF NDP REPLY ACTION>"))
.withParameter(targetMacParam)
.build();
// Table ID.
final String tableId = "<PUT HERE NAME OF NDP REPLY TABLE>";
// ---- END SOLUTION ----
// Build flow rule.
final FlowRule rule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
return rule;
}
示例12
/**
* Insert flow rules to forward packets to a given host located at the given
* device and port.
* <p>
* This method will be called at component activation for each host known by
* ONOS, and every time a new host-added event is captured by the
* InternalHostListener defined below.
*
* @param host host instance
* @param deviceId device where the host is located
* @param port port where the host is attached to
*/
private void learnHost(Host host, DeviceId deviceId, PortNumber port) {
log.info("Adding L2 unicast rule on {} for host {} (port {})...",
deviceId, host.id(), port);
final String tableId = "IngressPipeImpl.l2_exact_table";
// Match exactly on the host MAC address.
final MacAddress hostMac = host.mac();
final PiCriterion hostMacCriterion = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"),
hostMac.toBytes())
.build();
// Action: set output port
final PiAction l2UnicastAction = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.set_egress_port"))
.withParameter(new PiActionParam(
PiActionParamId.of("port_num"),
port.toLong()))
.build();
// Forge flow rule.
final FlowRule rule = Utils.buildFlowRule(
deviceId, appId, tableId, hostMacCriterion, l2UnicastAction);
// Insert.
flowRuleService.applyFlowRules(rule);
}
示例13
/**
* Sets up the "My Station" table for the given device using the
* myStationMac address found in the config.
* <p>
* This method will be called at component activation for each device
* (switch) known by ONOS, and every time a new device-added event is
* captured by the InternalDeviceListener defined below.
*
* @param deviceId the device ID
*/
private void setUpMyStationTable(DeviceId deviceId) {
log.info("Adding My Station rules to {}...", deviceId);
final MacAddress myStationMac = getMyStationMac(deviceId);
// HINT: in the p4 program, the My Station table matches on the
// *ethernet destination* and there is only one action called
// *NoAction*, which is used as an indication of "table hit" in the
// control block.
final String tableId = "IngressPipeImpl.my_station_table";
final PiCriterion match = PiCriterion.builder()
.matchExact(
PiMatchFieldId.of("hdr.ethernet.dst_addr"),
myStationMac.toBytes())
.build();
// Creates an action which do *NoAction* when hit.
final PiTableAction action = PiAction.builder()
.withId(PiActionId.of("NoAction"))
.build();
final FlowRule myStationRule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
flowRuleService.applyFlowRules(myStationRule);
}
示例14
@Override
public Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type) {
if (CRITERION_MAP.containsKey(type)) {
return Optional.of(PiMatchFieldId.of(CRITERION_MAP.get(type)));
} else {
return Optional.empty();
}
}
示例15
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId,
MacAddress deviceMac,
Ip6Address targetIp) {
PiCriterion match = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ndp.target_addr"), targetIp.toOctets())
.build();
PiActionParam paramRouterMac = new PiActionParam(
PiActionParamId.of("target_mac"), deviceMac.toBytes());
PiAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na"))
.withParameter(paramRouterMac)
.build();
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchPi(match)
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.piTableAction(action)
.build();
return DefaultFlowRule.builder()
.forDevice(deviceId)
.forTable(PiTableId.of("IngressPipeImpl.ndp_reply_table"))
.fromApp(appId)
.makePermanent()
.withSelector(selector)
.withTreatment(treatment)
.withPriority(DEFAULT_FLOW_RULE_PRIORITY)
.build();
}
示例16
/**
* Insert flow rules to forward packets to a given host located at the given
* device and port.
* <p>
* This method will be called at component activation for each host known by
* ONOS, and every time a new host-added event is captured by the
* InternalHostListener defined below.
*
* @param host host instance
* @param deviceId device where the host is located
* @param port port where the host is attached to
*/
private void learnHost(Host host, DeviceId deviceId, PortNumber port) {
log.info("Adding L2 unicast rule on {} for host {} (port {})...",
deviceId, host.id(), port);
// TODO EXERCISE 2
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "IngressPipeImpl.l2_exact_table";
// Match exactly on the host MAC address.
final MacAddress hostMac = host.mac();
final PiCriterion hostMacCriterion = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ethernet.dst_addr"),
hostMac.toBytes())
.build();
// Action: set output port
final PiAction l2UnicastAction = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.set_output_port"))
.withParameter(new PiActionParam(
PiActionParamId.of("port_num"),
port.toLong()))
.build();
// Forge flow rule.
final FlowRule rule = Utils.buildFlowRule(
deviceId, appId, tableId, hostMacCriterion, l2UnicastAction);
// ---- END SOLUTION ----
// Insert.
flowRuleService.applyFlowRules(rule);
}
示例17
/**
* Sets up the "My Station" table for the given device using the
* myStationMac address found in the config.
* <p>
* This method will be called at component activation for each device
* (switch) known by ONOS, and every time a new device-added event is
* captured by the InternalDeviceListener defined below.
*
* @param deviceId the device ID
*/
private void setUpMyStationTable(DeviceId deviceId) {
log.info("Adding My Station rules to {}...", deviceId);
final MacAddress myStationMac = getMyStationMac(deviceId);
// HINT: in our solution, the My Station table matches on the *ethernet
// destination* and there is only one action called *NoAction*, which is
// used as an indication of "table hit" in the control block.
// TODO EXERCISE 3
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "IngressPipeImpl.l2_my_station";
final PiCriterion match = PiCriterion.builder()
.matchExact(
PiMatchFieldId.of("hdr.ethernet.dst_addr"),
myStationMac.toBytes())
.build();
// Creates an action which do *NoAction* when hit.
final PiTableAction action = PiAction.builder()
.withId(PiActionId.of("NoAction"))
.build();
// ---- END SOLUTION ----
final FlowRule myStationRule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
flowRuleService.applyFlowRules(myStationRule);
}
示例18
/**
* Populate the My SID table from the network configuration for the
* specified device.
*
* @param deviceId the device Id
*/
private void setUpMySidTable(DeviceId deviceId) {
Ip6Address mySid = getMySid(deviceId);
log.info("Adding mySid rule on {} (sid {})...", deviceId, mySid);
// TODO EXERCISE 4
// Fill in the table ID for the SRv6 my segment identifier table
// ---- START SOLUTION ----
String tableId = "IngressPipeImpl.srv6_my_sid";
// ---- END SOLUTION ----
// TODO EXERCISE 4
// Modify the field and action id to match your P4Info
// ---- START SOLUTION ----
PiCriterion match = PiCriterion.builder()
.matchLpm(
PiMatchFieldId.of("hdr.ipv6.dst_addr"),
mySid.toOctets(), 128)
.build();
PiTableAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.srv6_end"))
.build();
// ---- END SOLUTION ----
FlowRule myStationRule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
flowRuleService.applyFlowRules(myStationRule);
}
示例19
/**
* Insert a SRv6 transit insert policy that will inject an SRv6 header for
* packets destined to destIp.
*
* @param deviceId device ID
* @param destIp target IP address for the SRv6 policy
* @param prefixLength prefix length for the target IP
* @param segmentList list of SRv6 SIDs that make up the path
*/
public void insertSrv6InsertRule(DeviceId deviceId, Ip6Address destIp, int prefixLength,
List<Ip6Address> segmentList) {
if (segmentList.size() < 2 || segmentList.size() > 3) {
throw new RuntimeException("List of " + segmentList.size() + " segments is not supported");
}
// TODO EXERCISE 4
// Fill in the table ID for the SRv6 transit table.
// ---- START SOLUTION ----
String tableId = "IngressPipeImpl.srv6_transit";
// ---- END SOLUTION ----
// TODO EXERCISE 4
// Modify match field, action id, and action parameter to match your P4Info.
// ---- START SOLUTION ----
PiCriterion match = PiCriterion.builder()
.matchLpm(PiMatchFieldId.of("hdr.ipv6.dst_addr"), destIp.toOctets(), prefixLength)
.build();
List<PiActionParam> actionParams = Lists.newArrayList();
for (int i = 0; i < segmentList.size(); i++) {
PiActionParamId paramId = PiActionParamId.of("s" + (i + 1));
PiActionParam param = new PiActionParam(paramId, segmentList.get(i).toOctets());
actionParams.add(param);
}
PiAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.srv6_t_insert_" + segmentList.size()))
.withParameters(actionParams)
.build();
// ---- END SOLUTION ----
final FlowRule rule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
flowRuleService.applyFlowRules(rule);
}
示例20
@Override
public Optional<PiMatchFieldId> mapCriterionType(Criterion.Type type) {
if (CRITERION_MAP.containsKey(type)) {
return Optional.of(PiMatchFieldId.of(CRITERION_MAP.get(type)));
} else {
return Optional.empty();
}
}
示例21
private FlowRule buildNdpReplyFlowRule(DeviceId deviceId,
MacAddress deviceMac,
Ip6Address targetIp) {
PiCriterion match = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("hdr.ndp.target_addr"), targetIp.toOctets())
.build();
PiActionParam paramRouterMac = new PiActionParam(
PiActionParamId.of("target_mac"), deviceMac.toBytes());
PiAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.ndp_ns_to_na"))
.withParameter(paramRouterMac)
.build();
TrafficSelector selector = DefaultTrafficSelector.builder()
.matchPi(match)
.build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.piTableAction(action)
.build();
return DefaultFlowRule.builder()
.forDevice(deviceId)
.forTable(PiTableId.of("IngressPipeImpl.ndp_reply_table"))
.fromApp(appId)
.makePermanent()
.withSelector(selector)
.withTreatment(treatment)
.withPriority(DEFAULT_FLOW_RULE_PRIORITY)
.build();
}
示例22
/**
* Insert flow rules to forward packets to a given host located at the given
* device and port.
* <p>
* This method will be called at component activation for each host known by
* ONOS, and every time a new host-added event is captured by the
* InternalHostListener defined below.
*
* @param host host instance
* @param deviceId device where the host is located
* @param port port where the host is attached to
*/
private void learnHost(Host host, DeviceId deviceId, PortNumber port) {
log.info("Adding L2 unicast rule on {} for host {} (port {})...",
deviceId, host.id(), port);
// TODO EXERCISE 2
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "MODIFY ME";
// Match exactly on the host MAC address.
final MacAddress hostMac = host.mac();
final PiCriterion hostMacCriterion = PiCriterion.builder()
.matchExact(PiMatchFieldId.of("MODIFY ME"),
hostMac.toBytes())
.build();
// Action: set output port
final PiAction l2UnicastAction = PiAction.builder()
.withId(PiActionId.of("MODIFY ME"))
.withParameter(new PiActionParam(
PiActionParamId.of("MODIFY ME"),
port.toLong()))
.build();
// ---- END SOLUTION ----
// Forge flow rule.
final FlowRule rule = Utils.buildFlowRule(
deviceId, appId, tableId, hostMacCriterion, l2UnicastAction);
// Insert.
flowRuleService.applyFlowRules(rule);
}
示例23
/**
* Sets up the "My Station" table for the given device using the
* myStationMac address found in the config.
* <p>
* This method will be called at component activation for each device
* (switch) known by ONOS, and every time a new device-added event is
* captured by the InternalDeviceListener defined below.
*
* @param deviceId the device ID
*/
private void setUpMyStationTable(DeviceId deviceId) {
log.info("Adding My Station rules to {}...", deviceId);
final MacAddress myStationMac = getMyStationMac(deviceId);
// HINT: in our solution, the My Station table matches on the *ethernet
// destination* and there is only one action called *NoAction*, which is
// used as an indication of "table hit" in the control block.
// TODO EXERCISE 3
// Modify P4Runtime entity names to match content of P4Info file (look
// for the fully qualified name of tables, match fields, and actions.
// ---- START SOLUTION ----
final String tableId = "MODIFY ME";
final PiCriterion match = PiCriterion.builder()
.matchExact(
PiMatchFieldId.of("MODIFY ME"),
myStationMac.toBytes())
.build();
// Creates an action which do *NoAction* when hit.
final PiTableAction action = PiAction.builder()
.withId(PiActionId.of("MODIFY ME"))
.build();
// ---- END SOLUTION ----
final FlowRule myStationRule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
flowRuleService.applyFlowRules(myStationRule);
}
示例24
/**
* Populate the My SID table from the network configuration for the
* specified device.
*
* @param deviceId the device Id
*/
private void setUpMySidTable(DeviceId deviceId) {
Ip6Address mySid = getMySid(deviceId);
log.info("Adding mySid rule on {} (sid {})...", deviceId, mySid);
// TODO EXERCISE 4
// Fill in the table ID for the SRv6 my segment identifier table
// ---- START SOLUTION ----
String tableId = "MODIFY ME";
// ---- END SOLUTION ----
// TODO EXERCISE 4
// Modify the field and action id to match your P4Info
// ---- START SOLUTION ----
PiCriterion match = PiCriterion.builder()
.matchLpm(
PiMatchFieldId.of("MODIFY ME"),
mySid.toOctets(), 128)
.build();
PiTableAction action = PiAction.builder()
.withId(PiActionId.of("MODIFY ME"))
.build();
// ---- END SOLUTION ----
FlowRule myStationRule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
flowRuleService.applyFlowRules(myStationRule);
}
示例25
/**
* Insert a SRv6 transit insert policy that will inject an SRv6 header for
* packets destined to destIp.
*
* @param deviceId device ID
* @param destIp target IP address for the SRv6 policy
* @param prefixLength prefix length for the target IP
* @param segmentList list of SRv6 SIDs that make up the path
*/
public void insertSrv6InsertRule(DeviceId deviceId, Ip6Address destIp, int prefixLength,
List<Ip6Address> segmentList) {
if (segmentList.size() < 2 || segmentList.size() > 3) {
throw new RuntimeException("List of " + segmentList.size() + " segments is not supported");
}
// TODO EXERCISE 4
// Fill in the table ID for the SRv6 transit table.
// ---- START SOLUTION ----
String tableId = "MODIFY ME";
// ---- END SOLUTION ----
// TODO EXERCISE 4
// Modify match field, action id, and action parameters to match your P4Info.
// ---- START SOLUTION ----
PiCriterion match = PiCriterion.builder()
.matchLpm(PiMatchFieldId.of("MODIFY ME"), destIp.toOctets(), prefixLength)
.build();
List<PiActionParam> actionParams = Lists.newArrayList();
for (int i = 0; i < segmentList.size(); i++) {
PiActionParamId paramId = PiActionParamId.of("s" + (i + 1));
PiActionParam param = new PiActionParam(paramId, segmentList.get(i).toOctets());
actionParams.add(param);
}
PiAction action = PiAction.builder()
.withId(PiActionId.of("IngressPipeImpl.srv6_t_insert_" + segmentList.size()))
.withParameters(actionParams)
.build();
// ---- END SOLUTION ----
final FlowRule rule = Utils.buildFlowRule(
deviceId, appId, tableId, match, action);
flowRuleService.applyFlowRules(rule);
}
示例26
@Override
public PiFieldMatch decode(
P4RuntimeOuterClass.FieldMatch message, P4InfoOuterClass.Preamble tablePreamble,
PiPipeconf pipeconf, P4InfoBrowser browser)
throws CodecException, P4InfoBrowser.NotFoundException {
String fieldMatchName = browser.matchFields(tablePreamble.getId())
.getById(message.getFieldId()).getName();
PiMatchFieldId headerFieldId = PiMatchFieldId.of(fieldMatchName);
P4RuntimeOuterClass.FieldMatch.FieldMatchTypeCase typeCase = message.getFieldMatchTypeCase();
switch (typeCase) {
case EXACT:
P4RuntimeOuterClass.FieldMatch.Exact exactFieldMatch = message.getExact();
ImmutableByteSequence exactValue = copyFrom(exactFieldMatch.getValue().asReadOnlyByteBuffer());
return new PiExactFieldMatch(headerFieldId, exactValue);
case TERNARY:
P4RuntimeOuterClass.FieldMatch.Ternary ternaryFieldMatch = message.getTernary();
ImmutableByteSequence ternaryValue = copyFrom(ternaryFieldMatch.getValue().asReadOnlyByteBuffer());
ImmutableByteSequence ternaryMask = copyFrom(ternaryFieldMatch.getMask().asReadOnlyByteBuffer());
return new PiTernaryFieldMatch(headerFieldId, ternaryValue, ternaryMask);
case LPM:
P4RuntimeOuterClass.FieldMatch.LPM lpmFieldMatch = message.getLpm();
ImmutableByteSequence lpmValue = copyFrom(lpmFieldMatch.getValue().asReadOnlyByteBuffer());
int lpmPrefixLen = lpmFieldMatch.getPrefixLen();
return new PiLpmFieldMatch(headerFieldId, lpmValue, lpmPrefixLen);
case RANGE:
P4RuntimeOuterClass.FieldMatch.Range rangeFieldMatch = message.getRange();
ImmutableByteSequence rangeHighValue = copyFrom(rangeFieldMatch.getHigh().asReadOnlyByteBuffer());
ImmutableByteSequence rangeLowValue = copyFrom(rangeFieldMatch.getLow().asReadOnlyByteBuffer());
return new PiRangeFieldMatch(headerFieldId, rangeLowValue, rangeHighValue);
default:
throw new CodecException(format(
"Decoding of field match type '%s' not implemented", typeCase.name()));
}
}
示例27
private void populateInstTableEntry(PiTableId tableId, PiMatchFieldId matchFieldId,
int matchValue, PiActionId actionId, ApplicationId appId) {
PiCriterion instCriterion = PiCriterion.builder()
.matchExact(matchFieldId, matchValue)
.build();
TrafficSelector instSelector = DefaultTrafficSelector.builder()
.matchPi(instCriterion)
.build();
PiAction instAction = PiAction.builder()
.withId(actionId)
.build();
TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
.piTableAction(instAction)
.build();
FlowRule instFlowRule = DefaultFlowRule.builder()
.withSelector(instSelector)
.withTreatment(instTreatment)
.withPriority(DEFAULT_PRIORITY)
.makePermanent()
.forDevice(deviceId)
.forTable(tableId)
.fromApp(appId)
.build();
flowRuleService.applyFlowRules(instFlowRule);
}
示例28
/**
* Generates and insert a flow rule to perform the tunnel INGRESS function
* for the given switch, destination IP address and tunnel ID.
*
* @param switchId switch ID
* @param dstIpAddr IP address to forward inside the tunnel
* @param tunId tunnel ID
*/
private void insertTunnelIngressRule(DeviceId switchId,
IpAddress dstIpAddr,
int tunId) {
PiTableId tunnelIngressTableId = PiTableId.of("c_ingress.t_tunnel_ingress");
// Longest prefix match on IPv4 dest address.
PiMatchFieldId ipDestMatchFieldId = PiMatchFieldId.of("hdr.ipv4.dst_addr");
PiCriterion match = PiCriterion.builder()
.matchLpm(ipDestMatchFieldId, dstIpAddr.toOctets(), 32)
.build();
PiActionParam tunIdParam = new PiActionParam(PiActionParamId.of("tun_id"), tunId);
PiActionId ingressActionId = PiActionId.of("c_ingress.my_tunnel_ingress");
PiAction action = PiAction.builder()
.withId(ingressActionId)
.withParameter(tunIdParam)
.build();
log.info("Inserting INGRESS rule on switch {}: table={}, match={}, action={}",
switchId, tunnelIngressTableId, match, action);
insertPiFlowRule(switchId, tunnelIngressTableId, match, action);
}
示例29
/**
* Creates a new LPM field match.
*
* @param fieldId field identifier
* @param value value
* @param prefixLength prefix length
*/
public PiLpmFieldMatch(PiMatchFieldId fieldId, ImmutableByteSequence value, int prefixLength) {
super(fieldId);
this.value = checkNotNull(value);
this.prefixLength = prefixLength;
checkArgument(value.size() > 0, "Value must have non-zero size");
checkArgument(prefixLength >= 0, "Prefix length must be a non-negative integer");
}
示例30
/**
* Creates a new range field match for the given low and high value.
*
* @param fieldId field identifier
* @param lowValue low value
* @param highValue high value
*/
public PiRangeFieldMatch(PiMatchFieldId fieldId, ImmutableByteSequence lowValue,
ImmutableByteSequence highValue) {
super(fieldId);
this.lowValue = checkNotNull(lowValue);
this.highValue = checkNotNull(highValue);
checkArgument(lowValue.size() == highValue.size() && lowValue.size() > 0,
"Low and high values must have the same non-zero size.");
}