+
+ private Interface getInterfaceByIfName(String ifName) {
+ InstanceIdentifier<Interface> id = buildId(ifName);
+ Optional<Interface> port = read(LogicalDatastoreType.CONFIGURATION, id);
+ if(port.isPresent()) {
+ return port.get();
+ }
+ return null;
+ }
+
+ Long getPortForInterface(String ifName) {
+ Interface iface = getInterfaceByIfName(ifName);
+ return getPortNumForInterface(iface);
+ }
+
+ long getDpnForInterface(String ifName) {
+ Interface iface = getInterfaceByIfName(ifName);
+ try {
+ NodeConnector port = getNodeConnectorFromDataStore(iface);
+ //TODO: This should be an MDSAL Util method
+ return Long.parseLong(IfmUtil.getDpnFromNodeConnectorId(port.getId()));
+ } catch (NullPointerException e) {
+ LOG.error("OFPort for Interface {} not found", ifName);
+ }
+ return 0L;
+ }
+
+ String getEndpointIpForDpn(long dpnId) {
+ //TODO: This should be MDSAL Util function
+ NodeId dpnNodeId = IfmUtil.buildDpnNodeId(dpnId);
+ return dbDpnEndpoints.get(dpnNodeId);
+ }
+
+ List<MatchInfo> getInterfaceIngressRule(String ifName) {
+ Interface iface = getInterfaceByIfName(ifName);
+ List<MatchInfo> matches = new ArrayList<MatchInfo>();
+ Class<? extends InterfaceType> ifType = iface.getType();
+ long dpn = this.getDpnForInterface(ifName);
+ long portNo = this.getPortNumForInterface(iface).longValue();
+ matches.add(new MatchInfo(MatchFieldType.in_port, new long[] {dpn, portNo}));
+
+ if (ifType.isInstance(L2vlan.class)) {
+ IfL2vlan vlanIface = iface.getAugmentation(IfL2vlan.class);
+ long vlanVid = vlanIface.getVlanId().longValue();
+ if (vlanVid != 0) {
+ matches.add(new MatchInfo(MatchFieldType.vlan_vid,
+ new long[] {vlanVid}));
+ LOG.trace("L2Vlan: {}",vlanIface);
+ }
+ } else if (ifType.isInstance(L3tunnel.class)) {
+ //TODO: Handle different tunnel types
+ IfL3tunnel ifL3Tunnel = iface.getAugmentation(IfL3tunnel.class);
+ Class<? extends TunnelTypeBase> tunnType = ifL3Tunnel.getTunnelType();
+ LOG.trace("L3Tunnel: {}",ifL3Tunnel);
+ } else if (ifType.isAssignableFrom(StackedVlan.class)) {
+ IfStackedVlan ifStackedVlan = iface.getAugmentation(IfStackedVlan.class);
+ LOG.trace("StackedVlan: {}",ifStackedVlan);
+ } else if (ifType.isAssignableFrom(Mpls.class)) {
+ IfMpls ifMpls = iface.getAugmentation(IfMpls.class);
+ LOG.trace("Mpls: {}",ifMpls);
+ }
+ return matches;
+ }
+
+ public List<ActionInfo> getInterfaceEgressActions(String ifName) {
+ Interface iface = getInterfaceByIfName(ifName);
+
+ List<ActionInfo> listActionInfo = new ArrayList<ActionInfo>();
+ Class<? extends InterfaceType> ifType = iface.getType();
+ long dpn = this.getDpnForInterface(ifName);
+ long portNo = this.getPortNumForInterface(iface).longValue();
+ if (iface.isEnabled()) {
+
+ if(ifType.isAssignableFrom(L2vlan.class)) {
+ IfL2vlan vlanIface = iface.getAugmentation(IfL2vlan.class);
+ LOG.trace("L2Vlan: {}",vlanIface);
+ long vlanVid = (vlanIface == null) ? 0 : vlanIface.getVlanId();
+ if (vlanVid != 0) {
+ listActionInfo.add(new ActionInfo(ActionType.push_vlan, new String[] {}));
+ listActionInfo.add(new ActionInfo(ActionType.set_field_vlan_vid,
+ new String[] { Long.toString(vlanVid) }));
+ }
+ listActionInfo.add(new ActionInfo(ActionType.output, new String[] { Long.toString(portNo)}));
+
+ } else if (ifType.isAssignableFrom(L3tunnel.class)) {
+ //TODO: Handle different tunnel types
+ IfL3tunnel ifL3Tunnel = iface.getAugmentation(IfL3tunnel.class);
+ Class<? extends TunnelTypeBase> tunnType = ifL3Tunnel.getTunnelType();
+ LOG.trace("L3Tunnel: {}",ifL3Tunnel);
+ //TODO: check switch_type and configure accordingly
+ listActionInfo.add(new ActionInfo(ActionType.output, new String[] { Long.toString(portNo)}));
+
+ } else if (ifType.isAssignableFrom(StackedVlan.class)) {
+ IfStackedVlan ifStackedVlan = iface.getAugmentation(IfStackedVlan.class);
+ LOG.trace("StackedVlan: {}",ifStackedVlan);
+ // TODO: TBD
+ } else if (ifType.isAssignableFrom(Mpls.class)) {
+ IfMpls ifMpls = iface.getAugmentation(IfMpls.class);
+ LOG.trace("Mpls: {}",ifMpls);
+ // TODO: TBD
+ }
+ }
+ return listActionInfo;
+
+ }
+
+ private NodeId getNodeIdFromNodeConnectorId(NodeConnectorId ncId) {
+ return new NodeId(ncId.getValue().substring(0,ncId.getValue().lastIndexOf(":")));
+ }
+
+ private Long getPortNumForInterface(Interface iface) {
+ try {
+ NodeConnector port = getNodeConnectorFromDataStore(iface);
+ FlowCapableNodeConnector ofPort = port.getAugmentation(FlowCapableNodeConnector.class);
+ return ofPort.getPortNumber().getUint32();
+ } catch (Exception e) {
+ LOG.error("OFPort for Interface {} not found", iface.getName());
+ }
+ return 0L;
+ }
+