2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
11 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.applyActionIns;
12 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.instructions;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
18 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
19 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.FlowMap;
20 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.Action;
21 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.AllowAction;
22 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf.SubjectFeatures;
23 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * Manage the table that assigns source endpoint group, bridge domain, and
36 * router domain to registers to be used by other tables.
38 public class ExternalMapper extends FlowTable {
40 protected static final Logger LOG = LoggerFactory.getLogger(ExternalMapper.class);
42 public static short TABLE_ID;
44 public ExternalMapper(OfContext ctx, short tableId) {
50 public short getTableId() {
55 public void sync(NodeId nodeId, PolicyInfo policyInfo, FlowMap flowMap) throws Exception {
57 if (ctx.getSwitchManager().getExternalPorts(nodeId) == null) {
58 LOG.trace("No external ports found for node: {}", nodeId);
62 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID));
64 // Drop IP traffic that doesn't match a source IP rule
65 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(2), FlowUtils.ARP, TABLE_ID));
66 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(2), FlowUtils.IPv4, TABLE_ID));
67 flowMap.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(2), FlowUtils.IPv6, TABLE_ID));
68 l3flow(flowMap,nodeId, 100, true);
69 l3flow(flowMap,nodeId, 200, false);
72 private void l3flow(FlowMap flowMap, NodeId nodeId, Integer priority, boolean arp) {
74 List<ActionBuilder> actionBuilderList = new ArrayList<ActionBuilder>();
76 Action action = SubjectFeatures.getAction(AllowAction.DEFINITION.getId());
77 actionBuilderList = action.updateAction(actionBuilderList, new HashMap<String, Object>(), 0, null);
80 Long etherType = null;
83 etherType = FlowUtils.ARP;
85 etherType = FlowUtils.IPv4;
88 Match match = new MatchBuilder().setEthernetMatch(FlowUtils.ethernetMatch(null, null, etherType))
91 FlowId flowid = FlowIdUtils.newFlowId(TABLE_ID, "ExternalMapper", match);
92 Flow flow = base().setPriority(priority)
95 .setInstructions(instructions(applyActionIns(actionBuilderList)))
98 flowMap.writeFlow(nodeId, TABLE_ID, flow);